Design a Ticket Booking System for High-Demand Sales
Design the waiting room, rate limits, exact ticket count and purchase flow for one very popular ticket on-sale, where each user can buy only once.
Problem statement
This version of Design a Ticket Booking System is built from Disney's and ByteDance's interview reports. Both ask about the rush when a very popular sale opens.
Design the ticket booking system for one very popular on-sale. When sales open, far more people show up than there are tickets.
For this exercise, assume:
One on-sale, one event. The on-sale has a fixed number of general admission tickets. There is no seat map: every ticket is the same, and one purchase is 1 to 4 tickets.
Virtual waiting room. Users must be signed in. Everyone who arrives joins the on-sale's waiting room. The system lets people into the purchase step a limited number at a time, in the order the server recorded their join. Refreshing the page or reconnecting keeps a user's place. Getting in lets a user try to buy. It does not promise that tickets are still left.
Rate limits and scripts. Some clients are scripts that send far more requests than a person would. The system must limit how often each client can call it, so scripts cannot crowd out real users or get ahead in line. You may use an outside challenge service, such as a puzzle check that is easy for people and hard for scripts.
Short purchase window. An admitted user has 10 minutes to reserve tickets and pay. Reserved tickets are held for that user, and nobody else can buy them. If the user has not paid by the end of the window, the held tickets go back on sale.
Payment. Payment goes through an outside payment provider. A charge can succeed, be declined, or time out with no clear answer. A user who was charged must get their tickets.
No overselling. The system must never sell more tickets than the on-sale has. Once a user is told their order is confirmed, that order must survive the crash of any single machine.
One purchase per user. This rule comes from Disney's report. Many ticket sales do not have it, but this exercise does. Each signed-in user can complete at most one successful purchase in this on-sale. Network retries, double clicks, a second tab or a second device must never create a second purchase or a second charge.
Out of scope: seat maps, cancellations and refunds, a waitlist for returned tickets, event search, more than one event at a time, building your own bot detection, and spotting one person who uses many accounts.
What to build
- Users can join the on-sale's waiting room, see that they are still waiting, and keep their place after a refresh or reconnect. The system lets users in a limited number at a time, in the order they joined.
- An admitted user can reserve 1 to 4 tickets while enough are left. The total sold and held never goes above the on-sale's ticket count.
- The user can pay for reserved tickets within their window and get a confirmed order. Retrying a payment never charges twice or creates a second order.
- Each signed-in user completes at most one successful purchase in the on-sale, even across tabs, devices and retries.
At scale
- The on-sale has 50,000 tickets. Most users buy 2 to 4, so it sells out after roughly 15,000 to 25,000 purchases.
- Up to about 1 million users may arrive in the first 10 minutes, most of them in the first minute after sales open. Some clients are scripts that send hundreds of requests per second each.
- The purchase step behind the waiting room is sized for about 5,000 admitted users at a time. Even so, reserve requests can reach a few thousand per second, all against the same ticket count.
- A payment call usually takes a few seconds, but it can time out after about 30 seconds with no answer.