Seat Reservation Platform for High-Demand Ticket Sales
System DesignModel answerLast updated
Design a ticketing backend where thousands of buyers compete for the same seats, with temporary holds, safe checkout, and a firm guarantee that no seat is sold twice.
Seat Reservation Platform for High-Demand Ticket Sales
Design the backend for a ticketing service covering concerts, plays, and similar live events. Buyers browse events, look at a venue's seat map, pick particular seats, pay, and receive confirmed tickets. When a popular event goes on sale, a very large crowd arrives at once and goes after a limited set of seats.
What the system must do
- Show a list of events and the seat map for each venue.
- Let a buyer temporarily hold chosen seats (for example, 10 minutes) while they pay.
- Let the buyer complete payment to turn the hold into a confirmed booking.
- Once a seat is sold, no other buyer may obtain it.
Quality targets
- Stay available and scale during sale-start spikes.
- Seat ownership must be strongly consistent: the same seat can never go to two buyers.
- Seat selection and checkout must feel fast.
What to cover in your answer
- The main components and how a request flows through them.
- The API for viewing seats, holding them, and checking out.
- A data model for events, seats, holds, and bookings.
- Your concurrency approach: what happens when two buyers try to take the same seat at the same instant?
- Failure handling: what happens when a buyer abandons checkout or payment fails?
State your assumptions about scale (venue size, peak traffic, hold duration) and explain the trade-offs behind your choices.
Hints
Hint 1
Treat this as a contention problem rather than a CRUD problem: reads of the catalog and seat map are easy to cache, while a small number of hot seat rows decide correctness.
Hint 2
Let the database be the single arbiter of seat ownership: use a conditional atomic update (only change a seat if it is available or its hold has expired) and check the number of rows affected. Any cache or lock in front of it is only an optimization.
Hint 3
Make holds time-limited and idempotent, and make expiry safe in two ways: reclaim expired holds lazily inside the update condition, and run a background sweeper so the seat map shows seats as free again.
Hint 4
Do not block on the payment gateway. Return quickly from checkout, process payment asynchronously with an idempotency key, and make the final confirmation conditional on the hold still being yours.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model answer
The key framing is that this is a contention problem. Browsing is read-heavy and cacheable. Correctness depends on a small set of hot seat rows that many users hit within seconds.
1. Assumptions and scale
- Venues range from about 500 to 80,000 seats.
- Normal load is around 1K reads/s and tens of bookings/s.
- A major on-sale may bring 100K to 1M users to one event, with seat-map reads near 50K req/s and hold attempts near 10K req/s.
- Hold TTL is 10 minutes, with up to about 8 seats per order.
- Seat ownership must be linearizable per seat. Catalog and seat-map views may be stale by 1 to 2 seconds.
Contention is per event, so shard inventory by event_id. Each event's writes land on one partition, which keeps strong consistency cheap inside a shard.
2. Architecture
- CDN for static venue layouts, event pages, and assets.
- API gateway for auth, rate limits, and bot filtering.
- Waiting room enabled only for hot events; it admits users at a controlled rate using signed tokens.
- Catalog service backed by a read replica, cache, and search index.
- Inventory/booking service, stateless, owning holds and confirmations against the sharded seat database.
- Redis for per-event availability bitmaps and an optional fast pre-filter.
- Payment service consuming from a durable queue and talking to the gateway.
- Expiry worker that frees expired holds and publishes updates.
- Notification service for confirmations and tickets.
Write path: client, gateway, inventory service, seat DB transaction, update Redis bitmap, push change to clients via WebSocket/SSE.
3. API
GET /events?city=&date=&cursor= -> paginated list (CDN)
GET /events/{id} -> details + venue map (CDN)
GET /events/{id}/seats -> availability (cached ~1s)
POST /events/{id}/holds (Idempotency-Key)
{ seatIds: [...] } -> 201 { holdId, expiresAt } | 409 { unavailableSeatIds }
DELETE /holds/{holdId} -> release early
POST /holds/{holdId}/checkout (Idempotency-Key)
{ paymentMethodToken } -> 202 { bookingId, status: PAYMENT_PENDING }
GET /bookings/{bookingId} -> PAYMENT_PENDING | CONFIRMED | FAILED
Multi-seat holds are all-or-nothing. Idempotency keys make retries safe. Checkout is asynchronous so slow payments never tie up booking threads.
4. Data model
Event(event_id PK, venue_id, name, start_time, status, on_sale_at)
Venue(venue_id PK, name, layout_json)
Seat(event_id, seat_id, section, row, price_tier,
status {AVAILABLE, HELD, BOOKED},
hold_id, held_until, booking_id, version,
PK (event_id, seat_id))
Hold(hold_id PK, event_id, user_id, seat_ids, expires_at,
status {ACTIVE, CONVERTED, EXPIRED, RELEASED})
Booking(booking_id PK, hold_id UNIQUE, user_id, event_id, seat_ids,
amount, status {PAYMENT_PENDING, CONFIRMED, FAILED, REFUNDED},
payment_ref, idempotency_key UNIQUE, created_at)
The Seat row is the only place ownership is decided. Use a relational store (PostgreSQL, for example) or a document store with conditional writes, partitioned by event_id.
5. Concurrency: the core of the answer
Use a conditional atomic update and check how many rows it changed:
BEGIN;
UPDATE seat
SET status='HELD', hold_id=:h,
held_until=now()+interval '10 minutes', version=version+1
WHERE event_id=:e AND seat_id = ANY(:seats)
AND (status='AVAILABLE'
OR (status='HELD' AND held_until < now()));
-- if rows_affected <> number of seats requested: ROLLBACK, return 409
INSERT INTO hold(...);
COMMIT;
Why it works:
- Row locks mean that when two users race, exactly one update matches; the other sees zero rows and gets 409.
- The guarantee holds across any number of stateless app servers because the database decides.
- The transaction makes multi-seat holds all-or-nothing. Touch seats in sorted
seat_idorder to avoid deadlocks. - The
held_until < now()clause reclaims expired holds lazily, so correctness never depends on a sweeper.
Redis pre-filter (optional). SET seat:{e}:{s} holdId NX EX 600 rejects most losers in under a millisecond and shields the database. Never rely on it alone: failover can lose keys, and a lock without a fencing token is unsafe. The DB update is the real fence, with hold_id as the token.
Confirmation is also conditional:
UPDATE seat SET status='BOOKED', booking_id=:b
WHERE event_id=:e AND seat_id = ANY(:seats)
AND hold_id=:h AND status='HELD';
If the hold expired and someone else took the seat, this matches nothing and the confirm fails safely.
Alternatives considered. SELECT ... FOR UPDATE then update is correct but holds locks longer. Serializable isolation everywhere causes many aborts under hot contention. A single global lock service becomes a bottleneck and a single point of failure.
6. Abandoned checkout and payment failures
Abandonment. Every hold has an expiry. Lazy reclaim guarantees correctness; an expiry worker scanning an index on held_until every few seconds resets seats, marks holds EXPIRED, and updates the Redis bitmap so other users see the seats again. Polling an indexed column is simpler and more reliable than keyspace notifications or delay queues.
Payment flow.
- Checkout creates a
PAYMENT_PENDINGbooking, extends the hold once (for example, 5 minutes) to cover payment, and enqueues a payment job. - The worker calls the gateway with the same idempotency key, so retries never double-charge.
- On success, run the conditional confirm. If the hold was somehow lost, refund automatically and notify the user.
- On failure or timeout, mark the booking FAILED and release the seats.
- Reconcile periodically against the gateway for payments whose outcome is unknown.
7. Scaling and trade-offs
- Serve seat maps from CDN and short-lived cache; show sections or bitmaps rather than per-seat detail under extreme load.
- Use the waiting room to cap the write rate to what the shard can handle.
- Offer "best available" selection to reduce everyone clicking the same popular seats.
- Per-user and per-IP limits plus a cap on seats per order reduce hoarding and bots.
Common mistakes
- Checking availability with a SELECT and then updating separately (a classic race).
- Relying on Redis locks alone with no database fence.
- Depending only on a background job for expiry.
- Calling the payment gateway synchronously inside the booking transaction.
- Forgetting idempotency, which leads to duplicate holds or double charges on retry.
- Requiring strong consistency for the seat map display, which makes reads needlessly expensive.