Idempotent Charge Endpoint for Rakuten Pay Merchant Retries
Last updated: November 29, 2026
Quick Overview
Design and implement the server side of an idempotency key for a create-charge API so that merchant retries, concurrent duplicates and timeouts never charge a customer twice.
Rakuten
November 29, 20260
0
0 solved
Design and implement the server side of an idempotency key for a create-charge API so that merchant retries, concurrent duplicates and timeouts never charge a customer twice.
Rakuten Pay and the card business process payments from merchants whose clients retry aggressively on flaky mobile networks. Onsite interviewers use this to test API semantics, state machines for in-flight requests, and honest handling of unknown outcomes.
What the Interviewer Expects
- Scope idempotency keys per merchant
- Store a request fingerprint and reject key reuse with a different body
- Handle concurrent duplicates with an in-progress state
- Distinguish definite failures from unknown outcomes on timeout
- Return the stored response on replay
- Discuss key retention and storage
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 long should keys be retained, and what happens when a merchant retries after expiry?
- Where does the reconciler get the truth for charges stuck in progress?
- How would you implement the begin step on a sharded SQL database?
- Should a 4xx validation error be cached under the key?
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 /charges with header Idempotency-Key. Same merchant plus key plus same body must return the same result and move money at most once. Same key with a different body is a client bug and gets 42...
High-Level Design
An idempotency table keyed by (merchant_id, idem_key) stores a body fingerprint, a state (IN_PROGRESS or DONE) and the final response. begin is an atomic insert: in SQL, `INSERT ... ON CONFLICT DO...