Design a Real-Time Event Ticketing and Seat Reservation Platform
System DesignModel answerLast updated
Design a scalable event ticketing backend that supports high-throughput browsing and guarantees strong consistency during high-contention seat reservation and payment flows.
Architect the backend infrastructure for a high-volume event ticketing service where clients can browse active venues, select specific seats on a interactive seating layout, and complete purchases.
Your solution must gracefully manage major traffic spikes when highly anticipated tickets drop, ensuring strict isolation so that no individual seat is ever double-booked across competing transactions.
Core Functional Requirements
- Catalog & Availability: Users can search events and retrieve live seat availability for specific event maps.
- Temporary Holds: A user can lock one or more seats for a configurable time window (e.g., 10 minutes) to proceed through checkout.
- Checkout & Purchase: Users can supply payment information to finalize holds into confirmed orders.
- Automatic Hold Expiration: If the checkout timer elapses prior to payment authorization, reserved seats must immediately return to the open pool.
Core Non-Functional Requirements
- Strict Data Consistency: Absolute linearizability for seat allocations—zero overbooking or concurrent assignment of identical seats.
- Massive Scalability: Support traffic surges up to 100,000 requests per second (RPS) during major drop times without degrading write safety.
- High Read Availability: Viewing event listings and seat maps must remain fast and available, even during peak load.
- Auditability & Traceability: Retain an immutable audit trail of every seat state transition for accounting, fraud detection, and operational debugging.
Expected Deliverables
- High-Level System Architecture: Diagram narrative and service layout separating read-heavy catalog paths from write-heavy transactional paths.
- API Specification: Endpoint contracts for seat locking, checkout, and payment processing.
- Data Model Strategy: Storage technology selection (SQL vs. NoSQL) with exact table/document schemas and primary/secondary indexing choices.
- Concurrency & Reservation Mechanics: Technical depth on preventing race conditions, handling state transitions, and managing queue admission during high-contention scenarios.
Hints
Hint 1
Differentiate the read path (seat availability maps) from the write path (locking specific seat IDs). Seat maps can accept second-scale staleness, while seat allocation requires strict linearizability.
Hint 2
Consider how an atomic conditional SQL query (`UPDATE ... WHERE status = 'AVAILABLE'`) can act as the ultimate single source of truth, avoiding split-brain scenarios common in distributed locks.
Hint 3
Incorporate a virtual waiting room or traffic shaper upstream to convert massive incoming traffic spikes into a controlled, manageable stream of requests aligned with database write capacity.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. System Requirements & Capacity Estimations
Scale Assumptions
- Active Events & Venues: ~10,000 active events simultaneously; venue capacity ranges up to 80,000 seats.
- Peak Demand Load: Up to 100,000 RPS during high-profile ticket launches.
- Read-to-Write Ratio: 95:5 during peak launches. Reads primarily consist of polling seat map states and catalog listings.
- Physical Limit on Writes: A 50,000-seat event can yield at most 50,000 successful bookings regardless of request volume. The system design must prioritize rejecting unsuccessful contention early at low cost rather than attempting to write 100k DB transactions per second.
- Reservation Hold Window: 10 minutes.
2. API Design
Interactive Seat Map & Availability
GET /v1/events/{eventId}/seats
- Response (200 OK):
{
"eventId": "evt_9981",
"generatedAt": "2026-03-30T10:00:00Z",
"seats": [
{ "seatId": "SEC101-A-12", "price": 15000, "status": "AVAILABLE" },
{ "seatId": "SEC101-A-13", "price": 15000, "status": "HELD" }
]
}
Reserve Seats (Temporary Hold)
POST /v1/events/{eventId}/holds
Header: Idempotency-Key: <UUID>
- Request Body:
{
"seatIds": ["SEC101-A-12", "SEC101-A-13"]
}
- Response (201 Created):
{
"holdId": "hld_44321",
"expiresAt": "2026-03-30T10:10:00Z",
"seatIds": ["SEC101-A-12", "SEC101-A-13"],
"totalAmount": 30000
}
- Response (409 Conflict):
{
"errorCode": "SEATS_UNAVAILABLE",
"conflictedSeatIds": ["SEC101-A-12"]
}
Initiate Checkout
POST /v1/holds/{holdId}/checkout
Header: Idempotency-Key: <UUID>
- Request Body:
{
"paymentMethodId": "pm_card_visa_1111"
}
- Response (202 Accepted):
{
"orderId": "ord_88712",
"status": "PROCESSING"
}
3. High-Level System Architecture
[ Client Applications ]
│
▼
[ Cloud CDN ] ── (Static Assets & Cached Catalog Pages)
│
▼
[ API Gateway ] ── (Auth, Rate Limiting, TLS Termination)
│
├──> [ Virtual Waiting Room Service ] (Token Admission via Redis)
│
├──> [ Seat Map Read Service ] ───────> [ Redis Read Cache ]
│ ▲
│ CDC / Events │
│ │
└──> [ Reservation Service ] ────────> [ Primary OLTP DB (PostgreSQL) ]
│ │ (Outbox Pattern)
▼ ▼
[ Payment Gateway ] [ Event Bus (Kafka) ]
│
▼
[ Audit & Ledger Worker ]
Key Components
- Virtual Waiting Room (Traffic Shaper): Uses a FIFO queue backed by Redis Sorted Sets. During peak traffic events, incoming clients are issued signed admission tokens. Only requests carrying a valid admission token can reach the Reservation Service, smoothing 100k RPS surges down to a steady rate aligned with database write throughput (e.g., 2k write RPS).
- Seat Map Read Service: Fetches seat layouts and status from distributed in-memory caches (Redis). Accepts eventual consistency (~1-2 second lag) for seat map renders.
- Reservation Service: Handles atomic seat reservations and manages state transitions using sharded relational storage.
- Payment Processing Engine: Integrates asynchronously with external PSPs (Payment Service Providers) using webhooks and background worker verification.
4. Storage Architecture & Data Schema
Because seat assignment demands multi-row atomic updates, predictable isolation, and ACID guarantees, a relational database engine (e.g., PostgreSQL or Amazon Aurora MySQL) is selected for inventory state. Multi-tenant partitioning is achieved by sharding data by event_id.
CREATE TABLE events (
event_id VARCHAR(64) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
venue_id VARCHAR(64) NOT NULL,
on_sale_at TIMESTAMPTZ NOT NULL,
status VARCHAR(32) NOT NULL
);
CREATE TABLE seats (
event_id VARCHAR(64) NOT NULL,
seat_id VARCHAR(64) NOT NULL,
section VARCHAR(32) NOT NULL,
row_num VARCHAR(16) NOT NULL,
seat_num VARCHAR(16) NOT NULL,
price_cents INT NOT NULL,
status VARCHAR(32) NOT NULL DEFAULT 'AVAILABLE', -- AVAILABLE, HELD, PAYMENT_PENDING, SOLD
version INT NOT NULL DEFAULT 1,
hold_id VARCHAR(64),
PRIMARY KEY (event_id, seat_id)
);
CREATE TABLE holds (
hold_id VARCHAR(64) PRIMARY KEY,
event_id VARCHAR(64) NOT NULL,
user_id VARCHAR(64) NOT NULL,
expires_at TIMESTAMPTZ NOT NULL,
status VARCHAR(32) NOT NULL, -- ACTIVE, EXPIRED, CONVERTED, RELEASED
idempotency_key VARCHAR(128) UNIQUE NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TABLE seat_ledger (
ledger_id BIGSERIAL PRIMARY KEY,
event_id VARCHAR(64) NOT NULL,
seat_id VARCHAR(64) NOT NULL,
hold_id VARCHAR(64),
order_id VARCHAR(64),
previous_status VARCHAR(32) NOT NULL,
new_status VARCHAR(32) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
5. Concurrency Control & Hold Execution Flow
Atomic Hold Allocation
To prevent race conditions without relying on external lock managers, reservations utilize atomic single-statement SQL updates evaluated within a single transaction:
UPDATE seats
SET status = 'HELD',
hold_id = $1,
version = version + 1
WHERE event_id = $2
AND seat_id = ANY($3)
AND (
status = 'AVAILABLE'
OR (status = 'HELD' AND hold_id IN (
SELECT hold_id FROM holds WHERE expires_at < NOW() AND status = 'ACTIVE'
))
);
Why This Prevents Double-Booking
- Row-Level Mutual Exclusion: PostgreSQL obtains exclusive write locks (
FOR UPDATE) on the matching rows for the targetedseat_ids in key-order sequence to prevent deadlocks. - Re-Evaluation of
WHEREClause: When concurrent transactions target the same seat, only the first transaction changes the status to'HELD'. The second transaction evaluates theWHEREcondition against the modified row and updates 0 rows. - All-or-Nothing Checking: The application checks the count of affected rows. If
affected_rows < requested_seat_count, the transaction callsROLLBACKand returns an error response (409 Conflict).
Client 1 ───┐ PostgreSQL (Row Lock)
├── (Select Seat A1) ──> [ Lock A1 ] ──> Status: AVAILABLE ──> Success (HELD)
Client 2 ───┘ │
└──> Blocked until Client 1 commits
└──> Re-evaluates status: HELD ──> 0 Rows Updated ──> Rollback (409)
6. Payment Processing & Expiration Mechanics
State Machine Lifecycle
[ AVAILABLE ] ──(Hold Request)──> [ HELD ] ──(Initiate Checkout)──> [ PAYMENT_PENDING ] ──(Webhook Success)──> [ SOLD ]
▲ │ │
│ ├──(TTL Expired) ├──(Payment Failure/Timeout)
└──────────────────────────────┴────────────────────────────────────┘
Preventing Payment Expiration Race Conditions
A critical edge case occurs when a payment succeeds right as the 10-minute hold window expires:
- Checkout Transition: When a user initiates payment, the seats transition from
HELDtoPAYMENT_PENDING. The hold expiration is frozen or extended by an extra grace period (e.g., +5 minutes). - Two-Phase Authorization:
- Phase 1 (Authorization): Reserve funds on the user's card via payment provider.
- Phase 2 (Database State Settlement): Execute a final DB commit setting
seats.status = 'SOLD'. If state update fails (e.g., hard timeout prior to authorization), initiate an automatic payment reversal/refund. - Phase 3 (Capture): Capture the authorized payment after DB transaction confirmation.
Expired Hold Cleanup
Instead of executing heavy scanning queries against the primary database, hold expirations are handled by two complementary approaches:
- Lazy Expiration (Inline Query Check): As seen in the reservation
UPDATEstatement, any seat markedHELDwhose correspondingholds.expires_at < NOW()is treated asAVAILABLEduring write attempts. - Active Asynchronous Sweeper: An external scheduler (e.g., Temporal workflow or scheduled AWS ECS task) processes expired holds from a queue sorted by expiration timestamp. It releases stale seats back to
AVAILABLEand emits cache invalidation events to Kafka to keep read caches up-to-date.
7. Operational Trade-Offs & Edge Cases
| Challenge | Strategy / Mitigation |
|---|---|
| Distributed Locks vs. DB Atomicity | Redis locks can fail during network partitions or GC pauses. Database row-level locks are used as the true source of truth, with Redis used only upstream in the Virtual Waiting Room for traffic shaping. |
| Distributed Multi-Seat Deadlocks | Always order the array of requested seat_id values lexicographically (e.g., ['A1', 'A2', 'A3']) before issuing transactional UPDATE statements to ensure identical lock acquisition sequence across threads. |
| Idempotency | Clients generate a unique UUID Idempotency-Key header for hold and payment requests. Keys are stored in the database to prevent duplicate charges or double holds on network retries. |