GL-E-006Sheet 006RECORDE · ENGINEERING
Two customers bought the last item. Both won. Stock: −1.
NCR 002 · INVENTORY RACE · MULTIVENDOR MARKETPLACE · STOCK

General notes
- 01Both reads saw stock = 1. Both checks passed. Both writes went through. Two people were promised one thing.
- 02The database didn't lie. It did what it was asked, twice. Atomicity is your job.
- 03Fix: lock the row for the whole placement, inside one transaction. Boring. Correct.
Schedule of eventsTwo requests, one row
| T | Order A | Order B | Stock |
|---|---|---|---|
| t0 | reads stock | reads stock | 1 |
| t1 | check passes | check passes | 1 |
| t2 | decrements | — | 0 |
| t3 | — | decrements | −1 |
As posted
Two customers. One item. Same second.
Both reads saw stock = 1. Both checks passed. Both writes went through. Stock: −1.
The database didn't lie. It did what it was asked, twice. Atomicity is your job.
Row lock, one transaction. Boring. Correct.
Sheet 006, NCR 002.