43. Design Flash-Sale Ticket Booking (Ticketmaster / IRCTC Tatkal)
1
The interview prompt2
43.1 What do you ask first?3
43.2 How big is this, really?4
43.3 What are the doors?5
43.4 What do we store?6
43.5 What does the whole system look like?7
43.6 How does the waiting room work?8
43.7 How does seat locking work?9
43.8 How do you rate-limit bots?10
43.9 How do you keep it fair?11
43.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab43. 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."