Design Ticketmaster
Design Ticketmaster in a 45-minute interview: seat holds with a TTL, double-booking prevention compared (row locks, conditional updates, Redis locks), a virtual waiting room and fairness.
On this page
How to use this page
This page follows the order of a real system design interview. At each step there is a Your turn box: write your own answer first (it stays in your browser), then open ours and compare. Reading a finished design feels easy; producing one under time pressure is the skill you are practising.
| Phase | Time in a 45-min interview | What you produce |
|---|---|---|
| 1. Clarify requirements | 5 min | Functional list, non-functional targets, what's out of scope |
| 2. Estimate | 5 min | Arrival rate, fans per seat, queue drain time, seat-map reads |
| 3. API | 5 min | Queue, seat map, hold, order |
| 4. Data model | 5 min | Seat inventory, holds, queue, orders |
| 5. High-level design | 10 min | The protective front door and the consistent core |
| 6. Deep dives | 10–15 min | Double booking, holds, the waiting room, fairness, the seat map |
| 7. Wrap up | 2–3 min | Bottlenecks, failures, what you would monitor |
Fans browse events, see a seat map, pick seats, hold them for 10 minutes while paying, and get tickets. For hot on-sales, traffic arrives in a burst at a known time. Stop bots and be fair. Skip resale marketplaces, venue management tools and dynamic pricing.
1. Clarify the requirements
The interviewer says: "Design Ticketmaster." Write down your questions, then 4–6 functional requirements, 4–5 non-functional requirements with targets, and what's out of scope.
Compare with our answer
The questions that matter most: Assigned seats or general admission? How big is the biggest on-sale? How long can a fan hold seats while paying? Is there a ticket limit per person? Do we need to stop bots? The answer to "how big" turns this from a CRUD app into a flash-crowd problem.
A strong answer mentions: browse events and seat maps · hold seats for a fixed time · pay and receive tickets · a per-person limit · a waiting room for hot on-sales · every seat sold exactly once · stays up under a burst · fair to humans.
Functional: what it must do
- Browse events and seat maps: Live availability
- Hold seats: Reserved for 10 minutes while checking out
- Pay and receive tickets: Mobile tickets with QR codes
- Waiting room for hot sales: Queue fans fairly before they reach the seat map
- Limit tickets per person: e.g. max 4
Out of scope
Resale marketplaceVenue managementDynamic pricing
Non-functional: how well it must work
| Quality | Target | Why |
|---|---|---|
| Correctness | A seat is sold to exactly one person | Absolutely no double booking |
| Burst handling | 1 M users in the first minute | Thousands of times normal traffic |
| Fairness | First come, first served; bots blocked | Public trust and regulation |
| Availability | The site must stay up during the on-sale | A crash is national news |
| Latency | Seat map loads quickly; holds confirm in < 1 s |
2. Back-of-the-envelope estimates
1 M fans arrive within 60 seconds for 50,000 seats. The back end can serve 2,000 new fans a second; each fan spends about 2 minutes choosing and refreshes the seat map 6 times a minute. Work out the arrival rate, fans per seat, how long the queue takes to drain, and seat-map reads per second.
Compare with our answer
- Arrivals: 1 M ÷ 60 s ≈ 17,000 new fans/s, each making several requests (page, assets, queue polls): easily 100 K+ requests/s at the edge.
- Fans per seat: 1 M ÷ 50 K = 20. Most fans will leave empty-handed; telling them quickly is part of the job.
- Queue drain: 1 M ÷ 2,000/s = 500 s ≈ 8 minutes. In practice the seats run out well before the end of the queue.
- Inside the store: 2,000/s × 120 s = 240,000 fans at once, each refreshing 6 times a minute: 240 K × 6 ÷ 60 = 24,000 seat-map reads/s.
- Holds: at most a few thousand a second, all aimed at 50,000 rows.
A strong answer mentions: the arrival rate vs what the core can take · fans per seat · drain time · read load inside the store · that the write set is tiny but extremely contended.
Assumptions: fans arriving at on-sale 1 M; arrival window (seconds) 60; seats available 50 K; fans let in per second 2 K; seat-map refreshes per fan per minute 6.
| Number | Estimate | Why it matters |
|---|---|---|
| Arrival rate | 16.7 K / s | ≈ 17,000 new users a second, each making many requests. |
| Fans per seat | 20 | 20 fans per seat: most will be disappointed, so be fast and honest. |
| Time to let everyone through the queue (minutes) | 8.33 | ≈ 8 minutes; long before then the seats are gone. |
| Seat-map reads per second (inside) | 24 K / s | Fans inside the store (≈ 2 minutes each) refreshing the map. |
- Without a waiting room, 17 K new users per second would all hit seat selection at once.
- Seats are scarce: the system mostly needs to say “sold out” quickly and correctly.
3. API
List the calls from "join the queue" to "receive tickets". Which call is the only one that must be strongly consistent, and which must be idempotent?
Compare with our answer
A strong answer mentions: join the queue (returns a token and position) · poll or subscribe for position until admitted with a signed access token · a cached seat map · a hold call that is all-or-nothing for several seats and returns an expiry · an order call with an idempotency key that turns a hold into a sale.
| Call | Request | Response | Notes |
|---|---|---|---|
GET /v1/events/{id} | – | { name, venue, onSaleAt } | Static: CDN-cached |
POST /v1/events/{id}/queue | – | { queueToken, position } | Join the waiting room |
GET /v1/queue/{token} | – | { position, eta } or { accessToken } | Poll (or WebSocket) until admitted |
GET /v1/events/{id}/seats | accessToken | { sections[{ seat, status }] } | Availability, cached for 1–2 s |
POST /v1/holds | { eventId, seatIds[], accessToken } | 201 { holdId, expiresAt } or 409 | Atomic: all seats or none |
POST /v1/orders | { holdId, paymentMethodId } | 201 { orderId, tickets[] } | Idempotency-Key header |
Every call after admission carries the access token: a short-lived, signed value (for example an HMAC over user ID, event ID and expiry) that the gateway can verify without a database lookup. Without it, a bot could skip the queue by calling /holds directly.
4. Data model
What is the most contended data in the system, and how do you store it so two fans can't both get seat A12? Where do holds and the queue live?
Compare with our answer
A strong answer mentions: one row per seat per event with a status, hold ID and hold expiry · holds as records with an expiry, released automatically · the queue in Redis (a sorted set or a counter) · orders and tickets in SQL · partitioning the seat inventory by event.
events SQL + CDN cache
event_id, venue_id, starts_at, on_sale_at
Small, read constantly, rarely changes.
seat inventory Strongly consistent store (SQL / Redis with atomic ops), per event
event_id, seat_idstatus: available | held | soldhold_id, held_until, version
The single most contended data: holds must be atomic.
holds Redis with TTL (+ DB record)
hold_id → seat_ids, user_id (TTL 600 s)
Expire automatically after 10 minutes so seats return to sale.
waiting room Redis sorted set / queue
queue:{eventId} → (token, joinedAt)admitted tokens (signed, short-lived)
Ordered positions and admission tokens for millions of users.
orders and tickets SQL
order_id, user_id, event_idticket_id, seat_id, barcode
Purchases, payments and barcodes: transactional.
A hold is a temporary reservation: the seats are taken off sale for, say, 10 minutes while the fan pays, then either become sold or return to available. The TTL (time to live) is the expiry. Note the design data keeps holds in two places (Redis with a TTL and the seat rows' held_until); in the deep dives we make the seat row the source of truth and treat Redis as optional, which removes a whole class of disagreements between the two.
5. High-level design
Sketch the layers a fan passes through from the first page load to a held seat. Which layers scale horizontally without limit, and which one can't?
Compare with our answer
Compare with the figure. The front layers (CDN, bot defence, waiting room, seat-map cache) are stateless or read-only and scale out; the seat inventory is the one thing that can't, because every hold on a seat must go to the same row. Everything in front exists to protect it.
The architecture, then joining the queue
- The architecture puts protection in front: CDN for static pages, bot defence, and a virtual waiting room that meters traffic. Behind it, a cached seat map for reads, a hold service doing atomic reservations on the seat inventory, and an order service for payment, with expiring holds.
- At 10 am, fans hit a static page from the CDN and are placed in a virtual waiting room after a bot check. The waiting room admits them at a steady rate the back end can handle, giving each a signed access token.
| Component | What it does |
|---|---|
| CDN | Event pages and assets; absorbs the initial stampede |
| Bot defence | Rate limits, fingerprinting, CAPTCHAs, verified-fan pre-registration |
| Virtual waiting room | Queues users and admits them at a safe rate with signed tokens |
| Seat map service + cache | Availability snapshot refreshed every 1–2 s |
| Hold service | Atomic all-or-nothing seat holds with a TTL |
| Seat inventory | Strongly consistent seat status per event |
| Order service + payments | Turns holds into sales; idempotent |
| Hold expirer | Releases seats from expired holds |
Hold the seats, then pay or let the hold expire
- Inside, the seat map comes from a cache refreshed every second or two. When the fan picks two seats, the hold service tries to reserve both atomically. If either is already taken, nothing is reserved and the fan picks again.
- If the fan pays in time, the held seats become sold and tickets are issued. If the timer runs out, the hold expires and the seats go back on sale automatically.
Trace a purchase out loud:
- At 10:00 the fan loads the event page from the CDN, passes bot checks, and joins the waiting room. They get a queue token and a position.
- When admitted, they receive a signed access token valid for, say, 15 minutes.
- They load the seat map (a snapshot cached for 1–2 seconds) and pick A12 and A13.
- The hold service flips both seats to
heldin one atomic conditional update. Both succeed or neither does. The fan sees a 10-minute countdown. - They pay with an idempotency key; the order service marks the seats
soldonly if the hold is still theirs and unexpired, and issues tickets.
6. Deep dives
Before reading on: name three ways to stop two fans holding the same seat, and one way each can fail. What happens if payment succeeds one second after the hold expired? How do you decide who gets in first?
Compare with our answer
A strong answer mentions:
- Row locks (
SELECT … FOR UPDATE): correct but deadlock-prone and must never span the payment. - Conditional updates: one statement, all-or-nothing, check the affected row count.
- Redis locks with a TTL: fast, but can be lost on failover or expire under a paused holder; need a fencing check at the database.
- Pay only against a valid hold; extend the hold while payment is in flight; void the payment if the sale can't complete.
- A waiting room that admits at a rate set by back-end health; randomised order for early arrivals; per-person limits; bot defence.
Double booking: three approaches compared
Two fans click A12 in the same millisecond. The naive code checks status = 'available' and then writes held; both checks pass before either write, and both fans get the seat. The three standard fixes:
1. Pessimistic row locks. Lock the seat rows, check, update, commit:
BEGIN;
SELECT seat_id, status FROM seats
WHERE event_id = 'E1' AND seat_id IN ('A12','A13')
ORDER BY seat_id FOR UPDATE; -- second fan waits here
-- if all are available:
UPDATE seats SET status = 'held', hold_id = 'h77', held_until = now() + interval '10 minutes'
WHERE event_id = 'E1' AND seat_id IN ('A12','A13');
COMMIT;
2. A conditional (optimistic) update. One statement does the check and the write:
UPDATE seats
SET status = 'held', hold_id = 'h77', held_until = now() + interval '10 minutes'
WHERE event_id = 'E1' AND seat_id IN ('A12','A13')
AND (status = 'available' OR (status = 'held' AND held_until < now()));
-- affected rows must equal 2; otherwise ROLLBACK: "a seat was just taken"
3. A Redis lock per seat. SET lock:E1:A12 h77 NX PX 600000 (set only if absent, expire in 10 minutes); several seats atomically through a small Lua script that sets all or none.
A hold is an atomic conditional update
- Each hold is an atomic conditional update: seats flip to held only if they’re still available, so two fans can never both get A12.
| Approach | Good at | Failure mode | Fix |
|---|---|---|---|
| Row locks | Familiar; arbitrary checks inside the transaction (limits per fan) | Deadlocks if two fans lock seats in different orders; lock queues on hot seats; disaster if held across payment | Lock in sorted order; keep the transaction milliseconds long; represent the 10-minute hold as a status, never as a lock |
| Conditional update | One round trip; no lock waits; multi-seat all-or-nothing inside one transaction | Many losers under contention (each just gets "taken"); a lost response looks like a failure | Idempotent by hold_id: if the seats are already held by h77, report success |
| Redis lock with TTL | Very fast; expiry built in | Redis replicates asynchronously, so a failover can lose the lock and a second fan gets it; a holder that pauses past its TTL still acts as if it holds it | Use it only as a front filter; the database checks a fencing token or the hold ID when selling |
Choice: conditional updates on the seat rows in a strongly consistent database, partitioned by event. 50,000 rows for one event fit easily on one primary, and a few thousand short conditional updates a second is within its reach. Redis can sit in front as a cache of availability, never as the authority.
Fencing: why a lock alone is not enough
A fencing token stops a holder whose lease has expired
A fencing token is a number that increases every time the lock is granted. The holder sends it with every write, and the storage rejects writes carrying a lower number than one it has already seen. Applied here: the hold ID (or a version number) on the seat row is the fence. Selling is UPDATE seats SET status = 'sold' WHERE seat_id = 'A12' AND hold_id = 'h77' AND held_until > now(). A fan whose hold expired and was re-held by someone else matches no row, however sure their client is that it still holds the seat. The general pattern, with more options, is in contention and double booking.
Holds with a TTL, and the payment race
Holds must expire, or abandoned checkouts would take seats off sale forever. Two mechanisms, used together:
- Lazy expiry: the hold query already treats
held_until < now()as available, so an expired hold is free the instant it expires, even if nothing has cleaned it up. - A sweeper that periodically resets expired holds to
available, so the seat map shows them and counts stay tidy.
The virtual waiting room
A waiting room meters the flash crowd
- Deep dive: the flash crowd. A virtual waiting room admits fans at a steady rate, turning a spike that would crash the site into a queue.
The waiting room turns a spike into a flow. Its parts:
- Join: the queue page is static (CDN); joining gets a position from an atomic counter (
INCR queue:E1) or a sorted set, plus a token. - Wait: the client polls a lightweight endpoint (or holds a server-sent-events connection) with a server-suggested interval, so millions of waiting clients don't hammer it.
- Admit: a controller lets in N fans a second and adjusts N from back-end health (hold latency, error rate, number of fans inside), like a thermostat.
- Pass: admitted fans receive a signed access token bound to their account and a short expiry, checked by the gateway on every call.
Fairness. Pure arrival order rewards whoever has the fastest connection or the most bots. A common rule: everyone who joins before the on-sale time gets a random position at 10:00 (so opening the page at 9:55 or 9:59 doesn't matter); after that, first come, first served. Add per-account ticket limits, verified-fan pre-registration (fans register days earlier and receive codes), and one queue position per account.
The seat map: eventually consistent reads, exact writes
24,000 seat-map reads a second must not touch the seat rows that holds are fighting over. Serve a snapshot rebuilt every 1–2 seconds from the inventory and cached at the edge. A fan who clicks a seat that was taken in the last second gets "just taken, pick again", which is acceptable because the hold is the exact check.
Two refinements interviewers like: send deltas (seats changed since version N) instead of whole maps for a 50,000-seat stadium, and offer "best available": the fan chooses a section and quantity and the server picks seats, which removes most of the collisions caused by thousands of fans clicking the same front-row seats.
7. Bottlenecks, failures and monitoring
Scaling bottlenecks
| Bottleneck | Fix |
|---|---|
| Read stampede on event pages | CDN with long cache times; static HTML |
| Seat inventory contention | Per-event partitioning; short transactions; holds in Redis with atomic scripts |
| Payment provider rate limits | Hold timer gives slack; queue payments; multiple providers |
| Waiting room itself | Simple, horizontally scaled, mostly static pages polling a lightweight endpoint |
When things fail
| Failure | What happens |
|---|---|
| Hold service node fails | Holds are persisted; clients retry; idempotent hold ids |
| Payment slow during the rush | Hold timer extended slightly; payments retried with the same key |
| Expirer stops | Seats stay held too long; alert, and paying checks expiry anyway |
| Waiting room overloaded | Serve the queue page statically; slow admission rather than fail |
What to monitor
Admission rate vs back-end healthHold success / conflict rateDouble-booking checks (must be 0)Payment successQueue length and wait timeBot block rate
8. Follow-up questions
Answer in order: 1) The event is general admission: 20,000 standing tickets, no seat numbers. What changes? 2) The database primary for a hot event fails over mid-sale. What could go wrong, and what doesn't? 3) Fans complain that seats shown as available are always "just taken". Why, and what do you change?
Compare with our answer
A strong answer mentions:
- A counter per section with a conditional decrement (
WHERE remaining >= n), plus hold rows; one hot row instead of many, so split it into several counters if needed. - With synchronous replication no committed hold is lost; in-flight holds fail and are retried idempotently by hold ID; a brief pause in admission; Redis-only holds would have been lost.
- The snapshot is stale and everyone targets the same seats; shorten the refresh, push deltas, and steer fans to "best available".
How would you handle general admission (no seat numbers)?
A single counter per section: atomic decrement, like inventory; much less contention than per-seat maps.
How is fairness defined in the queue?
Often: everyone who arrives before the on-sale gets a random position; after that, first come first served.
How do tickets stop being copied?
Rotating barcodes in the app (time-based codes), tied to the account, checked at the gate.
- Numbers: 1 M fans in 60 s ≈ 17 K arrivals/s; 20 fans per seat; admit 2,000/s → ~8 min to drain; ~24 K seat-map reads/s inside.
- Shape: protect a tiny, consistent core (seat rows) behind CDN, bot defence and a waiting room.
- Double booking: conditional update
WHERE status = 'available' OR held_until < now(), affected rows must equal seats requested, all-or-nothing. - Row locks: sorted order, millisecond transactions, never across payment.
- Redis locks: fast filter only; failover and expired leases break them; the database checks the hold ID as a fencing token.
- Holds: 10-minute TTL; lazy expiry plus a sweeper;
payingstate extends the hold. - Sell: authorise, conditional update to
soldby hold ID, then capture; void if 0 rows. - Waiting room: static page, atomic position counter, admission rate from back-end health, signed account-bound tokens.
- Fairness: random order for pre-on-sale arrivals, per-account limits, verified fans.
- Seat map: 1–2 s snapshot, deltas, "best available" to cut collisions.
1. Two fans try to hold seat A12 at the same moment. Which approach is correct and keeps transactions short?
The conditional update is the check and the write in one atomic step. Read-then-write races; a table lock serialises the whole sale; the cache is stale by design.
2. A team holds seats with SELECT … FOR UPDATE and keeps the transaction open until the fan pays. What goes wrong?
A hold that lasts minutes must be a status with an expiry, not a lock. Locks should last milliseconds.
3. Seats are held with a Redis SET … NX PX lock. Which failure can still cause a double booking?
Redis replicates asynchronously. Use it as a filter and make the database's conditional sale (checking the hold ID) the final word.
4. A fan's payment confirms three seconds after their hold expired, and another fan now holds the seat. What should the order service do?
The sale is conditional on the hold ID and expiry. Authorise first, capture only after the seat is confirmed; void otherwise. A "paying" state that extends the hold makes this rare.
5. 1 M fans arrive in a minute and the waiting room admits 2,000 a second. How long until everyone has had a turn?
1,000,000 ÷ 2,000 = 500 s ≈ 8 minutes. With 50,000 seats, it will sell out long before the queue drains.
6. Fans who opened the queue page at 9:50 always beat fans who arrived at 9:59. Which change makes the on-sale fairer without favouring bots?
Randomising the pre-on-sale pool removes the reward for arriving early or scripting the join; later arrivals still queue in order.
7. The seat map is read 24,000 times a second. Where should those reads go?
Reads must not compete with holds on the hot rows. A short-lived snapshot is cheap, and the conditional hold catches the rare stale seat.
Score 60% or more and the lesson is marked complete.