Module 5 · Transactions and concurrency control
Episode 40 Lab: Two Users Bought the Last Ticket
▶ This video is coming to YouTube soon.
One ticket left, two buyers, two sales. This lab reproduces the bug in two real Postgres sessions, replays it in a simulator to show the lost update at READ COMMITTED, then fixes it three ways (SELECT ... FOR UPDATE, a single atomic UPDATE, SERIALIZABLE with a retry), proves each fix in Postgres and measures them with six buyers.
Chapters
- 0:00Intro
- 0:13The symptom
- 0:34Reproduce: two checkouts, one ticket
- 1:15Diagnose: a lost update
- 2:18Why READ COMMITTED allowed it
- 2:45Three ways to tie the decision to the write
- 3:22Fix 1: SELECT … FOR UPDATE
- 3:48Fix 2: one atomic UPDATE
- 4:13Half a fix, and a safety net
- 4:57Fix 3: SERIALIZABLE and a retry
- 5:28The code: the atomic checkout
- 6:00Measure: six buyers, two tickets
- 6:51Before and after
- 7:23Recap
- 7:50Next: Write-Ahead Logging