Tickets for a cricket final or a superstar's first-day show sell out in minutes, with millions tapping at the same second. “Design BookMyShow” or “design Ticketmaster” is a frequently reported question at Amazon, Microsoft and Indian product companies. Everything comes down to one rule: never sell the same seat twice, even when two people tap it in the same millisecond.
Step 1 · Requirements
- Functional: browse movies/events by city; see showtimes and a live seat map; select seats; pay; get a ticket; cancel within rules.
- Non-functional: no double booking, ever; fast browsing; survive huge spikes at sale start; fair to users; payments safe against retries.
- Out of scope (say it): recommendations, reviews, food add-ons, dynamic pricing details.
Step 2 · Estimates
- Normal days: 10 million bookings a month ≈ 4 bookings/s average, but 100× more people browsing than booking.
- Flash sale: 5 million users arrive in the first minutes for 50,000 seats. The real problem is the spike, not the average.
- Data: seats are small: 10,000 screens × 5 shows × 300 seats = 15 million seat-show rows a day. Fine for a sharded relational database.
Step 3 · API
GET /cities/{id}/shows?date=… → movies, theatres, showtimes (cached)
GET /shows/{id}/seats → seat map with free/held/booked (short cache)
POST /shows/{id}/holds { seats: ["F7","F8"] } → { holdId, expiresAt } or 409 seats taken
POST /orders { holdId, idempotencyKey } → { paymentUrl }
POST /payments/webhook (from the payment gateway) → seats held → booked, ticket issuedStep 4 · Design
The heart of it: holding a seat atomically
🎮 Two fans, one seat
Run the race with seat holds off, then on. The fix is one condition, AND status = 'free', checked and changed in a single atomic step. Then try both endings: paying, and walking away until the hold expires.
-- Hold seats F7 and F8 for 10 minutes, all or nothing
BEGIN;
UPDATE show_seats
SET status = 'held', hold_id = :hold, hold_until = now() + interval '10 minutes'
WHERE show_id = :show AND seat IN ('F7','F8')
AND (status = 'free' OR (status = 'held' AND hold_until < now())); -- expired holds count as free
-- If fewer than 2 rows changed, someone got there first:
ROLLBACK; -- and tell the user "seats just taken"
-- Otherwise:
COMMIT;| Approach | How | Good | Watch out |
|---|---|---|---|
| Conditional update (optimistic) | UPDATE … WHERE status = 'free'; check rows changed | Simple, no long locks, scales well | Losers must retry with other seats |
| Row lock (pessimistic) | SELECT … FOR UPDATE inside a transaction | Easy to reason about | Locks held during slow steps hurt under load |
| Distributed lock (e.g. Redis with expiry) | Lock key per show-seat with a TTL | Fast for huge spikes | The database must still be the final source of truth |
Step 5 · Scale and reliability
- Consistency where it matters: the hold and booking hit the primary database; browsing reads replicas and caches. Seat maps may lag a second; the hold step re-checks.
- Shard by show: all seats for one show live on one shard, so a multi-seat hold is a single-shard transaction.
- Virtual waiting room: at sale start, queue users and admit a steady number per second; show their position. Combine with rate limiting and bot detection.
- Hold expiry: store
hold_until; treat expired holds as free in queries, and run a cleanup job to tidy them. - Payments: idempotency keys on orders; confirm via the gateway's webhook; if payment lands after the hold expired and the seat was resold, refund automatically.
- Tickets: after booking, send the ticket through the notification system (email, SMS, push).
🧠 PATH memory card
Remember the ticket booking design for good
Picture it · Anchor it · Trace it · Hit-recall it. Four quick steps that turn “I read it once” into “I can explain it in an exam”.
- P
Picture it
Your brain remembers scenes far better than definitions.
← swipe to see the whole picture →
The canteen has one samosa left and two students reach for it. The counter rule: the first hand on the plate holds it, and the other student is told it's gone. The holder has a few minutes to pay. If they pay, it's theirs. If they wander off, the samosa goes back on the counter for the next person.
- A
Anchor it
A silly sentence you can't forget, where every word maps to the concept.
“Hold, Pay, Confirm, or Release”
- Hold→Atomic conditional update: free → held, with hold_until
- One hand on the plate→Only one update succeeds; the other gets 0 rows (409)
- Pay→Order with an idempotency key; gateway webhook confirms
- Confirm→held → booked, ticket sent
- Release→Hold expires; seat is free again
- T
Trace it
Run it by hand on a tiny example once. Doing beats reading.
10:00:00.000 Riya and Arjun both request F7. Riya's UPDATE … WHERE status='free' changes 1 row → hold until 10:10. Arjun's changes 0 rows → 409 “taken”. Riya creates order with keyord-77, pays by UPI; the gateway webhook arrives (twice, a retry) → first one marks F7 booked, the second seesord-77done and does nothing. Ticket emailed. - H
Hit-recall it
Test yourself now, then again on the day each card comes back.
Card 1 / 8 · new0 mastered · 0 practisedSay the answer out loud first, then flip and be honest.
Follow-up questions interviewers ask
- “Show the seat map live?” Push seat changes over WebSockets for the busiest shows, or refresh every few seconds; the hold step is still the real check.
- “Payment succeeded but our server crashed?” The gateway's webhook retries; reconciliation jobs compare gateway records with orders and fix mismatches.
- “Group bookings that must sit together?” Hold all seats in one transaction; if any is taken, roll back and suggest the nearest block of free seats.
You've finished the course 🎉
That's thirteen parts: the READS framework, then twelve famous questions, from a URL shortener to a ticket system that survives a cricket final. Notice how the same blocks kept returning: caches, queues, consistent hashing, idempotency, atomic updates. That's the real skill interviewers test. Go back to the course page to review with the flashcards, or sharpen the algorithms underneath in the DSA course.
Key takeaways
- ✓Browsing is cache-friendly; booking must be strongly consistent.
- ✓Hold seats with an atomic conditional update (or row lock), with an expiry time.
- ✓Pay with an idempotency key and confirm via the gateway's webhook.
- ✓Shard seats by show so multi-seat holds are single-shard transactions.
- ✓Protect flash sales with a virtual waiting room, rate limits and bot checks.
Frequently asked questions
How does BookMyShow prevent double booking?
When you pick a seat, the system places a temporary hold on it in a single atomic database operation that only succeeds if the seat is still free (for example, an UPDATE with WHERE status = 'free', or a row lock inside a transaction). If two people try at once, only one update changes the row; the other gets zero rows and is asked to choose another seat. The hold expires after a few minutes if payment doesn't complete.
Why are seats held for a few minutes during booking?
Payment takes time: entering card details, OTPs, UPI approval. Holding the seat for a short window (often around 10 minutes) guarantees it's still yours when payment succeeds, while making sure abandoned bookings release the seat automatically so it can be sold to someone else.
What is a virtual waiting room?
During huge sales (a cricket final, a big concert), far more people arrive than the booking system can serve. A virtual waiting room lets everyone into a queue and admits users to the booking pages a few thousand at a time, so the core system stays fast and fair instead of crashing under millions of simultaneous requests.
Should a ticket booking system choose consistency or availability?
For the booking step, consistency: it is better to show an error or ask a user to wait than to sell the same seat twice. Less critical parts, like browsing movies, showtimes and approximate seat maps, can favour availability and be served from caches and replicas, as long as the final hold and payment step checks the source of truth.
How are payments made safe in a booking system?
The booking creates an order with a unique idempotency key before redirecting to the payment gateway, so retries never charge twice. The gateway confirms the payment through a callback (webhook); only then is the seat changed from held to booked. If payment succeeds after the hold expired and the seat was resold, the system refunds automatically.
🧠 Quick check: ticket booking
1. Two users tap seat F7 at the same moment. What makes sure only one gets it?
2. A user holds two seats and closes the app. What should happen?
3. 5 million fans arrive at 10:00 for a 50,000-seat final. Best protection for the booking service?
4. For the final seat booking step, which matters more?
Checking your access…