← All sheets
GL-E-006Sheet 006RECORDE · ENGINEERING

Two customers bought the last item. Both won. Stock: −1.

NCR 002 · INVENTORY RACE · MULTIVENDOR MARKETPLACE · STOCK

Drawing sheet 006: Two customers bought the last item. Both won. Stock: −1.

General notes

  1. 01Both reads saw stock = 1. Both checks passed. Both writes went through. Two people were promised one thing.
  2. 02The database didn't lie. It did what it was asked, twice. Atomicity is your job.
  3. 03Fix: lock the row for the whole placement, inside one transaction. Boring. Correct.

Schedule of eventsTwo requests, one row

TOrder AOrder BStock
t0reads stockreads stock1
t1check passescheck passes1
t2decrements0
t3decrements−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.

Read with

  • Sheet 003 · The rider billed 50 km. The trip was 2 km. Nothing crashed.
  • Sheet 018 · Five bugs. Months apart. One bug.