Implement Idempotency Keys for a Payout Creation Endpoint
Last updated: November 29, 2026
Quick Overview
Build an in-process component that makes a payout-creation handler idempotent: repeated requests with the same client key and payload return the original response, a reused key with a different payload is rejected, and concurrent duplicates never run the handler twice.
Airwallex
November 29, 20260
0
0 solved
Build an in-process component that makes a payout-creation handler idempotent: repeated requests with the same client key and payload return the original response, a reused key with a different payload is rejected, and concurrent duplicates never run the handler twice.
Airwallex's public APIs ask clients to send a unique request id on money-moving calls, because a network timeout followed by a retry must never pay someone twice. The interviewer is checking concurrency reasoning, the payload-fingerprint check, and what happens when the handler fails midway.
What the Interviewer Expects
- Scopes keys per client so two customers cannot collide
- Fingerprints a canonicalized payload to detect key reuse with different content
- Reserves the key atomically before running the handler
- Returns a distinct in-progress signal for concurrent duplicates
- Defines behavior when the handler throws (release the key or store the error)
- Adds expiry so the store does not grow forever
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
- How does this change when the store is Postgres or Redis across many service instances?
- The handler called the bank and then crashed before saving the response. What now?
- Should a 4xx validation error be cached against the key? A 5xx?
- How long should keys live, and who decides?
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
execute(client_id, key, payload, handler). Same key and same payload: return the stored response, handler runs at most once. Same key, different payload: conflict error. Duplicate arriving while the...
High-Level Design
A record per (client_id, key) holds a fingerprint, status, response and expiry. The critical section only reserves or reads the record; the handler runs outside the lock so one slow bank call does n...