System designProblem breakdowns9 min read

Design a Ticket Booking System

This breakdown walks one classic system design question end to end: an event ticketing site where fans browse concerts and games, pick seats and pay. It follows the delivery framework from System Design Interviews: The Quick Start, and it is written for mid-level and senior software engineers. The problem looks like plain CRUD until the interviewer says "a stadium tour goes on sale and a million people show up at once". The whole interview is about what happens then.

Requirements

Spend the first five minutes here and write the answers down where the interviewer can see them.

Functional

  • Users search and browse events by keyword, date, location and category.

  • Users view an event's seat map with current availability.

  • Users select seats and hold them for a short time while they pay.

  • Users pay and receive tickets; unpaid holds are released.

Out of scope unless the interviewer asks: resale, dynamic pricing, venue management tools, refunds after purchase.

Non-functional, with numbers

State assumptions and let them drive decisions:

  • 5 million daily active users, about 10 page views each: 50 million reads a day, roughly 580 per second on average and a few thousand at the evening peak.

  • About 500,000 tickets sold a day: around 6 sales per second on average. Writes are not the problem on a normal day.

  • 100,000 active events averaging 5,000 seats: 500 million seat rows. At about 100 bytes each that is around 50 GB, which fits on one well-sized relational database partitioned by event.

  • The spike: one stadium show with 60,000 seats and 1,000,000 fans arriving in the first ten minutes. If each fan refreshes the seat map every 5 seconds, that is 200,000 reads per second for one event, plus tens of thousands of hold attempts per second against 60,000 seats.

  • Correctness: a seat is sold at most once. Never double-sell, even if it means turning a buyer away.

  • Availability: browsing should stay up during the spike; it is fine for the seat map to be a few seconds stale.

That last pair is the key trade-off of the whole problem, and saying it out loud early scores on requirements: strong consistency for the act of booking, eventual consistency for displaying availability.

Core entities and API

Entities: Event, Venue, Seat (per event: section, row, number, status, price), Hold (a set of seats for one user with an expiry), Order (a paid hold) and Ticket.

A small API is enough:

GET  /events?query=&city=&date=        -> list of events (search)
GET  /events/{eventId}                 -> event details
GET  /events/{eventId}/seats           -> seat map with availability
POST /events/{eventId}/holds           { seatIds } -> { holdId, expiresAt }
POST /holds/{holdId}/checkout          { paymentToken, idempotencyKey } -> { orderId, status }
GET  /orders/{orderId}                 -> order and tickets

The user comes from the auth token, never the request body. For more on resource naming and idempotency keys, see API Design.

High-level design

            +-----------+        +-------------------+
Client ---> | CDN / LB  | -----> | Event + search    | ---> Search index
            +-----------+        | service           |       (fed by CDC)
                  |              +-------------------+
                  |              +-------------------+      +-----------+
                  +------------> | Booking service   | ---> | Postgres  |
                  |              | (holds, orders)   |      | seats,    |
                  |              +-------------------+      | holds,    |
                  |                       |                 | orders    |
                  |                       v                 +-----------+
                  |              +-------------------+
                  |              | Payment provider  | --webhook--> Booking
                  |              +-------------------+
                  +------------> Seat map cache (short TTL)

Walk the two flows:

  1. Browse: search queries hit a search index built from the events table through change data capture. The seat map is served from a cache keyed by event, refreshed every few seconds from the database.

  2. Book: the booking service holds seats with a single atomic database update, then hands the user to the payment provider. A webhook confirms payment and the service converts the hold into an order and tickets in one transaction.

Keep the booking path on a relational database with transactions. Seat state is small, highly structured and needs atomic multi-row updates, which is exactly what it is good at. Choosing and Scaling a Database covers the reasoning.

Deep dive 1: holding seats without double-selling

This is the deep dive the interviewer is waiting for. Two people click seat A12 in the same millisecond; exactly one may win.

Option one, a distributed lock per seat in an in-memory store, works but adds a second source of truth that can disagree with the database. Option two, a pessimistic SELECT ... FOR UPDATE per seat, works but holds row locks across application code. Option three is a conditional update: let the database decide in one statement.

UPDATE seats
SET status = 'held', hold_id = $1, held_until = $2
WHERE event_id = $3
  AND seat_id = ANY($4)
  AND (status = 'available'
       OR (status = 'held' AND held_until < $5));

Run it in a transaction and check the affected row count. If the user asked for four seats and four rows changed, commit and return the hold. If fewer changed, someone beat them to at least one seat: roll back so they hold nothing, and tell them which seats are gone. The held_until < now clause means an expired hold is free to take without waiting for a cleanup job; a periodic sweeper still resets expired rows so the seat map looks right.

Why this wins: the database's row locks serialize competing writers per seat, there is no separate lock service to keep in sync, and the hold expiry is data, not a timer that can be lost. Dealing with Contention compares the options in general.

Tip

If the event is general admission with no seat map, contention moves to a single counter row ("tickets remaining"), which becomes a hot row. Split the inventory into, say, 20 buckets of 3,000 tickets and pick a bucket at random per request, falling back to another bucket when one is empty.

Deep dive 2: a million fans at once

Even with correct holds, 1,000,000 people hammering the booking service for 60,000 seats is a bad experience: most requests fail, retries multiply the load, and the database spends its time rejecting losers.

