Lesson 7 of 15
43. 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)

2 million people wait with numbered, signed spots; 2,000 a second are admitted; each sees an honest position and estimate.

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."