Build an Idempotency Layer for a Transfers API
Last updated: November 29, 2026
Quick Overview
Implement the server side of Idempotency-Key handling for a POST /transfers endpoint: replay stored responses for repeat requests, reject a key reused with different parameters, return a conflict while the first request is still running, and expire keys after 24 hours.
Bridge
November 29, 20260
0
0 solved
Implement the server side of Idempotency-Key handling for a POST /transfers endpoint: replay stored responses for repeat requests, reject a key reused with different parameters, return a conflict while the first request is still running, and expire keys after 24 hours.
Bridge sells developer APIs that move real money, so a client retry after a timeout must never create a second transfer. Interviewers on an API-product team use this to see whether you understand the exact semantics clients rely on, and which failures should and should not be cached.
What the Interviewer Expects
- Scope keys per API key so tenants cannot collide
- Fingerprint the request canonically and reject mismatched reuse
- Handle the concurrent in-flight case explicitly
- Decide clearly which outcomes are stored (2xx, 4xx) and which are not (5xx, crashes)
- Explain how the in-memory version maps to a database with a unique constraint
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
- The handler commits the transfer and then the process dies before saving the response. What happens on retry?
- How would you implement this across many API servers?
- Should a 402 insufficient funds response be replayed or re-evaluated?
- How long should keys live, and what is the cost of a longer TTL?
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
Same (api_key, idempotency key) with the same method, path and body returns the original status and body without running the handler. Same key with different parameters is a client bug: 422. Same key ...
High-Level Design
Store a record per key: fingerprint, status (in_progress or done), creation time, and the stored response. Insert the in_progress record before calling the handler; this is the lock. Store final...