Idempotency Keys for a Card Payment Posting API
Last updated: November 29, 2026
Quick Overview
Design and implement an idempotent POST endpoint for posting a card payment so that client retries after timeouts never post the same payment twice, and reused keys with different bodies are rejected.
Capital One
November 29, 20260
0
0 solved
Design and implement an idempotent POST endpoint for posting a card payment so that client retries after timeouts never post the same payment twice, and reused keys with different bodies are rejected.
Customers paying their Capital One card from the mobile app on flaky networks will retry, and so will upstream services. The interviewer checks that you understand why POST is not naturally idempotent, how idempotency keys work, and how to handle concurrent duplicates and failures.
What the Interviewer Expects
- Explain why retries cause duplicate payments
- Store a record per key with a request fingerprint and the saved response
- Replay the stored response for a true retry
- Reject a key reused with a different body
- Handle concurrent requests with the same key and failures mid-processing
- Expire keys after a retention window
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
- Where would you store keys in a multi-instance deployment?
- Should a 4xx validation error be cached for the key?
- How do idempotency keys interact with a downstream processor that is not idempotent?
- How would you test the concurrent duplicate case?
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
POST /paymentswith headerIdempotency-Keyand a body (account, amount).- Same key plus same body returns the original result and does not post again.
- Same key with a different body is a clie...
High-Level Design
The client generates a unique key per logical payment (a UUID) and reuses it on every retry. The server keeps a table keyed by idempotency key holding a fingerprint of the body, a status (`in_progress...