Design an event ticket booking system
Selling tickets to a popular event is a concurrency problem disguised as a CRUD app: thousands of users fight for the same limited seats in seconds. The whole design centers on reserving inventory correctly under a thundering herd — without overselling and without locking users out unfairly.
Web Apps, 11 components, about 40 min
1. Scope
In scope
- • Browse events and seat maps
- • Reserve (hold) and purchase specific seats
- • Prevent overselling / double-booking
- • Handle high-demand on-sale spikes
Out of scope
- • Dynamic/secondary-market pricing & resale
- • Fraud detection internals
- • Physical ticket fulfillment / delivery
2. Functional requirements
Must have
- • View an event's available seats
- • Hold a seat for a limited time while paying
- • Confirm purchase (or auto-release on timeout)
- • A seat is never sold to two people
Nice to have
- • Virtual waiting room for hot on-sales
- • Best-available auto-selection
- • Email/SMS confirmation
3. Non-functional requirements
4. Back-of-envelope estimation
Assumptions
- • Large venue ~50K seats
- • Hot on-sale: ~1M users hit the page in the first minute
- • Each user makes ~10 read requests browsing
- • Hold window 10 minutes
Derived numbers
5. API design
Seat map with availability (cached)
Hold seats: { eventId, seatIds } → { holdId, expiresAt }
Pay and confirm the held seats
Release a hold early
6. High-level design
What each box in the reference diagram is responsible for:
7. Data model
8. Deep dives
Reserve without overselling
The invariant: a seat is held by at most one user and sold at most once. Take the hold atomically in Redis (SET hold:{event}:{seat} {userId} NX PX 600000); exactly one request wins, the rest get 409. On payment, write the sale with a conditional update (UPDATE seats SET status=sold, order_id=? WHERE event_id=? AND seat_id=? AND status=available) backed by a unique (event_id, seat_id) rule, so even a lost Redis hold cannot become a double sale. The DB is the source of truth for sold seats.
The thundering herd & waiting room
When 1M users hit at 10:00:00 sharp, you cannot let them all reach the booking service. A virtual waiting room issues a token and admits users at a sustainable rate (e.g. a few thousand/sec), turning a spike into a queue. Browse traffic is absorbed by CDN + cache; only admitted users perform contended writes.
Holds and timeouts
A hold reserves seats for ~10 minutes so the user can pay. Model it only as a Redis key with a TTL; the DB row stays available until the sale. If payment succeeds, write sold; if the TTL expires, the key disappears and the seat is free again, with no sweeper needed. Always re-validate the hold is still valid at confirm time to avoid races with expiry.
Payment as a saga
Reserve → charge → confirm spans services and an external PSP. Run it as a saga: on payment success, confirm the seats; on failure or timeout, release the hold (compensating action). Make confirm idempotent (keyed by holdId) so retries from a flaky PSP don't double-sell or double-charge.
9. Bottlenecks
- Hot event = write contention on a few thousand seats → atomic CAS + waiting room
- On-sale spike → CDN for reads, waiting room throttles writes
- Hold expiry races → re-validate at confirm, idempotent confirm
10. Trade-offs
Holding seats
Choose: Seat hold with a TTL in Redis (SET seat NX PX 600000) plus a durable booking row written only on payment.
Instead of: Database row lock held through payment: correct, but locks live for minutes and exhaust connections.
Holds are short-lived and high-contention; an in-memory atomic set is fast and the TTL cleans up abandoned holds automatically.
Admission control for hot events
Choose: A virtual waiting room: users get a queue position, and are admitted at the rate the booking path can serve.
Instead of: Let everyone hit the seat map: simplest, but the booking path collapses and nobody buys.
A popular on-sale can see millions of users for tens of thousands of seats; fairness and stability both need a queue.
Seat map freshness
Choose: Serve the seat map from a cache refreshed every few seconds; show availability as approximate and confirm on hold.
Instead of: Read live availability per request: accurate, but the map is the hottest read during an on-sale.
The hold step is the source of truth; the map only needs to be close enough to avoid most failed clicks.
11. Failure modes
Redis primary fails during an on-sale
Holds lost; seats may be double-held after failover.
Mitigation: The booking write re-checks seat ownership with a conditional insert (unique seat_id per event), so a lost hold cannot become a double sale.
Bots grab the queue
Real fans cannot buy; resale market floods.
Mitigation: Verified fan pre-registration, per-account and per-card limits, device fingerprinting and challenges at queue entry.
Payment slow during peak
Holds expire mid-payment.
Mitigation: Extend the hold once when payment starts; make payment idempotent so a retried payment cannot double-charge.
12. What interviewers probe
Answer each one yourself before opening it.
Two users click the same seat at the same millisecond. Walk through it.Show a strong answer
Both send hold requests; Redis SET NX succeeds for exactly one. The other gets 409 and the UI refreshes the map. The booking table has a unique (event_id, seat_id) as the final guard.
How do you size the waiting room admission rate?Show a strong answer
From the measured throughput of hold → pay → confirm, minus headroom (for example 70%); adjust in a feedback loop on p99 latency and error rate.
How do you handle general admission (no seats)?Show a strong answer
A counter per section with conditional decrement, or pre-minted ticket tokens in a queue; no per-seat state.
What does the data model look like?Show a strong answer
events, venues, seats(venue_id, seat_id, section), event_seats(event_id, seat_id, status, version), bookings(id, user_id, event_id, seats[], payment_id, state).
Sign in to track this guide in your curriculum progress.