The answer is a virtual waiting room in front of the booking flow for high-demand events:

  1. When an on-sale starts, every arriving user gets a signed queue token with a position. Positions can be random for everyone who arrived before the start time, so refreshing early does not help.

  2. A gatekeeper admits users at a controlled rate. Size the rate from what checkout can absorb: if a checkout takes about 5 minutes and the booking service handles 20,000 concurrent shoppers comfortably, admit about 4,000 users a minute.

  3. Admitted users get a short-lived access token that the booking service requires for this event. Everyone else sees their position, served from a cache, never touching the database.

  4. When inventory runs out, the gatekeeper tells the remaining queue so they are not left waiting for nothing.

The arithmetic tells you when the event ends: 60,000 seats at an average of 2.5 tickets per order is 24,000 orders. At 4,000 admissions a minute and, say, half of admitted users completing a purchase, seats last roughly 12 minutes.

The waiting room converts an uncontrolled spike into a steady stream the system was sized for. It is also fairer, which is a product argument worth making.

Deep dive 3: reading availability at scale

200,000 seat map reads a second for one event would crush the primary. Three layers handle it:

  • Cache the seat map per event with a TTL of 2 to 5 seconds. The data is allowed to be stale because the hold statement re-checks every seat. One cache entry serves every viewer of that event; request coalescing stops a thousand misses from all hitting the database when it expires. See Caching in Depth.

  • Serve the cache from read replicas, not the primary, when it refreshes.

  • Send a compact format: two bits per seat (available, held, sold) is 120,000 bits, about 15 KB, for all 60,000 seats, instead of a JSON object per seat. Clients can also fetch one section at a time.

Search is a separate path: an inverted index over event names, performers and venues, with filters on date and location, kept up to date from the events table. A few seconds of lag is fine. Search and Geospatial Indexes covers how that index works. Scaling Reads generalizes this layering.

Deep dive 4: payment and hold expiry

Payment is the multi-step part: hold, charge, confirm. Each step can fail independently.

  • Hold timer: show the user a 10-minute countdown but set held_until a couple of minutes later. The buffer absorbs a payment that completes in the last seconds.

  • Idempotent checkout: the client sends an idempotency key, and the order row stores it with a unique constraint, so a double click or a retry never charges twice.

  • Confirmation: the payment provider's webhook triggers one transaction that marks the seats sold only if the hold is still ours.

UPDATE seats
SET status = 'sold', order_id = $1
WHERE hold_id = $2 AND status = 'held';

If the row count matches, insert the tickets and mark the order paid in the same transaction. If it does not, the hold expired and someone else took a seat: refund automatically and tell the user. That path should be rare, and saying how you would monitor its rate earns points.

  • Lost webhooks: a reconciliation job polls the provider for orders stuck in "pending" for more than a few minutes.

Multi-Step Processes and Long-Running Jobs explains how to keep sequences like this correct when a step fails halfway.

Follow-ups to expect

  • "How do you stop bots from buying everything?" Rate limits per account and payment method, a per-order ticket cap, the queue token bound to a verified account, and a challenge at queue entry. Admit fewer, verified users rather than more anonymous ones.

  • "What if the database primary fails during an on-sale?" Synchronous replication to a standby in another zone so a committed hold or sale is never lost; the waiting room pauses admission during failover so users wait in line rather than seeing errors.

  • "Can you shard this?" Partition seats, holds and orders by event_id. Every booking touches one event, so every transaction stays on one shard, and a hot event can be given its own.

  • "Why not keep holds only in Redis?" You can, with TTL-based keys, but then the sale itself must still be recorded durably, and you need a plan for the two stores disagreeing. One store for seat state is simpler to reason about at this write volume.

What changes with seniority

  • Mid-level: a working end-to-end design with a correct hold mechanism and an explanation of why two users cannot both get a seat.

  • Senior: drives the conversation to the on-sale spike unprompted, sizes the waiting room from numbers, separates the consistency needs of reads and writes, and handles payment failure paths.

  • Staff: discusses fairness and abuse as product trade-offs, operating the on-sale (load testing, a kill switch, dashboards for hold failures and refund rate) and how the design changes for general admission, resale or many simultaneous on-sales.

Mistakes that cost points

  • Checking availability, then writing. A read followed by an update is a race. The check must be the update's own condition.

  • Treating the seat map as strongly consistent. It does not need to be, and pretending it does makes the read path impossible to scale.

  • Ignoring the spike until asked. It is the point of the question; raise it in your requirements.

  • No answer for a payment that succeeds after the hold expired. Decide: grace period, then automatic refund.

Practice it

Spend 15 minutes writing the hold and confirm statements from memory and listing every way a booking can fail between them. Then practice the same reasoning, with consistency and fan-out at the center, on a live interview:

Practise this in a mock interview

Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.

Read next

  • Design a News Feed

    Build a social feed end to end, choosing fan-out on write, on read or a hybrid from the read and write numbers, sizing the feed cache, and handling celebrity accounts, pagination and ranking.

    7 min read

  • System Design Interviews: The Quick Start

    Know which system design interview you face and how depth expectations change by level, then deliver any design with a six-step, 45-minute framework whose estimates drive real decisions.

    7 min read

  • ML System Design Interviews: The Quick Start

    Run an ML system design interview with an eight-step, 45-minute framework, from framing and labels to metrics, serving, drift and feedback loops, worked through on a harmful-comment classifier.

    9 min read

  • Thinking in Systems: From One Server to Millions of Users

    Explain why each part of a typical web architecture exists by growing one app from a single server to millions of users, naming what broke and what each fix costs.

    7 min read