A ticket booking system like Ticketmaster or BookMyShow sells a fixed, tiny inventory (one seat can be sold exactly once) to a crowd that can be thousands of times larger than the supply, all arriving in the same minute. Most of the time it is a read-heavy catalog. At a hot on-sale it becomes one of the most contended write workloads on the internet. The design hinges on three ideas: temporary seat holds with a TTL, contention-safe inventory updates that make double booking impossible, and a virtual waiting room that turns a stampede into an orderly line.
Think of it like
A deli counter with take-a-number tickets
When the doors open for a limited batch of something, the shop does not let 5,000 people rush the counter. Everyone takes a number and waits outside; the clerk calls in as many as the counter can serve. At the counter, you put items in your basket and they are set aside for you for ten minutes. Pay in time and they are yours; wander off and they go back on the shelf for the next number.
1. Requirements
Functional
- Search and browse events by city, date, artist or venue
- View a seat map with live availability (reserved seating) or ticket counts (general admission)
- Select seats and hold them for a few minutes while paying
- Pay and receive tickets; cancel or let the hold expire
- Enforce per-customer purchase limits
- Queue users fairly when demand exceeds capacity
Non-functional
- No double booking, ever: strong consistency for seat inventory
- High availability for browsing; booking may queue but must not fall over
- Survive on-sale spikes 100× to 1,000× normal traffic
- Fairness: humans in order of arrival, not bots with the fastest scripts
- Holds and confirmations in well under a second for admitted users
| In scope | Out of scope |
|---|---|
| Event catalog and seat maps | Resale marketplace and ticket transfers |
| Holds, booking, payment within the hold | Dynamic pricing algorithms (mention only) |
| Waiting room and admission control | Venue management and access-control scanners |
| Bot mitigation and fairness at a high level | Payment processing internals (see Design a Payment System) |
2. Back-of-the-envelope estimation
Normal traffic is easy: a platform selling 1 million tickets a day averages about 12 tickets per second. The design is driven by the worst minute. Assume a stadium on-sale: 60,000 seats, 2 million fans arriving within 10 minutes, about 4 tickets per order. See Back-of-the-Envelope Estimation.
Fans at on-sale
2M
in 10 minutes
Seats
60,000
~15,000 orders
Unprotected load
~1M req/s
refresh storms
Admitted write rate
~100 holds/s
after the waiting room
3. API design
GET /v1/events?city=chicago&from=2026-12-01&q=coldplay
GET /v1/events/evt_42/seatmap (static layout from CDN, versioned per venue)
GET /v1/events/evt_42/availability?section=112
-> 200 { "section": "112", "available": ["A12", "A13", "B7"], "asOf": "2026-11-10T10:00:01Z" }
POST /v1/events/evt_42/holds
Authorization: Bearer <user token>
X-Admission-Token: <signed waiting-room token>
Idempotency-Key: 3f1c...
{ "seats": ["112-A12", "112-A13"] }
-> 201 { "holdId": "hold_9x", "expiresAt": "2026-11-10T10:10:01Z" }
-> 409 { "unavailable": ["112-A13"] } (nothing is held: all or nothing)POST /v1/holds/hold_9x/booking
Idempotency-Key: hold_9x
{ "paymentMethod": "pm_tok_7Q" }
-> 201 { "bookingId": "bk_51", "status": "confirmed", "tickets": ["tkt_..", "tkt_.."] }
-> 410 { "error": "hold_expired" }
DELETE /v1/holds/hold_9x -> 204 (user changed their mind: release now)
GET /v1/queue/evt_42/status -> 200 { "position": 48210, "etaSeconds": 960 }
-> 200 { "admitted": true, "admissionToken": "eyJ..." }- Holds are all or nothing. A family wants four seats together; holding three is worse than holding none.
- The hold id doubles as the booking's idempotency key, so a double-clicked Pay button or a retried request can produce at most one booking. See Idempotency & Delivery Guarantees.
- Availability responses carry
asOf: they come from a cache and may be a second old. The hold, not the map, is the authority.
4. Data model
CREATE TABLE events (
event_id BIGINT PRIMARY KEY,
venue_id BIGINT NOT NULL,
layout_ver INT NOT NULL, -- which seat map version this event uses
starts_at TIMESTAMPTZ NOT NULL,
on_sale_at TIMESTAMPTZ NOT NULL,
max_per_user INT NOT NULL DEFAULT 6
);
-- One row per sellable seat per event: the contended table.
CREATE TABLE event_seats (
event_id BIGINT NOT NULL,
seat_id TEXT NOT NULL, -- '112-A12'
price_cents INT NOT NULL,
status TEXT NOT NULL DEFAULT 'available', -- 'available' | 'held' | 'sold'
hold_id TEXT,
held_until TIMESTAMPTZ,
booking_id TEXT,
PRIMARY KEY (event_id, seat_id)
);
CREATE TABLE bookings (
booking_id TEXT PRIMARY KEY,
event_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
hold_id TEXT NOT NULL UNIQUE, -- at most one booking per hold
payment_id TEXT,
status TEXT NOT NULL, -- 'pending_payment' | 'confirmed' | 'canceled'
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Final guard: whatever the application does, a seat can appear on only one ticket.
CREATE TABLE tickets (
ticket_id TEXT PRIMARY KEY,
booking_id TEXT NOT NULL REFERENCES bookings(booking_id),
event_id BIGINT NOT NULL,
seat_id TEXT NOT NULL,
UNIQUE (event_id, seat_id)
);
-- General admission: a counter instead of rows.
CREATE TABLE ga_inventory (
event_id BIGINT NOT NULL,
section TEXT NOT NULL,
capacity INT NOT NULL,
held INT NOT NULL DEFAULT 0,
sold INT NOT NULL DEFAULT 0,
PRIMARY KEY (event_id, section),
CHECK (held >= 0 AND sold + held <= capacity)
);| Data | Store | Why |
|---|---|---|
| Seat inventory, holds, bookings, tickets | Relational DB (Postgres or MySQL), sharded by event_id | Row-level atomicity, conditional updates and unique constraints; one event's seats share a shard |
| Fast hold gate and availability bitmaps | Redis | Atomic multi-key scripts and TTLs at memory speed for hot events |
| Event search | Elasticsearch / OpenSearch | Full-text and geo queries; eventual consistency is fine (see Search Systems) |
| Seat map layouts, images, event pages | Object storage + CDN | Static and versioned; cache for days (see Content Delivery Networks) |
5. High-level architecture
The read path is served from the CDN, caches and a search index. The write path sits behind the waiting room: only admitted users with a valid token reach the booking service, which holds seats atomically, takes payment within the hold window, and confirms the sale in the database. A worker releases expired holds. Press play on a flow.
6. Deep dive: seat holds with a TTL
A hold is a lease on inventory: the seat is unavailable to others but not yet sold. It exists because payment takes minutes (form filling, 3-D Secure, bank latency) and selling a seat only after payment would let two people pay for the same seat.
Short holds (2 to 5 minutes)
- Inventory recycles quickly; fewer seats locked by abandoned carts
- More users fail payment in time (3-D Secure, slow typists)
- Better for very hot on-sales
Long holds (10 to 15 minutes)
- Friendlier checkout and fewer expired-hold failures
- Bots can hold large blocks of seats and resell or squat on them
- Seats look sold out, then reappear, which feels unfair
- Expire on two clocks: Redis TTLs release the fast gate automatically; the database
held_untilcolumn is checked by every confirm and swept by the expiry worker. Neither depends on the client coming back. - Extend once, with a cap: when payment starts (or a 3-D Secure challenge begins), extend the hold by a few minutes, never indefinitely.
- Count holds against purchase limits, so one account cannot hold 40 seats across several tabs.
- Release explicitly when the user leaves checkout, rather than making everyone wait for the TTL.
7. Deep dive: preventing double booking under contention
Thousands of requests may target the same front-row seats in the same second. Three techniques make the "check if free, then take it" step atomic. They can be combined: a fast atomic gate in Redis plus a database that independently refuses to sell a seat twice.
Pessimistic row locks
SELECT ... FOR UPDATEthe seat rows (in a fixed order to avoid deadlocks), check, update, commitNOWAITorSKIP LOCKEDmakes losers fail fast instead of queueing- Simple to reason about; locks are held for the whole transaction
- Under heavy contention, lock waits and connection pools become the bottleneck
Optimistic conditional updates
UPDATE ... WHERE status = 'available'(orversion = n) and check the row count- No explicit locks held across round trips; the database serializes the single statement
- Losers learn instantly that a seat was taken
- Best default for seat holds
Atomic Redis operations
- A Lua script checks and sets several seat keys with a TTL in one atomic step
- Tens of thousands of operations per second per shard, in memory
- Not the system of record: a failover can lose recent writes
- Use as a gate in front of the database, not instead of it
BEGIN;
UPDATE event_seats
SET status = 'held',
hold_id = 'hold_9x',
held_until = now() + interval '10 minutes'
WHERE event_id = 42
AND seat_id IN ('112-A12', '112-A13')
AND (status = 'available' OR (status = 'held' AND held_until < now()));
-- Application: if the row count is 2, COMMIT. If it is less, ROLLBACK:
-- another buyer won at least one seat, and the user holds nothing.
COMMIT;General admission is a counter, not rows
For a standing-room section with 5,000 identical spots there is nothing to choose, so model it as a counter: UPDATE ga_inventory SET held = held + 4 WHERE event_id = 42 AND section = 'floor' AND sold + held + 4 <= capacity. One row is a single hot spot, so for very large sections split the capacity into several sub-counters (buckets) and pick one at random, or keep the counter in Redis with an atomic decrement and reconcile to the database.
8. Deep dive: the virtual waiting room
Scaling the booking path to 1M requests per second for 15,000 orders would be enormously expensive and still unfair: whoever's script retries fastest wins. A waiting room instead admits users at the rate the backend and the inventory can absorb. It is Rate Limiting applied to people rather than requests.
| Design choice | Option | Trade-off |
|---|---|---|
| Ordering | Random for early arrivals, FIFO afterwards | Removes the incentive to hammer the site before the start; strict FIFO from the first second rewards bots |
| Admission rate | Fixed, or driven by backend health and inventory | Adaptive rates keep the backend safe but make wait estimates less precise |
| Token | Signed (HMAC or JWT) with account, event, expiry | Stateless verification at every booking server; revocation needs a short expiry |
| Build or buy | Own service vs Queue-it or Cloudflare Waiting Room | Products are proven at scale; building gives deeper integration with verified-fan and limits |
9. Deep dive: payment within the hold window
- 1
Authorize, do not capture
Authorize the card using the hold id as the idempotency key. If anything fails afterwards, a void releases the customer's funds without a refund cycle. See Design a Payment System.
- 2
Confirm the seats atomically
In one transaction: seats
held → soldonly wherehold_idmatches andheld_until > now(), booking confirmed, tickets inserted. If the row count is short, the hold expired: void the authorization. - 3
Capture
Capture after the commit. If capture fails (rare), retry it with the same key; a reconciliation job catches anything left in between. This is a small Distributed Transactions problem solved with ordering and idempotency rather than two-phase commit.
- 4
Notify asynchronously
Ticket emails, wallet passes and analytics consume a booking-confirmed event from a queue, so they never slow down the hot path. See Message Queues & Pub/Sub.
10. Bots and fairness
- Pre-registration and verified fans: invite likely humans (with purchase history) to a presale with access codes, which caps demand before the on-sale and filters bulk accounts. Ticketmaster's Verified Fan is one example.
- Per-account, per-card and per-address limits, enforced at hold time and again at confirmation.
- Challenge at the queue entrance, not at checkout: CAPTCHAs or proof-of-work when joining, plus device and behavior signals.
- Bind everything to the account: queue entries, admission tokens and holds. Shared or replayed tokens fail verification.
- Rate limit by account, IP range and device on every booking endpoint. See Rate Limiting.
- Law helps a little: the US BOTS Act of 2016 makes it unlawful to circumvent ticket sellers' purchase limits and security measures, but enforcement was rare for years (the FTC began pursuing cases more actively in 2025), so technical controls still matter most.
11. Scaling, bottlenecks and failure handling
- Shard by
event_id: all of one event's seats, holds and bookings live on one shard, so a hold is a single-shard transaction. A hot event cannot be split this way, which is exactly why the waiting room caps its write rate. See Sharding & Partitioning. - Pre-warm for known on-sales: on-sale times are scheduled, so scale the booking fleet, warm caches and pre-load seat bitmaps beforehand instead of relying on reactive autoscaling.
- Read path isolation: catalog and search run on separate infrastructure from booking, so a meltdown in one does not take down the other. See Resilience Patterns.
- Redis hash tags: keys like
seat:{evt42}:112-A12put one event's seats in one Redis Cluster slot so a multi-seat Lua script is allowed; that slot is a single-threaded hotspot, which again is fine only behind admission control. - Degrade gracefully: under extreme load, switch the seat map to section-level availability and best-available assignment.
| Failure | Risk | Handling |
|---|---|---|
| Redis failover loses recent holds | Two users think they hold the same seat | The database conditional update and ticket uniqueness decide; one user gets a clear conflict |
| Booking service crashes after a hold | Seats stuck as held | TTL and the expiry sweep release them automatically |
| Payment authorized, commit fails | Customer charged with no ticket | Void the authorization; reconciliation catches stragglers |
| Queue service down | Stampede on booking | Fail closed: pause admissions and show a status page rather than open the gates |
| Database shard for the hot event slow | Holds time out | Admission controller lowers the rate automatically from health feedback |
| Stale availability shown | Users click seats already taken | Expected; hold returns 409 with alternatives, and the bitmap refreshes within a second |
Implementation
A Lua script checks every requested seat key and sets them all with a TTL only if all are free. Keys share a hash tag so they live in one cluster slot.
import redis
HOLD = """
for _, key in ipairs(KEYS) do
if redis.call('EXISTS', key) == 1 then return {0, key} end
end
for _, key in ipairs(KEYS) do
redis.call('SET', key, ARGV[1], 'PX', ARGV[2])
end
return {1}
"""
r = redis.Redis.from_url("redis://localhost:6379", decode_responses=True)
hold_script = r.register_script(HOLD)
def seat_key(event_id: str, seat_id: str) -> str:
return f"seat:{{{event_id}}}:{seat_id}" # braces form the cluster hash tag
def hold_seats(event_id: str, seat_ids: list[str], hold_id: str, ttl_ms: int = 600_000):
keys = [seat_key(event_id, s) for s in sorted(seat_ids)]
result = hold_script(keys=keys, args=[hold_id, ttl_ms])
if result[0] == 1:
return True, None
return False, result[1] # the first seat that was already takenKey takeaways
- Separate the cached, eventually consistent browsing path from the strongly consistent booking path.
- Holds with a TTL lease seats during payment; expire them on two clocks (Redis TTL and a database sweep) so abandoned carts always return inventory.
- Make "check and take" atomic: conditional updates (or row locks) in the database, optionally behind an atomic Redis gate, with a unique constraint as the last line of defense.
- A virtual waiting room admits users at the rate the backend and inventory can absorb; randomizing early arrivals removes the reward for hammering the site.
- Authorize, commit the seats, then capture: a failed commit only needs a void.
- Best-available assignment and section-level views turn contention on popular seats into server-controlled allocation.
Common pitfalls
- Reading availability and then writing the hold in two separate steps without a condition, which double books under concurrency.
- Trusting Redis as the system of record for sold seats, then losing sales on failover.
- Holding partial seat sets (two of four) instead of all or nothing.
- Trying to scale the booking path to raw on-sale traffic instead of admitting users at a controlled rate.
- Capturing payment before the seats are confirmed, forcing refunds when the hold turns out to have expired.
Interview tips
- Do the on-sale math: millions of fans, tens of thousands of seats. It justifies the waiting room and tells you writes are modest once admission is controlled.
- Write the conditional
UPDATE ... WHERE status = 'available'and walk through two concurrent requests to show why only one wins. - Compare row locks, optimistic updates and Redis atomic scripts, then choose a combination and defend it.
- Mention fairness and bots unprompted; interviewers know this is where real systems struggle.
Real-world applications
- Ticketmaster's 2022 Taylor Swift Eras Tour presale drew demand far beyond expectations, causing widespread failures, a canceled general sale and a US Senate hearing in 2023. It is the canonical example of why admission control and bot defenses matter.
- Ticketmaster Verified Fan pre-registers buyers and distributes access codes to limit demand and filter bots before an on-sale.
- Queue-it and Cloudflare Waiting Room sell virtual waiting rooms used by ticketing, retail drops and government sites.
- BookMyShow and cinema chains use interactive seat maps with short time-limited holds while the customer pays.
- Airlines and hotels use the same hold-then-confirm pattern for inventory, but often overbook deliberately, a policy choice ticketing usually cannot make.
Test yourself
Two requests try to hold seat A12 at the same moment using UPDATE event_seats SET status = 'held' ... WHERE seat_id = 'A12' AND status = 'available'. What happens?
Related topics
Finished this lesson? Track it to see your progress on the roadmap.