Make Fund Transfers Idempotent and Deadlock Free Under Concurrent Retries
Last updated: November 29, 2026
Quick Overview
Implement a transfer service where clients may retry the same request with an idempotency key, concurrent transfers between the same accounts must never deadlock or lose money, and a retried key returns the original result instead of moving money twice.
TCS
November 29, 20260
0
0 solved
Implement a transfer service where clients may retry the same request with an idempotency key, concurrent transfers between the same accounts must never deadlock or lose money, and a retried key returns the original result instead of moving money twice.
Payment and core banking work at TCS, including BaNCS deployments, lives or dies on exactly-once effects when mobile apps and gateways retry. The interviewer is probing concurrency basics (lock ordering, check-then-act races) and idempotency design, and expects the candidate to map the in-memory version to database constraints.
What the Interviewer Expects
- Use an idempotency key store and return stored results on retry
- Handle two concurrent requests with the same key so only one executes
- Acquire account locks in a global order to avoid deadlock
- Check balance and debit inside the same critical section
- Explain the database equivalent (unique key, SELECT FOR UPDATE, 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
- What if a retry arrives with the same key but a different amount?
- How long do you keep idempotency keys, and what happens after expiry?
- How does this change when source and destination live in different databases?
- How would you test for deadlocks and lost updates?
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, amount) moves money atomically or rejects. Same key returns the same result forever (within retention). Two transfers A to B and B to A at once must not deadlock. Total money...
High-Level Design
Two layers. The idempotency layer, guarded by one lock, either returns a stored result, waits on an in-flight execution of the same key, or claims the key. The money layer locks both accounts in sorte...