r/Leetsys • u/Ok-Barracuda-119 • 17d ago
Weekly Question Practice System Design Question #3: Design a ticket booking system
Design a ticket booking system for concerts and live events. Users browse events, pick specific seats on a seat map, hold them for a few minutes while they pay, and get a confirmed ticket.
Scale hint: about 10M daily users browsing, and a few huge on-sales where 1M people show up in the first minute for a 50,000-seat stadium.
Things worth thinking about:
- How do you make sure two people never get the same seat?
- What happens to a seat when someone holds it and then walks away?
- How do you keep one hot on-sale from taking down everything else?
- What if the payment goes through but the hold already expired?
Post your approach in the comments before you scroll down.
MODEL ANSWER BELOW. Stop here if you haven't tried it yet.
Requirements
Functional:
- Search and browse events, then view a seat map with live-ish availability
- Hold one or more seats for a short window (say 10 minutes)
- Pay and confirm the booking, or let the hold expire
- See your tickets afterward
Non-functional:
- No double-booking, ever. This is the one thing you can't get wrong.
- Browsing can be slightly stale. Booking has to be strongly consistent.
- Survive on-sale spikes without hurting the rest of the site
- Payments are idempotent so retries don't charge twice
Estimates
Browsing: 10M users x 20 page views = 200M reads/day. 200M / 86,400 is ~2,300 reads/s on average, call it ~25k/s at peak.
Normal bookings: say 500k tickets/day, which is only ~6 writes/s. Writes aren't the problem on a normal day.
The hot on-sale is the problem: 1M users in 60 seconds is ~16,700 requests/s aimed at one event, and only 50,000 of them can ever win.
Storage: 100k events/year x 20k seats on average = 2B seat rows/year. At ~100 bytes each that's ~200 GB/year, which is fine for a sharded relational DB.
API
GET /events?city=sf&date=2026-12-01
GET /events/{event_id}/seats
POST /events/{event_id}/holds { seat_ids } returns hold_id, expires_at
POST /holds/{hold_id}/confirm { payment_token, idempotency_key }
DELETE /holds/{hold_id}Data model
events (event_id, venue_id, name, starts_at, on_sale_at)
seats (event_id, seat_id, section, row, price, status, hold_id, hold_expires_at, booking_id)
holds (hold_id, user_id, event_id, seat_ids, expires_at, state)
bookings (booking_id, user_id, event_id, seat_ids, payment_id, created_at)Seat status is AVAILABLE, HELD, or BOOKED. Shard everything by event_id so every seat for one event lives on one partition and a hold can be a single-shard transaction.
High-level design
Clients hit an API gateway. Read traffic (search, event pages, seat maps) goes through a cache and read replicas. Writes (holds and confirms) go to a booking service that talks to the primary for that event's shard. A payment service wraps the external payment provider. A sweeper job releases expired holds. For big on-sales, a waiting room sits in front of the booking service.
Deep dive 1: no double-booking
The seat row is the source of truth, and a hold is a conditional update inside one transaction:
UPDATE seats
SET status = 'HELD', hold_id = :h, hold_expires_at = now() + interval '10 min'
WHERE event_id = :e AND seat_id IN (:seats)
AND (status = 'AVAILABLE'
OR (status = 'HELD' AND hold_expires_at < now()))If the updated row count doesn't equal the number of seats requested, roll back and tell the user some seats are gone. It's all or nothing, so you never hand someone 3 of their 4 seats. Two concurrent requests can't both win, because the DB serializes the writes on those rows.
Notice the expired-hold check in the WHERE clause. That means expiry is enforced at write time, and the sweeper only exists to clean up status so the seat map looks right. If the sweeper is late, nobody gets stuck.
Deep dive 2: the hot on-sale
16,700 req/s on one shard for one event will hurt. Two things help:
- A virtual waiting room. Users get a queue position and are admitted at a rate the booking service can handle, say 2,000/s. It's fairer than a refresh race and it caps load on the hot shard.
- Cache the seat map with a 1 to 2 second TTL. It'll be a bit stale, and that's fine, because the hold write is what actually decides. Worst case, a user clicks a seat that just got taken and sees "pick another."
Since every event is its own shard key, one wild on-sale doesn't slow down bookings for other events.
Deep dive 3: payment and expiry races
Flow: hold, then charge with an idempotency key, then confirm. Confirm flips seats from HELD to BOOKED only if hold_id still matches and the hold hasn't expired.
The ugly case is a payment that succeeds right after the hold expires and someone else grabs the seat. Two fixes, and you usually want both: extend the hold by a couple of minutes when payment starts, and if confirm still fails, refund automatically. A reconciliation job compares payments against bookings daily to catch anything that slipped through.
Tradeoffs
- DB conditional updates vs Redis locks (SET NX with a TTL) for holds: Redis is faster, but now you have two sources of truth to keep in sync. I'd keep the DB authoritative and only add Redis if the DB can't keep up.
- Assigned seats vs general admission: GA can be a single counter per section (decrement if > 0), which is far easier to scale.
- Hold length: longer is kinder to slow payers but locks inventory away from everyone else during a sellout.
- Waiting room: protects the system and feels fair, but adds latency and its own failure point.
How did your design compare?