Design Ticketmaster
hard 55 minSell numbered seats to far more people than there are seats.
API and data
The contract first, then the data that serves it.
Entities
Name the things first
Venue, Event, Seat (one row for each seat of each event), Order, Ticket and Place in line. Every write carries an idempotency key, and lists use cursors. Versions go in a header here; a path is fine too, see API versioning.
API
Endpoints
HTTP
GET /v1/events?q=jazz&lat=48.1&lng=11.6&radius_km=50 &date_from=2027-05-01&category=concert&limit=20&cursor=...-> 200 { "events": [ { "id": "e1", "name": "River Jazz", "venue": "Lake Hall", "min_price": 49, "level": "few left" } ], "next_cursor": "..." }GET /v1/events/e1?include=venue_map,pricesGET /v1/events/e1/availability counts by sectionGET /v1/events/e1/availability?section=A-> 200 { "section": "A", "free": 45, "of": 200, "seats": "a compact string, one mark per seat", "as_of": "2027-04-01T10:30:00Z" }HTTP
POST /v1/events/e1/line join once, when signed in-> 201 { "token": "signed", "place": 12345, "wait_min": 8 }GET /queue/e1.json public, cached at the edge-> 200 { "now_serving": 8000, "status": "open" }POST /v1/events/e1/pass { "token": "signed" }-> 201 { "pass": "signed", "expires_in": 900 }POST /v1/events/e1/holdsIdempotency-Key: 5f0c...{ "seat_ids": ["A-1-5", "A-1-6"] }-> 201 { "hold_id": "h1", "expires_at": "...10:40:00Z", "seats": [ {"id": "A-1-5", "price": 15000, "fees": 2500}, {"id": "A-1-6", "price": 15000, "fees": 2500} ], "total": 35000, "currency": "USD" }-> 409 { "taken": ["A-1-6"], "near_pairs": [["A-2-5","A-2-6"]] }GET /v1/holds/h1 DELETE /v1/holds/h1POST /v1/checkoutIdempotency-Key: 91ab...{ "hold_id": "h1", "payment_token": "from the provider's form" }-> 200 { "order_id": "o9", "status": "confirmed", "tickets": [...] }-> 202 { "order_id": "o9", "status": "pending" } bank is askingGET /v1/orders/o9POST /v1/orders/o9/transfer { "ticket_ids": [...], "to": "u_2" }Design choices
| Choice | Why |
|---|---|
| All seats or none | People want to sit together; a half hold surprises them |
| The server sets the hold time | A client could ask for hours |
| Price is fixed by the hold | What was shown is what is charged |
| Amounts in cents | Fractions do not add up |
| 409 with near pairs | The next click has a better chance |
| End time in the answer | The page counts down without asking |
| 202 for bank prompts | The result comes later, by polling or a message |
Where do retries go wrong?
Interviewer
The network drops after I press buy.
You
The client repeats with the same random key.
- The key is a unique column of the order, so it lives as long as the order, not a day in a cache.
- Same key and a different body is an error.
- The provider call uses the order id as its key. Stripe keeps keys for at least 24 hours, which is why our own record must outlive it.
Interviewer
Two clicks in the same moment?
You
Both try to insert the order. One wins; the other reads the existing row and gets its state.
Database
Data model
The records
SQL
BEGIN;SELECT seat_id FROM seats WHERE event_id = 'e1' AND seat_id IN ('A-1-5', 'A-1-6') AND (status = 'available' OR (status = 'held' AND held_until <= now())) ORDER BY seat_id FOR UPDATE;-- expect 2 rows, else ROLLBACK and answer 409UPDATE seats SET status = 'held', hold_id = 'h1', held_by = 'u1', held_until = now() + interval '10 minutes' WHERE event_id = 'e1' AND seat_id IN ('A-1-5', 'A-1-6');COMMIT;SQL
CREATE UNIQUE INDEX one_ticket_per_seat ON tickets (event_id, seat_id) WHERE status IN ('active', 'used');CREATE INDEX free_seats ON seats (event_id, section) WHERE status = 'available';CREATE INDEX seat_price ON seats (event_id, price) WHERE status = 'available';CREATE INDEX old_holds ON seats (held_until) WHERE status = 'held';CREATE INDEX my_orders ON orders (user_id, created_at DESC);CREATE INDEX event_sales ON orders (event_id, created_at);CREATE INDEX to_match ON orders (provider_ref);CREATE INDEX events_day ON events (starts_at) WHERE status = 'active';CREATE INDEX venues_near ON venues USING GIST (location);Why each store
| Data | Store | Why |
|---|---|---|
| Events, venues, accounts | PostgreSQL | Relations, easy to cache |
| Seats, orders, tickets | PostgreSQL, sharded by event | One local transaction |
| Places in line, sessions, limits | Redis | Fast, may be rebuilt |
| Search | Elasticsearch or OpenSearch | Words, places, facets |
| Maps, pictures, ticket files | Object storage and CDN | Large and static |
| Messages | Kafka | Several readers, replay |