Full answer
Requirements
Functional:
- Browse shows by city, see a seat map with live availability.
- Select seats, hold them while paying, confirm the booking and get a ticket.
- Holds that are not paid in time are released automatically.
Non-functional:
- A seat is never sold to two people (strong consistency for seat status).
- The seat map can be a few seconds stale; booking itself cannot.
- Handle bursts when popular shows open (10 times the normal rate).
Capacity estimates
Assumptions: 10M bookings per day, peak factor 10 at big releases, about 4 seats per booking, 20 seat-map views per booking.
- Bookings: 10M / 86,400 = about 116 per second on average, about 1,160 per second at peak.
- Seat-map reads: 20 x 1,160 = about 23,000 per second at peak; serve them from a cache.
- Seat rows: a hall of 300 seats with 5 shows per day across 10,000 screens is 15M seat rows per day, which a sharded relational database handles easily.
API
GET /v1/shows/{show_id}/seats -> [{"seat_id": "F12", "status": "AVAILABLE"}, ...]
POST /v1/holds {"show_id", "seat_ids": ["F12", "F13"]} -> 201 {"hold_id", "expires_at"} or 409
POST /v1/bookings {"hold_id", "payment_token"} (Idempotency-Key header) -> 201 {"booking_id"}
DELETE /v1/holds/{hold_id}
Data model
CREATE TABLE show_seats (
show_id BIGINT,
seat_id VARCHAR(8),
status VARCHAR(10), -- AVAILABLE, HELD, BOOKED
hold_id UUID NULL,
held_until TIMESTAMP NULL,
booking_id UUID NULL,
PRIMARY KEY (show_id, seat_id)
);bookings: booking_id, user_id, show_id, seats, amount, payment_id, created_at. Shard by show_id so all seats of a show live together.
High-level design
flowchart LR
U[User] --> API[Booking API]
API --> C[(Seat map cache)]
API --> DB[(Shows and seats DB)]
API --> PAY[Payment gateway]
SW[Hold expiry worker] --> DB
DB -- "change events" --> CHolding seats safely
A hold is one atomic statement:
UPDATE show_seats
SET status = 'HELD', hold_id = :hold, held_until = now() + interval '8 minutes'
WHERE show_id = :show AND seat_id IN ('F12', 'F13')
AND (status = 'AVAILABLE' OR (status = 'HELD' AND held_until < now()));If the number of updated rows is less than the number of requested seats, roll back and return 409. Because the check and the update happen in one statement inside a transaction, two users can never hold the same seat. Expired holds are treated as available, so a crashed client cannot lock seats forever; a background worker also clears them for a clean seat map.
Confirming the booking checks the hold is still valid, charges the payment with an idempotency key, and sets status to BOOKED in one transaction.
An alternative is a Redis key per seat (SET seat:show:F12 hold NX EX 480), which is fast but must still be reconciled with the database before final confirmation.
Bottlenecks and trade-offs
- Hot shows. All seats of one show are on one shard, which becomes hot when tickets open. A virtual waiting room in front of the booking API admits users at a steady rate.
- Hold length. Longer holds are kinder to slow payers but leave seats unavailable; 5 to 10 minutes is common.
- Payment succeeds after the hold expired. Detect it at confirmation and refund automatically, or extend holds while a payment is in progress.
- Seat-map cache may show a seat as free that was just held; the hold call is the source of truth and returns 409 with a fresh map.
By level
Fresher: Describe the flow from seat map to hold to payment, and the seat table with a status column. A fresher should explain why the hold must expire.
Mid: Write the atomic hold, explain the race it prevents, size the peak and add a cache for the seat map. Cover idempotent confirmation.
Senior: Address hot shards, waiting rooms, bot defence, late payment refunds and Redis versus database holds. Expect clear reasoning about which data must be strongly consistent.
Key points
- One row per seat per show with a status
- Hold seats with an atomic conditional update and an expiry time
- Expired holds count as available
- Confirm payment and booking with an idempotency key
- Shard by show and use a waiting room for hot shows
Common mistakes
- Checking availability in one query and updating in another without a transaction
- Holds with no expiry
- Trusting the cached seat map for the final decision
- Ignoring the case where payment succeeds after the hold expired
Follow-ups
- How would you add a virtual waiting room?
- How do you handle general admission tickets without seat numbers?
- How would you prevent bots from holding all seats?
Tips
- Write the conditional update; it is the heart of the design
- Say what happens when a hold expires
- Separate the cached seat map from the source of truth
Evaluation rubric
- Correct seat-level data model
- Atomic hold with expiry
- Idempotent confirmation with payment
- Handles hot shows and late payments