Machine Room

Race Condition

How bad code sells one seat twice. The one-page notes from the reel.

Download the PDF

One-page notes on race conditions: Maya and Leo press Buy in the same second, and if the code isn't ready for that both get seat 42; the booking code is STEP 1 read seat — free?, STEP 2 write booking; Maya reads FREE, Leo reads FREE, both write: 2 bookings, 1 seat; a race condition is two requests reading the same data before either one wrote it; the fix is a lock on the seat's row (SELECT … FOR UPDATE): Leo locks, Maya waits, Leo's booking is written and the lock released, Maya reads TAKEN: 1 seat, 1 booking; paying takes minutes, so the site writes a hold, HELD BY LEO · 10:00, which expires at 0:00 and the seat goes back on sale to Maya.

On a phone, press and hold the image to save it. The reel: Race Condition: How Bad Code Sells One Seat Twice.