Designing a Flash-Sale Ticketing Platform Without Overselling
System DesignModel answerLast updated
Design a worldwide ticketing service that survives on-sale stampedes, gives fast seat-map reads, and guarantees every seat is sold to at most one buyer.
Design a Ticketing Platform for High-Demand Sales
You are asked to design a worldwide ticketing service for concerts and sporting events. When a popular event opens sales, millions of people arrive at nearly the same moment, but only a small number of seats exist.
What the system must do
- Let people discover events by place, date range, and category.
- Show which seats are still free, with near-real-time freshness.
- Let a buyer place a temporary hold on seats (for example 10 minutes) while they pay.
- Never let one seat end up with two buyers.
Quality goals
- Seat browsing and selection should be fast and stay available under load.
- Booking must be strongly consistent so overselling is impossible.
- The platform must absorb sudden surges (the thundering herd) without collapsing.
What to cover
- The API for selecting seats and completing a purchase.
- Your choice of storage (relational vs. NoSQL) and the reasoning behind it.
- How you handle concurrent writers during hold and checkout.
- How you serve a huge volume of simultaneous seat-map reads.
State your assumptions about scale, call out trade-offs, and explain what happens on failures such as payment errors or expired holds.
Hints
Hint 1
Estimate the numbers first: successful writes are capped by the seat count, while read traffic is effectively unbounded. How does that asymmetry shape the architecture?
Hint 2
Make the hold a single atomic conditional write on the seat row (available or expired-hold becomes held), and let the database's row locking decide the winner. Think about what role a unique constraint plays as a last line of defense.
Hint 3
Separate the paths: serve layouts from a CDN, availability from a cache with short TTLs and pushed deltas, and put a queue or admission token in front of the booking API so only a controlled rate of users reaches the database.
Hint 4
Payment is slow and can fail. Model checkout as a state machine with idempotency keys, and authorize payment before committing inventory, capturing afterwards.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
1. Sizing and the core insight
Assume about 1M events per year, normal search load of 5-10K QPS, and a hot sale of a 50K-seat venue with around 5M users arriving within minutes. Successful writes are bounded by inventory: at most 50K sales and perhaps 200K hold attempts. Reads are not bounded: seat-map polling may reach 500K-1M requests per second.
The design principle follows directly: protect a small, strongly consistent write path from a huge, cacheable read path. Booking needs linearizable behavior; search and seat maps can be stale by 1-2 seconds.
Holds last 10 minutes and are capped at roughly 6-8 seats per user.
2. API sketch
GET /events?lat=&lng=&radius=&from=&to=&category=&cursor=
GET /events/{id}/seatmap -> layout ref, availability bitmap, version
WS /events/{id}/seatmap/stream -> availability deltas
POST /queue/{id}/join -> queue token
GET /queue/{id}/status -> position or admission token
POST /events/{id}/holds (Idempotency-Key, Admission-Token) {seatIds}
-> 201 {holdId, expiresAt} | 409 {unavailable}
DELETE /holds/{holdId}
POST /holds/{holdId}/checkout (Idempotency-Key) {paymentToken} -> 202 {orderId}
GET /orders/{orderId}
Idempotency keys on all mutations make client retries safe. Checkout returns 202 because the payment provider call is slow and asynchronous.
3. Storage
Inventory, holds, and orders go in a relational store (Postgres/MySQL, or Spanner/CockroachDB for multi-region). We need ACID transactions across seats, holds, and orders, conditional updates, and unique constraints as a final safeguard. NoSQL can work but pushes correctness into application code.
Shard by event_id so one event's inventory is on one shard and no transaction crosses shards. Even a hot event produces only a few thousand writes per second, which a well-sized primary can handle; split by section if needed.
seats(event_id, seat_id, section, row, tier, status, hold_id, hold_expires_at, version,
PRIMARY KEY(event_id, seat_id))
holds(hold_id PK, event_id, user_id, expires_at, status)
orders(order_id PK, hold_id UNIQUE, user_id, amount, status, idempotency_key UNIQUE)
tickets(event_id, seat_id, order_id, PRIMARY KEY(event_id, seat_id))
The primary key on tickets guarantees one sale per seat even if application logic has a bug.
Other stores: Elasticsearch/OpenSearch for search (geo, date, category facets), fed by CDC through Kafka and eventually consistent; Redis for availability bitmaps.
4. Concurrency in hold and checkout
Hold is one atomic conditional update in a transaction:
UPDATE seats SET status='HELD', hold_id=:h, hold_expires_at=now()+interval '10 min'
WHERE event_id=:e AND seat_id IN (:sorted_seats)
AND (status='AVAILABLE' OR (status='HELD' AND hold_expires_at < now()));
-- if rows affected != number of seats requested: rollback, return 409
INSERT INTO holds ...;
- The row lock serializes competing writers, so exactly one wins each seat.
- Expired holds are reclaimed inside the predicate, so correctness does not depend on a cleanup job. A sweeper still frees them so the map refreshes promptly.
- Lock seats in sorted order to avoid deadlocks. Make the multi-seat hold all-or-nothing.
Redis alternative: SET seat:{e}:{s} holdId NX PX 600000 (or a Lua script for multiple seats) gives sub-millisecond holds and native TTLs, but asynchronous replication can lose acknowledged writes on failover. A good compromise is Redis as a fast-path gate that sheds contention, with SQL as the source of truth. Redis buys speed; SQL buys correctness.
Checkout is a saga with order states PENDING -> PAYMENT_AUTHORIZED -> CONFIRMED (or FAILED/REFUNDED):
- Validate the hold and extend it a couple of minutes as a payment grace period.
- Create the order under the idempotency key; authorize payment using the order ID as the provider's idempotency key.
- In one transaction, mark seats
SOLD(conditional onhold_idstill matching), insert tickets, confirm the order. - Capture payment. If step 3 fails, void the authorization.
Authorize-then-capture ensures money is taken only after inventory is committed.
5. Read-heavy seat maps
- CDN for static layout (geometry, sections, prices).
- Availability as a bitmap: 50K seats is about 6 KB, held in Redis and updated from the DB via CDC.
- Versioned delivery: clients fetch bitmap plus version, then receive deltas over WebSocket/SSE from a pub/sub tier separate from the API servers.
- Micro-caching at the edge for about 1 second collapses a million identical requests into a handful of origin reads.
- Staleness is fine: clicking a just-taken seat returns 409 and a refreshed map. Truth is only enforced at hold time.
- Read replicas serve order history and admin, never the hold decision.
6. Thundering herd
- Virtual waiting room: users join a queue before the sale. Early arrivals get random positions (so refreshing early doesn't help); later arrivals are FIFO.
- An admission service releases users at a rate matched to downstream capacity (e.g. 2K/s) and issues a short-lived signed admission token bound to user and event.
- The booking API rejects requests without a valid token, so the database only sees a controlled load.
- Add per-user and per-IP rate limits, bot detection, and per-user seat caps.
- Autoscale stateless tiers, but treat the DB write path as fixed capacity guarded by the queue.
7. Failure modes and trade-offs
- Payment fails or user abandons: hold expires and the seat is reclaimed; void any authorization.
- Crash between authorize and commit: a reconciliation job scans stuck
PENDINGorders and voids or completes them. - Region failure: with a single-leader-per-event model, fail over to a synchronous replica to avoid losing committed bookings; accept brief unavailability over inconsistency.
- Duplicate requests: idempotency keys plus unique constraints.
Common mistakes
- Sending seat-map reads to the primary database.
- Using "check then update" in two steps instead of one conditional write.
- Relying on a TTL-cleanup job for correctness.
- Charging the card before inventory is secured.
- Letting the full crowd hit the booking API with no admission control.
- Claiming strong consistency everywhere, when only booking needs it.