Prevent Double Debits in a Transfer API With Idempotency Keys
Last updated: November 29, 2026
Quick Overview
Implement a transfer service where clients may retry the same request many times, possibly concurrently, and the money must move exactly once. Show the idempotency handling and the locking that keeps balances consistent.
Wells Fargo
November 29, 20260
0
0 solved
Implement a transfer service where clients may retry the same request many times, possibly concurrently, and the money must move exactly once. Show the idempotency handling and the locking that keeps balances consistent.
Moving money between Wells Fargo accounts, or out through Zelle and wires, happens over unreliable mobile networks where timeouts trigger retries. Interviewers use this to check understanding of idempotency, race conditions, lock ordering, and how the same ideas map onto a relational database in a Java or Spring service.
What the Interviewer Expects
- Idempotency key stored with the request fingerprint and final result
- Concurrent duplicates wait for the first instead of both executing
- Reject a reused key with a different payload
- Lock both accounts in a consistent order to avoid deadlock
- Explain the database version: unique constraint, SELECT FOR UPDATE or optimistic versioning, single transaction
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 do you retain idempotency keys, and what happens after they expire?
- How would you do this across two services with separate databases?
- Would you cache a REJECTED result for the key, or let the client retry it?
- How do you make this work when the service runs on 40 pods?
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
transfer(key, src, dst, cents) returns the same result for every call with the same key. Two concurrent calls with the same key execute once. Different keys proceed in parallel unless they touch the...
High-Level Design
Two layers. Key layer: a map of finished results plus an in-flight marker per key; latecomers wait on the marker then read the stored result. Money layer: per-account locks acquired in sorted order (s...