Thread-Safe Account Transfers Without Deadlocks

Last updated: November 29, 2026

Quick Overview

Implement a transfer between two in-memory bank accounts that is safe when many threads run transfers concurrently, never deadlocks, and never lets money be created or lost.

Capital One
Software Engineering Fundamentals
Software Engineer
Capital One
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a transfer between two in-memory bank accounts that is safe when many threads run transfers concurrently, never deadlocks, and never lets money be created or lost.

Capital One engineering interviews often pair a coding exercise with fundamentals about correctness in money movement, such as transfers between checking and 360 Savings accounts. The interviewer checks that you identify the race, choose the right locking granularity, and explain why a consistent lock order prevents deadlock.

What the Interviewer Expects
  • Explain the lost update race on unsynchronized balances
  • Use per-account locks rather than one global lock
  • Acquire locks in a global order to prevent deadlock
  • Check funds inside the critical section
  • Store money as integer cents and test the conservation invariant under load
Key Topics to Cover
concurrency
mutual exclusion
deadlock prevention
lock ordering
invariants
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you extend this to a transfer touching three accounts?
  • What changes when balances live in a database instead of memory?
  • How would you detect a deadlock if lock ordering were not possible?
  • Would a single global lock be acceptable, and when?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • transfer(src, dst, amount) moves money atomically: either both balances change or neither does.
  • Many threads call it concurrently on overlapping accounts.
  • Never overdraw the source; reject non...
High-Level Design

Without locking, src.balance -= amount is a read, compute, write sequence, so two threads can read the same balance and one update is lost. A single global lock fixes correctness but serializes ever...


Submit Your Answer
Markdown supported