Databases · interactive
The lost update
Two requests add money to the same account at the same moment. Each reads the balance, adds in the application, and writes it back. The database did exactly what it was told, and one deposit vanished. Four ways to stop it.
balance
100
- db balance = 100. T1 adds 30, T2 adds 50. It should end at 180.
balance = 100. T1 adds 30, T2 adds 50. It should end at 180.
How the code updates
SELECT balance …; UPDATE … SET balance = :new
step 1 of 6Step 1 of 4 · read left to right
In production
Tools and technologies
The same bug appears in any database; the fixes are standard SQL.
Not tied to one language — use these names when you search docs or design a system.