Selling tickets without selling a seat twice
A ticketing site crashes and double-books seats when a popular show goes on sale. Design for the spike.
To design ticket booking, make seat reservation atomic with a conditional update, model seats as available, held with an expiry, or sold, and release expired holds. Protect the system with a virtual waiting room, serve seat maps from a cache, and make payment idempotent.
The system today: A ticketing site has a web server and one database. A seats table has a status column (available, sold). When a hit show goes on sale the site slows to a crawl, and twice last month two customers were sold the same seat.
What has to change: Design booking for a sale where 500,000 people arrive within a minute for 20,000 seats. Seats must never be sold twice, people should hold a seat while they pay for a few minutes, the site must stay up under the spike, and the experience should be fair.
Questions to ask first
- Is seating reserved by seat, or general admission by section?
- How long can someone hold a seat while paying, and what happens when the hold expires?
- Is fairness important (a queue by arrival), or is speed enough?
- Can we refuse or delay people to protect the system?
Where the interviewer digs in
- Correctness of a seat reservation under concurrency: transactions, row locks, conditional updates
- Holds with expiry, and releasing seats when payment fails
- A waiting room or queue that sheds load in front of the booking path
What a strong answer covers
- Makes the reservation atomic in the database: a conditional update or a unique constraint, not a read-then-write.
- Models three states (available, held with an expiry, sold) and releases holds with a timeout and a background sweep.
- Protects the system with a virtual waiting room that admits people at a rate the booking path can serve, and explains fairness.
- Separates the heavy read load (seat maps) and serves it from a cache, with the write path small; makes payment idempotent and reconciles after failures.
Common mistakes
- Checking that a seat is free, then marking it sold in a second statement.
- Holding a database transaction open while the user pays.
- Letting 500,000 people hit the seat map and the booking endpoint at the same time.