Movie Ticket Booking

Theater Seat Reservation System

Design a movie ticket booking system that holds seats for a few minutes while the user pays, never sells a seat twice, releases abandoned holds, and refunds cancellations by policy.

Overview

A booking system shows the seat map for a show, lets a user pick seats, holds them while the user pays, and turns the hold into a booking when the payment goes through. A show is one screening of one movie on one screen at one time, and each show has its own copy of the seat map.

The hard part is not the catalog of movies and theaters; it is the few minutes between picking seats and paying. Many users open the same popular show at once. Two of them must never both get seat F7, a user who closes the tab must not keep seats forever, and a payment that fails, or succeeds too late, must never leave a seat stuck or a card charged for nothing.

A strong answer says this early, spends most of the hour on the hold, and names the three failure cases: two users race for a seat, a hold expires, a payment fails or arrives late.

Scoping the problem

Ask these questions before you design anything, because each one settles a piece of the design.

  • Do we hold seats while the user pays? This decides whether a seat has a middle state. The usual answer is yes, for a few minutes.
  • How long is a hold? This is the timeout on the middle state. It is a setting, 8 minutes in the demo.
  • Can a user book some of the seats they picked? The choice is all or nothing, or partial. The usual answer is all or nothing.
  • Does the price depend on the seat? If so, there is a price per category per show. Usually there are two categories, standard and premium.
  • What is the cancellation rule? This is the refund formula. An example policy: a full refund a day ahead, half up to two hours before, and none after.
  • Is browsing movies and theaters in scope? That is a catalog, mostly reads. Mention it, then focus on booking.
  • One server or many? This picks an in-memory lock or a database lock. Design in memory, then say how the database does it.

Functional requirements

  • Shows: a movie on a screen at a start time, with a price per seat category
  • hold(show, seats, user): hold every requested seat or none, for a limited time
  • Expired holds free their seats; a declined payment frees them at once
  • pay_and_confirm(hold): charge and turn the hold into a booking; a retry never charges twice
  • cancel(booking): free the seats and refund by a cancellation policy based on time to showtime
  • available(show): the seats a user can pick right now

Non-functional requirements

  • A seat is never held or booked by two users (a lock per show, all-or-nothing holds)
  • No lock is held during the payment call; shows do not block each other
  • A failed or late payment never leaves a seat stuck or a card charged without a booking
  • Refund policy and payment provider are pluggable interfaces
  • Time is injected, so expiry and refunds are exact in tests

Interview questions

  • How does the database make sure two servers never hold the same seat?
  • Payment failed, or succeeded after the hold expired. What happens?
  • Why lock per show, and why not hold the lock during payment?
  • A blockbuster opens and 50,000 people want the same show. What changes?
  • How would you add dynamic pricing or a waitlist?

Sign up free to read the full topic

More Low-Level Design topics

Start free on Cariara · Coding problems · System design studio