Make Concurrent Account Transfers Deadlock Free and Consistent

Last updated: November 29, 2026

Quick Overview

Implement a thread-safe transfer(src, dst, amount) for an in-memory account store so that concurrent transfers in opposite directions never deadlock, balances never go negative, and a total-balance audit always sees a consistent snapshot.

JPMorgan Chase
Software Engineering Fundamentals
Software Engineer
JPMorgan Chase
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a thread-safe transfer(src, dst, amount) for an in-memory account store so that concurrent transfers in opposite directions never deadlock, balances never go negative, and a total-balance audit always sees a consistent snapshot.

Most JPMorgan Chase backend services are Java and Spring Boot systems that move money between accounts, so interviewers like to probe concurrency fundamentals rather than framework trivia. They are checking whether you can name the deadlock condition, fix it with a global lock order, and keep the check-then-act on the balance atomic.

What the Interviewer Expects
  • Explains why naive locking of src then dst deadlocks when two threads transfer A to B and B to A
  • Imposes a global lock order (by account id) and acquires both locks before reading balances
  • Keeps the insufficient-funds check inside the critical section
  • Makes the audit read consistent by locking in the same order
  • Compares with alternatives such as a single global lock, tryLock with backoff, or a database transaction
Key Topics to Cover
deadlock
lock ordering
race conditions
atomicity
Java concurrency
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 this look in Java with ReentrantLock and tryLock with a timeout?
  • The store is now a relational database. How do you get the same guarantees with SELECT ... FOR UPDATE?
  • How would you make the transfer idempotent when a client retries after a timeout?
  • What changes if accounts are sharded across two services?
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

Many threads call transfer(src, dst, amount) concurrently. Guarantees: no lost updates, no negative balances, no deadlock, and total() returns the true sum of all balances at some instant. Amount ...

High-Level Design

Per-account locks give parallelism between unrelated transfers. The danger is the Coffman circular-wait condition: thread 1 holds A and waits on B while thread 2 holds B and waits on A. Breaking circu...


Submit Your Answer
Markdown supported

Related Questions