1. Functional requirements
- View an event.
- Search for events.
- Book tickets to an event.
Below the line: refunds and transfers, resale, dynamic pricing, virtual queues for presales, admin tooling.
Scale: 100M daily users, 100K events a day; an on-sale puts 1M users on one event at once. Writes are tiny. The design is driven by consistency on the seat and the on-sale burst.
2. Non-functional requirements
- Consistency for booking: no double booking
- Availability for viewing and search
- 1M users on one on-sale absorbed
- Search under 500 ms
3. Core entities
- Users
- Events
- Venues
- Performers
- Tickets: available → held → booked
- Bookings
4. API routes
Auth is a header on booking; view and search are public. Simple enough to start; the booking route splits in two in the first deep dive.
View
GET /events/:eventId
returns: event, venue, performer, tickets[] for the seat map
Search
GET /events/search
params: keyword, start, end, page, pageSize
returns: Event[]
Book
POST /bookings/:eventId Idempotency-Key header
body: ticketIds, paymentDetails
returns: bookingId
5. High-level design
The simplest system that satisfies the three routes. One client, one gateway, one service per route, one database. The deep dives change this picture.
Boxes, drawing order: client · gateway · event service, search service, booking service · Postgres · Stripe beside booking.
Data model:
Event id, performerId, venueId, name
Venue id, seatMap
Ticket id, eventId, seat, price, status, userId
Booking id, userId, tickets[]
Postgres, one primary: the ticket flip and the booking commit in one transaction, conditional updates on ticket status, unique on the idempotency key. 100K events a day is a trivial write load; the burst is reads and holds, which the deep dives move to Redis.
6. Deep dives
Order in the room: 6.1 must · 6.5 if time · 6.2, 6.3, 6.4 one line each, only if asked. Each deep dive opens with three spoken sentences: Problem, Pick, Cost. Everything under them is what you say when the interviewer digs.
6.1 No double booking: reserve, then confirm
Problem. Booking is one request, so nothing holds the seats while the user enters payment details; two users reach checkout for the same seat and one loses it there.
Pick. Two phases. Reserve takes one Redis lock per ticket, SET NX EX 600, so exactly one user holds a seat and an abandoned checkout releases itself; confirm flips the rows available → pending in Postgres with a conditional update before charging, then pending → booked.
Cost. A second store to keep consistent with the orders database; the conditional update is what makes the money safe, the TTL is only cleanup. Rejected: a held status in Postgres, because expiry would need a cleanup job.
Draw: the booking route splits into reserve and confirm; Redis beside the booking service for holds.
Routes (replace POST /bookings/:eventId from section 4):
POST /bookings/:eventId/reserve { "ticketIds": string[] } → reservation, expires in 10 min
POST /bookings/:eventId/confirm { "ticketIds": string[], "paymentDetails": … } → bookingId
Flow
- Reserve: the Booking Service acquires one lock per ticket in Redis,
{ticketId: userId}with a 10-minute TTL (SET NX EX 600). If any ticket is already locked, nothing is acquired and the client gets a 409. While the locks live, no other user can reserve or book those seats. - The client shows the countdown and collects payment details.
- Confirm: the Booking Service checks each lock still belongs to
userId, charges Stripe, then in one transaction setsTicket.status = bookedandTicket.userIdand creates the Booking. Then it releases the locks. - No confirm within 10 minutes: the keys expire on their own and the seats are reservable again.
Follow up: the lock expires right as the user submits payment. How do you avoid a successful charge with no seat?
Answer: Money never moves before the seat is secured in the database. On confirm, before calling Stripe, flip the tickets available → pending under this user with a conditional update; if it misses any row, return an error and charge nothing. Once it succeeds the database holds the seat, so the Redis TTL no longer matters. Charge with the booking id as the idempotency key, then flip pending → booked, or back to available if the charge fails. A crash between the charge and that last update is replayed by the Stripe webhook or a reconciliation worker. Worst case is a retry, never a refund.
6.2 Scaling reads: cache, CDN, replicas
Problem. Every event page view goes to the one database, and 10M concurrent users during an on-sale read the same few events. Pick. A Redis cache for event, venue and performer data with a one-hour TTL, seat availability as a Redis hash written by the booking service on every transition, a CDN for static assets, Postgres read replicas for the misses. Cost. Staleness on event data and a stampede on expiry, so one request refills a missed key while the rest wait on it.
6.3 Search: Elasticsearch fed by CDC
Problem. Search is a LIKE '%keyword%' scan on the table that also takes bookings, with no ranking and no typo tolerance.
Pick. Elasticsearch fed by change data capture from Postgres, with hot query pages cached in Redis for 60 s.
Cost. A second store that lags by seconds and must be rebuildable from Postgres; it is an index, never the source of truth.
6.4 Real-time seat map over SSE
Problem. The seat map is a snapshot, so during an on-sale users click seats already gone and get 409s until they refresh.
Pick. Server-sent events per section, driven by booking transitions published through Redis Pub/Sub, with the client flipping held seats back when their until passes.
Cost. Connection servers to run, about 100K idle connections each; a push outage degrades to a 10-second snapshot poll, never a stale map.
6.5 The on-sale burst: a virtual waiting room
Problem. Millions hit the event page and reserve in the same minute, and the booking path, one lock per seat, one primary, Stripe, has a fixed throughput. Pick. A waiting room at the gateway: a Redis sorted set per event, users admitted in join order at a rate set from seats remaining, a signed admission token checked at the gateway without a lookup. Cost. People wait, and fairness needs per-account keys, rate limits on joins and a randomized order for everyone who joined before the on-sale minute. Rejected: autoscaling the booking path, because the bottleneck is one primary and one lock per seat, not stateless compute.
Draw: a queue box in front of the gateway with a sorted set and an admission worker; the token check sits in the gateway.
Routes (add; while the room is on, GET /events/:eventId and both booking routes require X-Admission-Token):
POST /events/:eventId/queue → { position, etaSeconds }
GET /events/:eventId/queue → { position } | { admissionToken }
Flow
- The room is switched on per event before the on-sale:
waiting_room:{eventId} = on, cached at the gateway. Any event-page or booking request without a valid token is redirected to the waiting room. - Join:
ZADD queue:{eventId} NX <nowMs> <userId>, score = join time, one entry per user. Position =ZRANK, ETA = position ÷ admission rate. - Admit: a worker per event runs
ZPOPMIN queue:{eventId} Nevery second and writesadmitted:{eventId}:{userId}= a signed token (JWT: userId, eventId, exp 15 min), TTL 15 min. N is the knob: 500/s with thousands of seats left, tens with hundreds, 0 when sold out. - Poll:
GET /events/:eventId/queueevery 5 s returns the token onceadmitted:{eventId}:{userId}exists, otherwise the position. The gateway verifies the token’s signature, eventId, userId and expiry locally, no lookup; expired means rejoining at the back.
Follow up: bots join the queue ten thousand times. How do you keep it fair?
Answer: The queue is keyed by authenticated userId with NX, so an account gets one place however many tabs or retries it opens. The gateway rate-limits joins per account and per IP and challenges suspicious traffic before a join is accepted. The token is bound to the userId and verified on every request, so it cannot be sold and used by someone else. Randomize the order among everyone who joined before the on-sale minute, so hammering join at the exact second buys nothing. Per-account ticket limits catch what gets through, and the 6.1 lock TTL means a bot that holds seats without paying loses them in 10 minutes.
Final design
Trade-offs, the two to say:
- Redis lock with a TTL over a
heldstatus in Postgres: expiry is free; an abandoned checkout needs no cleanup job, and the row changes only when money moves. - Waiting room over autoscaling the booking path: the bottleneck is one primary and one lock per seat; queueing users is cheaper and fairer than queueing requests.
Study only, not for the room: full flows for 6.2, 6.3 and 6.4, and the 6.4 follow-up.
6.2 flow
- View event: the Event Service reads
event:{eventId}from Redis (event, venue and performer as one JSON, TTL 1 hour). On a miss it reads a replica and writes the key; one request refills a missed key while the rest wait on it. - Availability:
seats:{eventId}is a Redis hash,ticketId → available | held:<expiresAt> | booked, read with oneHGETALL. The Booking Service writesheldon reserve andbookedon confirm; a hold past itsexpiresAtreads as available. - Static assets (images, the venue seat-map SVG, JS and CSS) come from the CDN with versioned URLs and long cache headers.
- Writes go to the Postgres primary, replicas take cache misses; an admin edit deletes
event:{eventId}.
6.3 flow
- Index: Debezium tails the Postgres WAL and publishes event, venue and performer changes to Kafka; an indexer upserts one document per event into the
eventsindex. Lag is seconds, fine for search. - Query:
GET /events/search→ Search Service → Elasticsearch:multi_matchon the keyword withfuzziness: AUTO, arangefilter on date,fromandsizefor pagination →Event[]. - Hot queries: the Search Service caches each result page in Redis as
search:{hash(normalized query)}, TTL 60 s. The on-sale artist’s search is one key, served without touching Elasticsearch. - Elasticsearch is an index, not the source of truth: a result click reads the event through the 6.2 cache, and the index can be rebuilt from Postgres.
6.4 flow and follow-up
- The client renders the seat map from the 6.2 snapshot, then opens the stream for the section it is viewing. The Seat Map Service holds the connection open; a section is a few hundred seats, so each client only receives deltas it can see.
- The Booking Service publishes every transition right after writing the lock:
PUBLISH seats:{eventId}:{section} {ticketId, status: held, until: expiresAt}on reserve,status: bookedon confirm. - The Seat Map Service subscribes to Redis Pub/Sub for the channels its clients watch and writes each message to every open stream for that event and section.
- Expiry needs no event: a
helddelta carriesuntil, and the client flips the seat back to available when it passes unlessbookedarrived first. On reconnect the client re-fetches the section snapshot, then resumes the stream.
Follow up: 1M users are watching one event. How does one hold reach all of them?
Answer: Connections are the cheap part: an idle SSE connection costs a few KB, so one push server holds about 100K and 1M viewers is ten servers behind the load balancer. Each server subscribes once per channel its clients watch, so a hold is one PUBLISH that Redis fans out to ten servers, each writing it to its own connections. Section scoping divides the work again: a client in section 112 never receives the other sections’ deltas. If one Redis node cannot keep up, shard channels by event across nodes, or move the feed to a Kafka topic partitioned by event. If the stream drops, the client re-fetches the snapshot every 10 seconds, so a push outage degrades to polling instead of a stale map.