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.6 How does the waiting room work?
3 min read+10 XP
Step 5: Deep dives (10 minutes)
Figure: a cheap queue protects an expensive system.
- Join once: the account gets a numbered spot (an atomic counter, or a sorted set keyed by the fair order of 43.9).
- Admit at a fixed rate: a scheduler moves the front of the queue to "admitted" at 2,000 a second, tuned to what booking can handle. In the chapter's code, position 600,000 waits about 5 minutes, and after 10 minutes 1.2 million have been admitted.
- Honest status: position and estimated wait, refreshed by a cheap, cacheable poll. When seats are gone, say so at once instead of letting people wait for nothing.
- Tokens expire: an admitted person who doesn't act within a few minutes loses their turn, and the slot goes to the next person.
- Back-pressure from booking: if booking slows (database, payment provider), lower the admit rate automatically (Chapter 22's backpressure).
Memory code: "Number them, admit at a steady pace, and never lie about the wait."