Prevent Lost Updates in Concurrent Db2 Account Balance Transfers
Last updated: November 29, 2026
Quick Overview
Two application servers transfer money between accounts by reading balances, computing new values and writing them back; explain why updates get lost under concurrency and implement a transfer that stays correct.
IBM
November 29, 20260
0
0 solved
Two application servers transfer money between accounts by reading balances, computing new values and writing them back; explain why updates get lost under concurrency and implement a transfer that stays correct.
IBM's banking clients run core systems on Db2 for z/OS and Db2 LUW, and engineers on those teams must reason precisely about isolation levels and locking. This onsite question checks that you can name the lost update anomaly, choose between pessimistic and optimistic control, and write a transfer that is atomic and retry-safe.
What the Interviewer Expects
- Explain the read-modify-write race with a concrete interleaving
- Contrast pessimistic locking (SELECT ... FOR UPDATE) with optimistic version checks
- Make both legs of the transfer one transaction
- Guard against overdraft inside the UPDATE itself
- Lock rows in a consistent order to avoid deadlocks
- Handle retries idempotently
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
- Which Db2 isolation level (UR, CS, RS, RR) would you pick and why?
- How do you make a retried transfer idempotent if the client times out after commit?
- How would this change if the two accounts live in different databases?
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
Accounts have id, balance and version. A transfer moves amount from src to dst, must never leave a negative balance, and must not lose concurrent updates. Show the broken pattern, then a c...
High-Level Design
The race: server A reads balance 100, server B reads 100, A writes 100 - 30 = 70, B writes 100 - 50 = 50. The 30 debit vanishes. Under Db2's default Cursor Stability, the read lock is released after t...