System design interview: design a ticket booking system
A ticket booking system sells a fixed number of seats to far more people than there are seats, often in the first minutes after a sale opens. The interview turns on three decisions: how you hold a seat while someone pays without ever selling it twice, how you absorb a crowd ten thousand times larger than normal traffic, and how you keep payment and reservation consistent when either can fail.
By Evin JohnPublished 7 min read
1. Clarify the requirements
- Functional: browse events, view available seats (assigned seating or general admission), hold seats while paying, pay, receive a ticket, cancel within the rules.
- Non-functional: strong consistency for inventory (no double booking), high availability for browsing, fairness when demand exceeds supply, and protection against bots.
- Ask about: assigned seats or general admission, how many tickets one person can buy, how long a hold lasts, and whether resale is in scope.
- Out of scope unless asked: event creation tools for organizers, dynamic pricing, the payment processor itself.
2. Estimate the scale
| Quantity | Assumption | Result |
|---|---|---|
| Normal load | 10 million seat-map views a day | about 115 reads a second; easy |
| A hot on-sale | 2 million people arrive in the first 10 minutes for 50,000 seats | about 3,300 arrivals a second, 40 people per seat |
| Hold attempts during the rush | each person tries 3 to 5 seat selections | 10,000 to 15,000 write attempts a second against one event's inventory |
| Inventory size | one venue of 50,000 seats | tiny: fits in memory on one machine |
| Tickets per year | 100 million | about 3 a second on average; storage is not the problem |
The estimate shows where the difficulty is. Data volume is small and average load is modest. The problem is contention: thousands of requests a second competing for the same few thousand rows, during a few minutes, with real money attached.
3. API
GET /events/{eventId}/seats -> seat map with status (may be a few seconds stale)
POST /events/{eventId}/holds {seatIds[], idempotencyKey} -> {holdId, expiresAt}
POST /holds/{holdId}/checkout {paymentToken, idempotencyKey} -> {orderId, status}
GET /orders/{orderId} -> order and tickets
DELETE /holds/{holdId} -> release early4. Data model
| Table | Key fields | Notes |
|---|---|---|
| events | event_id, venue_id, starts_at, on_sale_at | Read-heavy, cached |
| seats | event_id, seat_id, section, row, price_tier, status, hold_id, hold_expires_at, version | One row per seat per event; status is AVAILABLE, HELD or SOLD |
| holds | hold_id, user_id, event_id, seat_ids, expires_at | Short-lived; TTL cleanup |
| orders | order_id, user_id, hold_id, payment_id, status, idempotency_key | Unique constraint on idempotency_key |
| tickets | ticket_id, order_id, seat_id, barcode | Issued only after payment and confirmation both succeed |
A relational database is the natural choice here: the data is small, the relationships are real, and you need transactions on the seat rows. Partition by event_id when you have many events; one event's inventory stays on one shard, which keeps every hold a single-shard transaction.
5. Holding a seat without double booking
This is the core of the interview. Choosing a seat and paying for it are minutes apart, and you cannot lock a database row for minutes. So the seat moves through states, and each transition is a short atomic update that checks the state it expects.
UPDATE seats
SET status = 'HELD', hold_id = :holdId, hold_expires_at = now() + interval '8 minutes'
WHERE event_id = :eventId
AND seat_id = ANY(:seatIds)
AND (status = 'AVAILABLE' OR (status = 'HELD' AND hold_expires_at < now()));
-- In the same transaction: if rows updated != number of seats requested, roll back.UPDATE seats
SET status = 'SOLD'
WHERE hold_id = :holdId
AND status = 'HELD'
AND hold_expires_at > now();- Why not a distributed lock? You can hold seats in Redis with
SET seat:{id} holdId NX PX 480000, which is fast and expires on its own. It works, but the database must still enforce the final state, so many designs keep the conditional update as the source of truth and use Redis only to shed obviously failing requests early. - Expiry is lazy. The hold query treats an expired hold as available, so you do not depend on a cleanup job running on time. A background sweep only tidies rows and updates the cached seat map.
- General admission is simpler: one counter per section, decremented with a conditional update (
WHERE remaining >= :qty).
6. Surviving the on-sale rush: the waiting room
No database should take two million users at once for one event. A virtual waiting room turns the crowd into a queue with a controlled exit rate.
- Edge
- CDN
- Bot checks
- Waiting room (queue tokens)
- Services
- Seat map service
- Booking service
- Checkout service
- Data
- Seat map cache
- Inventory DB (sharded by event)
- Orders DB
- External
- Payment provider
- Ticket delivery (email, app)
- Async
- Hold expiry sweep
- Payment reconciliation
- ArriveBefore the sale opens, users land on a static page from the CDN. At opening time each gets a random position (fair for everyone who arrived early) or a first-come position, and a signed token.
- WaitThe page polls a cheap endpoint for its turn. This load hits the edge, not the booking service.
- AdmitThe waiting room admits users at the rate the booking service can handle, for example 2,000 a minute, and adjusts as holds turn into sales or expire.
- BookOnly requests with a valid admission token reach the booking service. When inventory is gone, the waiting room tells everyone still queued at once.
7. Payment and consistency
- Idempotency keys on hold and checkout requests mean a retried click or a dropped connection cannot create two orders or two charges.
- Authorize, then confirm, then capture. Authorize the card, run the confirm update on the seats, and capture the payment only if the confirm succeeded. If the confirm fails because the hold expired, void the authorization.
- Reconciliation. Payment providers send webhooks late or twice. A worker matches every successful payment with a sold order and refunds or flags anything left over.
- Tickets last. Issue the barcode only when both sides agree; then send it by email or to the app.
8. Failure modes
| Failure | Effect | Mitigation |
|---|---|---|
| Payment succeeds after the hold expired | Customer charged for a seat someone else now holds | Confirm before capture; void or refund automatically; offer a nearby seat if any remain |
| Inventory shard overloaded | Holds time out for one event | Waiting-room admission rate, per-user hold limits, and a read cache that keeps browsing off the shard |
| Bots grab seats | Real fans see nothing available | Bot checks at the edge, verified accounts for presales, per-account and per-card limits |
| Seat map cache is stale | A user picks a seat already taken | Hold fails cleanly with the updated map; staleness of a few seconds is acceptable by design |
| Region outage | Sales stop | Inventory for one event lives in one primary region with a synchronous replica; fail over rather than accept writes in two places |
9. Trade-offs to discuss
- Hold length. Long holds are kinder to slow buyers but lock inventory that may never sell; short holds keep seats moving but frustrate people mid-payment. Eight to ten minutes is common; say why you chose yours.
- Random or first-come queue order. Random order at opening removes the incentive to hammer the site early; first-come rewards those who arrived first. Many sellers randomize everyone who arrived before the sale opened.
- Pessimistic or optimistic. The conditional update is optimistic: no locks held, failures retried. Row locks (
SELECT ... FOR UPDATE) are simpler to reason about but serialize every attempt on hot seats. - Show exact availability or not. Exact live availability under heavy contention costs a lot; a "best available" picker that assigns seats server-side avoids most conflicts.
10. How to talk through it in the interview
Fictional example
- Interviewer
- Two people click the same seat at the same moment. What happens?
- Candidate
- Both send a hold. The hold is one conditional update: set the seat to HELD only if it is AVAILABLE or its old hold has expired. The database applies them one after the other, so the first succeeds and the second updates zero rows and gets the refreshed seat map.
- Interviewer
- And if the first person's card is declined?
- Candidate
- The hold expires after eight minutes or is released at once on decline, and the seat becomes available again. Confirmation only works for the current holder, so a late payment cannot steal it back.
- Lead with the contention numbers; they justify the waiting room.
- Write the conditional update on the whiteboard. It is the most convincing minute of the answer.
- Close with the payment-after-expiry case. It shows you think about money, not only rows.
Practicing this design with Natively
Ticket booking is a favourite because it hides a concurrency problem inside a product everyone knows, and candidates often talk about the product for too long. Rehearse it as a timed mock interview over a call. Natively keeps a live transcript and can turn the flow you describe into a diagram, so after the session you can check whether the hold and confirm steps came across clearly. Pair this walk-through with the payment system design for idempotency and reconciliation, and with the web crawler for a very different kind of scaling problem.
Questions people ask
How do you prevent double booking in a ticket system?
Hold the seat with one conditional update that only succeeds if the seat is available or its previous hold has expired, then confirm the sale with another update that only works for the current, unexpired holder.
What is a virtual waiting room?
A queue in front of a busy sale. Users get a signed position at the edge and are admitted to the booking service at a controlled rate, so the database sees a steady flow instead of the whole crowd at once.
What happens if payment succeeds after the seat hold expires?
The confirm step fails because the hold is no longer valid, so the payment is voided or refunded automatically. Authorizing first and capturing only after a successful confirm avoids most of these cases.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
