Build an Idempotent Consumer for Out of Order Payment Events
Last updated: November 29, 2026
Quick Overview
Implement a consumer for payment status events that may be delivered more than once and out of order. Ignore exact redeliveries, never let an older version overwrite a newer one, and refuse illegal status regressions.
Cognizant
November 29, 20260
0
0 solved
Implement a consumer for payment status events that may be delivered more than once and out of order. Ignore exact redeliveries, never let an older version overwrite a newer one, and refuse illegal status regressions.
Cognizant engineers often integrate client systems with payment processors and message buses such as Kafka, where at-least-once delivery is the default. This question checks whether you understand why deduplication alone is not enough and how versioning gives correctness even after the dedupe cache forgets.
What the Interviewer Expects
- Separates duplicate detection from ordering
- Uses a per-entity version as the true guard against stale writes
- Bounds the dedupe store with a TTL
- Encodes allowed status transitions
- Explains how this maps to a database or Redis in production
- Writes testable code with an injectable clock
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Two consumer instances process the same payment at once. How do you keep the version check atomic?
- How would you store dedupe keys in Redis or Postgres, and with what expiry?
- A CAPTURED event arrives before AUTHORIZED. Should you apply it, park it, or reject it?
- How do you make the side effects (ledger posting, email) idempotent too?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Events carry event_id, payment_id, version (monotonic per payment from the producer) and status. Guarantees needed: a redelivered event has no effect; an event with a version at or below the s...
High-Level Design
Two layers. A dedupe map of event_id to first-seen time, expired after a TTL, catches cheap redeliveries early. The authoritative check is the stored version per payment: even after the dedupe entry...