Lesson 8 of 15
43. Design Flash-Sale Ticket Booking (Ticketmaster / IRCTC Tatkal)

43.7 How does seat locking work?

3 min read+10 XP

The same pattern as Chapter 17's seat holds, under heavier load:

  • Hold with a conditional update: UPDATE seats SET status='held', hold_id=? , hold_expires=now()+5min WHERE seat_id IN (…) AND status='free'. If fewer rows update than requested, release what was taken and offer other seats.
  • One holder per seat: in the chapter's code, Ravi can't hold seat 0 while Asha does, and Asha's payment within the hold succeeds.
  • Expiry: Kiran's hold expires at 5 minutes; his late payment is refused, and the seat goes to Ravi.
  • Reduce contention: let users choose a section, then assign the best available seats inside it on the server, instead of thousands clicking the same seat on a map. Shard seats by section.
  • Payment inside the hold: the payment flow (Chapter 42) must finish before the hold expires; a payment that arrives late is refunded unless the seat is still free.

Memory code: "Hold briefly, pay inside the hold, or the seat goes back."