Building a Flash-Sale Seat Booking Platform
System DesignModel answerLast updated
Design a booking backend for hot live events that never double-sells a seat, holds seats briefly during checkout, guarantees tickets after successful payment, and fairly offers released seats to a waitlist.
Problem
Design the backend for a platform that sells seats to live events. When a popular event goes on sale, a huge crowd (hundreds of thousands of people) arrives within seconds and competes for a limited number of individually numbered seats.
Requirements
- Burst traffic. Tens or hundreds of thousands of users may try to buy for the same event at the same instant. No seat may ever be sold twice, and response times should stay low.
- Seat inventory and temporary holds.
- Events have sections and individually identifiable seats.
- When a buyer begins checkout, the chosen seats are held for a short window (for example 5 minutes).
- A hold that is not paid for in time must lapse by itself and return the seats to the available pool.
- Payment guarantee.
- Payment goes through a third-party provider that can take several seconds, or occasionally much longer.
- If a payment succeeds, the buyer must always end up with the seats they were shown as held.
- If payment fails or does not complete, the seats must be released.
- Sold-out waitlist.
- When nothing is available, users can join a waitlist.
- When held seats come back (hold or payment expiry, cancellation), waitlisted users should be offered them automatically in a fair order.
- Decide how users are notified and how long they have to claim an offer.
- Correctness. Describe how you prevent two buyers from getting the same seat across many servers, how you resolve races, and which consistency guarantees you offer.
- Scale. The system must scale horizontally. Consider the access patterns for browsing, seat selection, holding, checkout and ticket issuance, and propose a data model and storage strategy for events, seats, holds, and orders.
- Components and APIs. Name the main services (e.g. gateway, catalog, inventory/hold service, payment integration, waitlist) and sketch the key endpoints: search events, fetch seat map, create hold, pay, cancel hold, join waitlist.
What to cover
Walk through the design end to end: data modeling, concurrency control, hold expiry, payment-provider integration, waitlist behavior, and how you would test and monitor it in production.
Hints
Hint 1
A 50k-seat venue cannot serve 500k simultaneous buyers. Think about how to throttle or queue users before they ever reach the database that owns seat state.
Hint 2
Make the database row the arbiter: a single conditional update that only succeeds when the seat is free (or its hold has lapsed). Think about what happens if the background expiry job runs late.
Hint 3
Consider what happens when a payment completes right around the hold deadline. A dedicated 'payment in progress' seat state that expiry logic ignores, plus authorize-then-capture and a reconciler for unknown outcomes, closes this gap.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing and numbers
State assumptions first. Example: a 50k-seat stadium, about 500k users arriving in the first minute, browse traffic roughly 100x purchase traffic, a 5-minute hold, and payment providers that usually answer in seconds but sometimes take far longer.
Targets:
- Seat ownership is strongly consistent: zero double-sales.
- Seat maps and search can be eventually consistent (about 1 s stale is fine).
- Hold creation p99 around 200 ms. Seat map reads from cache in under 50 ms.
Key observation: only 50k seats exist, so admitting all 500k users to the hold path is wasteful. Admission control protects both correctness and cost.
Traffic shaping
Put a virtual waiting room in front of the on-sale. Users get a queue position and a signed admission token; the system admits them at a rate the inventory store can sustain (a few thousand holds per second). The hold endpoint rejects requests without a valid token. Static content and seat-map snapshots are served from a CDN or cache. Add rate limits and bot defenses at the gateway.
Components
- Gateway: auth, rate limiting, bot checks.
- Waiting-room service: Redis-backed queue, issues admission tokens.
- Catalog service: search (a search index) and event details, served from replicas and caches.
- Inventory/hold service: stateless; owns seat-state transitions.
- Checkout/order service and payment adapter: talks to the provider.
- Expiry worker: delay queue plus a periodic sweeper.
- Waitlist and notification services.
- Event bus (via a transactional outbox) for seat-released and order-confirmed events.
Data model
Use a relational store, sharded by event ID, so every seat of one event lives on one shard and a hold is a single-shard ACID transaction. One event with 50k seats is small; the admission rate bounds the write load.
events(event_id, venue_id, start_time, on_sale_at, status)seats(event_id, seat_id, section, row, tier, status, hold_id, hold_expires_at, version), PK(event_id, seat_id). Status is one of AVAILABLE, HELD, PAYMENT_PENDING, SOLD.holds(hold_id, event_id, user_id, seat_ids, status, expires_at, idempotency_key UNIQUE)orders(order_id, hold_id UNIQUE, amount, payment_status, provider_ref, idempotency_key UNIQUE)tickets(ticket_id, order_id, event_id, seat_id UNIQUE). The unique seat constraint is the final safety net against double issuance.waitlist: a Redis sorted set per event (score = join time), mirrored to a table for durability.outbox: events published reliably to the bus.
Concurrency control
A hold is one atomic conditional update inside a transaction:
UPDATE seats
SET status='HELD', hold_id=:h, hold_expires_at=now()+interval '5 min', version=version+1
WHERE event_id=:e AND seat_id = ANY(:seats)
AND (status='AVAILABLE' OR (status='HELD' AND hold_expires_at < now()));
-- commit only if rows_updated = number of seats requested, else roll back and return 409
- All or nothing: the user gets every requested seat or none.
- Row locks arbitrate: concurrent racers serialize on the row; one wins, the rest see the changed predicate and get a conflict. No distributed lock is needed.
- Lazy expiry in the predicate: an expired hold is reclaimable immediately, so correctness never depends on the background job being on time.
- Deadlock avoidance: sort seat IDs before updating.
- "Best available" requests: select candidates with
FOR UPDATE SKIP LOCKEDso buyers do not queue on the same rows. - Optional Redis pre-filter to reject obvious losers early; the database remains the decider.
Guarantee: linearizable seat ownership per event, backed by the unique constraint on tickets.
Hold expiry versus payment
The dangerous case is payment that succeeds right at, or just after, the hold deadline. Solve it with a state machine where starting payment freezes the seats:
- Begin checkout: in one transaction, verify the hold is HELD and unexpired, move seats to PAYMENT_PENDING with a longer deadline (say 15 min), and create a PENDING order keyed by an idempotency key. Neither the sweeper nor the lazy-expiry predicate touches PAYMENT_PENDING seats.
- Authorize (not capture) with the provider, using the order ID as the provider-side idempotency key.
- Authorization succeeds: in one transaction mark seats SOLD, insert tickets, confirm the order, write an outbox event. Then capture. Since the seats were frozen, this commit cannot lose a race.
- Authorization fails: return seats to AVAILABLE, mark the order FAILED, emit a seat-released event.
- Unknown outcome (timeout, crash): a reconciler queries the provider by order ID; provider webhooks feed the same idempotent handler. If the frozen deadline passes with no answer, void the authorization first, then release the seats.
Money is only captured after seats are SOLD, so payment implies a ticket by construction. Rare stuck cases end as a void or refund, never an oversell.
Expiry worker: schedule each hold on a delay queue and run a sweeper as a backstop. Release with WHERE status='HELD' AND hold_id=:h AND hold_expires_at < now(), which is idempotent, then publish a seat-released event.
Waitlist
- Join:
POST /events/{id}/waitlistwith quantity and optional section preference. Order is by join time (FIFO), per event. - A consumer of seat-released events matches released seats to the earliest compatible waitlist entries.
- Matching does not sell the seats; it creates a short offer hold (for example 10 minutes) through the normal hold path, so the same concurrency rules apply. The user is notified by push, SMS or email with a link.
- If the offer is not claimed in time, it expires, the seats are released again, and the next entry is offered them. Skipping entries whose quantity does not fit avoids blocking the line, while remembering their position for fairness.
- Cap waitlist size and dedupe per user.
APIs
GET /events?q=&city=&date=
GET /events/{id}/seatmap
POST /events/{id}/queue
POST /events/{id}/holds {seat_ids[], token, idempotency_key}
POST /holds/{id}/checkout {payment_method, idempotency_key}
DELETE /holds/{id}
POST /events/{id}/waitlist {quantity, section_pref}
GET /orders/{id}
All mutating calls take idempotency keys so retries are safe.
Testing and monitoring
- Testing: concurrent load tests hammering the same seats and asserting zero duplicates; fault injection on the payment provider (timeouts, duplicate webhooks, late success); clock-skew and worker-crash tests; a replay test that checks the invariant "every captured payment has exactly one ticket set".
- Monitoring: hold success/conflict rate, queue depth and admit rate, expiry lag, count of orders stuck in PENDING, reconciler backlog, provider latency and error rates, waitlist offer acceptance rate. Alert on any ticket-uniqueness violation or captured-without-ticket order.
Common mistakes
- Relying on the background job for expiry correctness.
- Letting expiry release seats while a payment is in flight.
- Using a distributed lock where a conditional row update suffices.
- Letting the full crowd hit the inventory database.
- Capturing money before the seat is durably sold.
- Not making hold, payment and webhook handlers idempotent.