Design a Seat Reservation System for Live Events
System DesignModel answerLast updated
Design a distributed ticketing platform that handles high search traffic, prevents duplicate seat bookings, and survives payment service failures.
Scenario
You're building the backend for a ticketing platform where fans purchase seats for concerts, sports games, and theater shows. During on-sale windows for popular events, demand spikes dramatically — thousands of people refresh the page simultaneously and race to grab the last few seats.
Your task is to design the core reservation system that powers this platform.
Functional Requirements
- Users can browse available seats for an event, filtered by section, price tier, and date.
- A user can select a seat and initiate a purchase, which locks that seat for up to 10 minutes while they complete checkout.
- After the hold period, the seat is released back to inventory if payment is not completed.
- The system integrates with an external payment processor to finalize purchases.
Non-Functional Requirements
- No duplicate bookings: two users must never end up with a confirmed ticket for the same seat.
- Search must stay responsive even during traffic spikes; slight staleness in availability counts is acceptable.
- Purchases must be durable: if a payment succeeds but an internal service crashes immediately afterward, the booking must still be recorded.
What to Cover
- API surface — define the key endpoints for browsing inventory, creating a hold, and confirming a purchase.
- Data model — propose a schema covering events, seats, hold state, and reservations.
- Concurrency handling — walk through exactly what happens at the database level when two users simultaneously try to claim the last seat in a section.
- Architecture and state transitions — describe the services involved and explain how a reservation moves from
HELDtoCONFIRMEDgiven that the payment call is asynchronous and the processor may be slow or temporarily unreachable.
Hints
Hint 1
Search traffic and booking traffic have fundamentally different consistency requirements — it helps to design them as two separate paths rather than forcing a single architecture to serve both.
Hint 2
The safest way to prevent a double-booking is an atomic conditional UPDATE that checks and decrements inventory in one statement, rather than a read-then-write pattern that leaves a gap for a race condition.
Hint 3
Payment processors are unreliable and retry webhooks, so every state transition should be written as an idempotent guarded update — and a background reconciliation job should handle the case where the webhook never arrives.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify Scale First
Pin down numbers before designing anything — they determine which trade-offs actually matter.
- Inventory: ~50K venues, ~5M seats. Seats are specific and physical (seat 14, row G, section 101), so a booking is for a single seat ID, not a room type. That actually simplifies the concurrency model.
- Search: ~30–50K QPS during a major on-sale. Read:write is at least 100:1. Slight staleness is fine.
- Holds: ~500–2,000/sec at peak. This path must be strongly consistent.
- Hold window: 10 minutes. The payment processor is external, takes 1–5 s, and sometimes goes down.
The key insight to state early: search is AP, booking is CP. Design them as separate paths or you'll over-engineer one and under-engineer the other.
2. API Design
GET /v1/events/{event_id}/seats
?section=101&tier=floor&available_only=true
-> [{seat_id, label, price, status: "AVAILABLE|HELD|SOLD"}]
POST /v1/holds
Idempotency-Key: <client-uuid>
Body: {seat_id, event_id, user_id}
-> 201 {hold_id, status: "HELD", expires_at, checkout_url}
-> 409 if seat is already taken
POST /v1/holds/{hold_id}/payment
Body: {payment_method_token}
-> 202 {status: "PAYMENT_PENDING"}
GET /v1/holds/{hold_id} # poll for status updates
POST /v1/webhooks/payments # processor callback, signature-verified
DELETE /v1/holds/{hold_id} # user cancels before expiry
The Idempotency-Key on hold creation is not optional. A user double-tapping or a mobile client retrying on a flaky connection must not create two holds for the same seat.
3. Data Model
Use a relational database (Postgres) sharded by event_id. Every booking transaction for a given event stays on one shard, eliminating distributed transactions.
events(event_id PK, venue_id, name, start_time, ...)
seats(seat_id PK, event_id, section, row, number, tier, base_price)
seat_status(
seat_id PK, -- one row per seat
event_id,
status ENUM('AVAILABLE','HELD','SOLD'),
hold_expires_at TIMESTAMP,
version INT DEFAULT 0 -- for optimistic locking if needed
)
reservations(
reservation_id PK,
idempotency_key UNIQUE,
seat_id, event_id, user_id,
status ENUM('HELD','PAYMENT_PENDING','CONFIRMED','EXPIRED','CANCELLED','FAILED'),
hold_expires_at TIMESTAMP,
payment_intent_id,
created_at, updated_at
)
outbox(
event_id PK, aggregate_id, type,
payload JSONB, published BOOL DEFAULT false, created_at
)
4. Concurrency: Two Users, One Seat
Never read-then-write. Use a single atomic conditional update inside a transaction:
BEGIN;
UPDATE seat_status
SET status = 'HELD',
hold_expires_at = now() + interval '10 minutes'
WHERE seat_id = :seat_id
AND status = 'AVAILABLE';
-- affected_rows == 0 means the seat was already taken
-- ROLLBACK and return 409 to the client
INSERT INTO reservations (
reservation_id, idempotency_key, seat_id, event_id, user_id,
status, hold_expires_at
) VALUES (..., 'HELD', now() + interval '10 minutes');
COMMIT;
Why this works: the UPDATE takes a row lock on seat_id. The second concurrent transaction blocks, then re-evaluates status = 'AVAILABLE' after the first commits — finds it HELD, gets affected_rows = 0, and rolls back. The client receives a clean 409.
Trade-off comparison:
SELECT ... FOR UPDATEis equally correct but holds the lock longer.- Optimistic locking with a
versioncolumn works fine under low contention but causes retry storms during flash sales for a popular event. - A distributed lock (Redis/Redlock) adds operational complexity and clock-safety concerns when the database already provides the atomicity you need. Avoid it here.
5. Architecture and the HELD → CONFIRMED Transition
Client
-> API Gateway
-> Seat Search Service -> Search Index (Elasticsearch)
-> Redis availability cache
-> Reservation Service -> Seat/Reservation DB (primary, sharded by event_id)
-> Outbox -> Kafka -> Payment Worker -> Processor
Processor webhook -> Webhook Handler -> Kafka -> Reservation Service
CDC (Debezium) from DB -> Kafka -> Search indexer (updates cache/index async)
Hold Sweeper (scheduled job every 30s)
Reconciler (polls processor for stuck PAYMENT_PENDING records)
State machine
HELD -> PAYMENT_PENDING -> CONFIRMED
HELD -> EXPIRED (sweeper fires after 10 min)
HELD -> CANCELLED (user cancels)
PAYMENT_PENDING -> FAILED
Every transition is a guarded update:
UPDATE reservations
SET status = 'CONFIRMED'
WHERE reservation_id = :id
AND status = 'PAYMENT_PENDING';
This makes webhook replays and Kafka redeliveries safe — duplicate transitions are no-ops.
Payment flow in detail
- User submits payment token → Reservation Service sets status to
PAYMENT_PENDING. In the same transaction, it writes aChargeRequestedevent to the outbox. This is the transactional outbox pattern: the intent survives even if the service crashes before publishing. - An outbox relay publishes to Kafka. The Payment Worker calls the processor using
reservation_idas the processor's idempotency key, so retries never charge twice. - The processor responds via webhook. The handler persists the result to Kafka before returning HTTP 200, then the Reservation Service applies the state transition and updates
seat_statustoSOLD.
"Payment succeeded but we crashed"
Three layers ensure a successful charge always produces a confirmed booking:
- Durable intent via the outbox — the charge request survives crashes.
- Webhook retries — processors retry on non-2xx until they succeed.
- Reconciler — a periodic job queries the processor for every reservation stuck in
PAYMENT_PENDINGfor more than N minutes and forces the correct outcome. A successful charge that somehow lost its webhook always resolves toCONFIRMED. If inventory was corrupted, it resolves to an explicit refund plus an alert — never a silent loss.
6. Key Trade-offs to Address
- Stale search results. The search index is updated asynchronously. A seat shown as available may already be held. That's acceptable because the booking path re-validates against the DB and returns a 409 with alternatives. Don't try to make search perfectly consistent — it kills availability.
- Hold duration. A 10-minute hold locks sellable inventory. Shorter holds improve turnover but hurt conversion. This is a business decision, not a technical one.
- Hot events. Row-level locking during a Taylor Swift on-sale is real contention, but it's millisecond-scale. For extreme spikes, put a virtual queue (similar to Ticketmaster's waiting room) in front of the event shard to rate-limit concurrent hold attempts.
- Overbooking. For standing-room or general-admission inventory, the system can model available count instead of individual seats, using the same
reserved_rooms < total_roomspattern from venue-style inventory. The physical-seat model here intentionally avoids that ambiguity.
What Distinguishes a Strong Answer
- Articulating the AP/CP split before touching any component.
- Showing the exact SQL that prevents double-booking rather than hand-waving "use a lock."
- Covering idempotency at every hop: client key, Kafka consumer, payment worker, webhook handler.
- Knowing the reconciler exists — not just webhooks — to handle processor-side failures.