LLD: Design Movie Ticket Booking (BookMyShow)

System Design · Low-Level Design · Advanced · 30 min

Design the booking core of a BookMyShow-style app: shows and seat maps, all-or-nothing seat holds that expire, confirm and release, a swappable SeatLockProvider, and exactly why two people can never end up with the same seat even when they click at the same moment.

You pick 3 seats and the app shows a 10-minute timer. For those 10 minutes the seats are grey for everyone else. Pay in time and they turn into your ticket. Let the timer run out and they quietly turn green again for the next person.

The idea in everyday words

A shop that lets you put clothes aside at the counter for 10 minutes while you fetch your wallet. The assistant writes your name and the time on a tag. If you come back in time, you pay and the clothes are yours. If not, the next customer who asks gets them. And if you ask for a full outfit of 3 pieces, she only puts it aside if all 3 are free: half an outfit is no use to you.

Requirements and the core entities

Functional (the LLD core):

  • Browse: city → movies → theatres → shows (a movie on a screen at a time) → the seat map of a show.
  • Hold several seats for a few minutes while the user pays. All or nothing: if any seat is taken, hold none.
  • Book (confirm after payment) and release (user cancels). Holds expire on their own.
  • Never sell one seat of one show twice.

Entities:

Movie ── Show ── Screen ── Seat           (a Show = movie + screen + start time)
              │
              └─ ShowSeat {show, seat, status: FREE | HELD(user, until) | BOOKED(user)}

Booking {id, user, show, seats, amount, status: PENDING | CONFIRMED | CANCELLED}
Payment {booking, method, status}

The key modelling choice: a seat's status belongs to (show, seat), not to the seat. Seat A1 on Screen 2 is free at 6 pm and booked at 9 pm. Many designs go wrong right here by putting is_booked on Seat.

Services: a BookingService (hold, book, release) that talks to a SeatLockProvider (who holds what, until when) and a PaymentService. In this lesson's challenge we build the booking core for one show.

Holds: all or nothing, with expiry

Why hold at all? Payment takes minutes. Without a hold, two users could both reach the payment page for A2 and one of them would pay for a seat that is gone.

The hold rules:

  1. Validate every seat id first (A5 in a 4-column hall is an error).
  2. One active hold per user (they must book or release it first).
  3. Check every requested seat before taking any. A seat is unavailable if it is booked, or held by someone whose hold is still active.
  4. If all are free, take them all with one expiry time: until = now + ttl.

Active means now < until. At exactly until the hold is over. Pick one boundary rule, write it in one method (Hold.active), and use that method everywhere.

Lazy expiry. You do not need a timer per hold. Whenever code looks at a seat or a user's hold, it first checks "has this expired?" and cleans it up if so. A background sweeper can still clear old holds now and then, but correctness never depends on it.

holds = {"A1": ("asha", 10), "A2": ("asha", 10)}   # seat -> (user, until)

def free(seat, now):
    h = holds.get(seat)
    return h is None or now >= h[1]

for now in [9, 10]:
    print(now, [s for s in ["A1", "A2", "A3"] if free(s, now)])

Why all or nothing? A family of four does not want 3 seats. Holding the free ones and failing the rest leaves seats locked that nobody will buy, and other users see them as taken.

Class design

BookingService / Show
 ├─ booked: seat -> user                 (final, never expires)
 ├─ locks: SeatLockProvider              (injected: in-memory, Redis or database)
 ├─ hold(user, now, seats) -> "held ..." | "fail user seat" | error
 ├─ book(user, now)        -> "booked ..." | "fail user no active hold"
 ├─ release(user, now)
 └─ available(now) -> count

SeatLockProvider
 ├─ holder(seat, now) -> Hold or none   (expired holds are removed here)
 ├─ user_hold(user, now) -> Hold or none
 ├─ lock(user, seats, now) -> Hold
 └─ unlock(hold)

Hold { user, seats, until; active(now) = now < until }
  • SeatLockProvider is an interface. The in-memory version is two dictionaries (by seat and by user) for fast lookups both ways. In production the same methods are backed by Redis keys with an expiry, or by rows in the database. BookingService does not change.
  • Booking is final, holds are temporary. Keep them in separate structures so an expiry can never touch a sold seat.
  • book() re-checks the hold at confirm time. The user might pay after the hold expired: then the booking fails and the payment is refunded. Never assume the hold is still valid because it was valid a minute ago.

Concurrency: why two people never get the same seat

This is the question that separates a good answer from a great one. Picture two users clicking Hold A3 at the same instant on a multi-threaded server:

Time Thread 1 (asha) Thread 2 (ben)
1 is A3 free? yes
2 is A3 free? yes
3 take A3 for asha
4 take A3 for ben (overwrites asha)

Both were told "held". Both pay. Double booking. The bug is check-then-act: the check and the write are two separate steps, and another thread slipped in between.

Fixes, from one process to many servers:

  1. A lock around hold(). One lock per show (not one for the whole app), so different shows never wait for each other. Check all seats and take them inside the lock. Simple and correct for a single server.
  2. Lock the seats in a fixed order if you use one lock per seat: always lock A1 before A2. Two users locking {A1, A2} and {A2, A1} in different orders can deadlock.
  3. Database: pessimistic locking. SELECT ... FROM show_seat WHERE show_id = ? AND seat_id IN (...) FOR UPDATE inside a transaction, then update. Other transactions wait for those rows only.
  4. Database: optimistic / conditional update. UPDATE show_seat SET status = 'HELD', user = ?, until = ? WHERE show_id = ? AND seat_id IN (...) AND (status = 'FREE' OR until <= now) and check that the number of rows changed equals the number of seats; if not, roll back. No waiting, and a loser simply gets "fail".
  5. Redis-style holds. SET seat:show42:A3 asha NX PX 600000 sets the key only if it does not exist, with an expiry. For several seats, do it in one atomic script so it stays all or nothing.
  6. A unique constraint as the last line of defence: a unique index on (show_id, seat_id) in the bookings table makes a second confirmed booking for the same seat impossible, whatever bug exists above it.

Go deeper: payments, flash sales and fairness

  • Hold, pay, confirm is a small saga. Hold seats, create a PENDING booking, call the payment gateway with an idempotency key, then confirm. If payment succeeds after the hold expired, refund automatically. Payment webhooks arrive late or twice, so confirm must be idempotent too.
  • Hold length is a business trade-off. Too short and people lose seats while typing an OTP; too long and seats sit locked by people who left. Many apps use 5 to 10 minutes and extend once when the user reaches the payment page.
  • Flash sales (a big film's first day). Put a virtual waiting room in front so only a few thousand users at a time reach the seat map. Shard holds by show, and serve the seat map from a cache that may be a second stale: the hold itself is the strongly consistent check.
  • Seat map freshness. Push seat changes to open seat maps (WebSocket or server-sent events), or poll every few seconds. A stale map is fine because the hold re-checks.
  • Fairness and bots. Limit holds per user and per payment card, add CAPTCHA under heavy load, and cap seats per booking.
  • The Advanced Walkthrough: Ticket Booking lesson takes this design to stadium scale (high-level design, numbers, the waiting room in depth).

Step by step

  1. asha holds two seats:

    Hall of 2 rows × 4 seats, holds last 10. hold asha 0 A1 A2: both valid, asha has no hold, both free. Take both until 0 + 10: 'held asha A1 A2 until 10'.

  2. ben's hold fails as a whole:

    hold ben 1 A2 A3: A2 is held by asha and her hold is active (1 < 10). Answer 'fail ben A2', and A3 is NOT held for ben: all or nothing.

  3. ben holds other seats:

    hold ben 2 A3 A4: both free: 'held ben A3 A4 until 12'.

  4. asha confirms:

    book asha 5: her hold is still active (5 < 10), so A1 and A2 become BOOKED for good and the hold is removed: 'booked asha A1 A2'. available 6: 8 seats - 2 booked - 2 held by ben = 'available 4'.

  5. ben is too late:

    book ben 12: ben's hold ends at exactly 12, and active means now < until, so it has expired. It is cleaned up lazily, and the answer is 'fail ben no active hold'.

  6. Seats come back:

    hold chen 12 A3 B1: A3 is free again because ben's hold expired: 'held chen A3 B1 until 22'. available 13: 8 - 2 booked - 2 held = 'available 4'.

Code example

# Check-then-act, replayed step by step: two users try to hold A3 at the same moment.
def replay(with_lock):
    seat = {"A3": None}
    told = []
    if with_lock:
        for user in ["asha", "ben"]:            # the lock makes check + take one step
            if seat["A3"] is None:
                seat["A3"] = user
                told.append(user + ": held")
            else:
                told.append(user + ": fail")
    else:
        sees = {u: seat["A3"] is None for u in ["asha", "ben"]}  # both check first
        for user in ["asha", "ben"]:            # then both write
            if sees[user]:
                seat["A3"] = user
                told.append(user + ": held")
    return told, seat["A3"]

print("no lock:  ", *replay(False))
print("with lock:", *replay(True))

Complexity

  • Time: hold O(k) for k seats; book and release O(k); available O(rows × cols)
  • Space: O(S) for S seats: at most one hold entry and one booking entry per seat

Interview tips

  • Model ShowSeat (show + seat + status) early and say why status cannot live on Seat.

  • Describe hold → pay → confirm, with a TTL on holds, lazy expiry, and all-or-nothing multi-seat holds.

  • Draw the check-then-act race as a two-column timeline, then give the fixes: lock per show, SELECT FOR UPDATE, conditional update with a row count check, or SET NX with an expiry, plus a unique index as the final guard.

  • Mention lock ordering (A1 before A2) if you lock seats one by one, to avoid deadlocks.

  • Bring up the payment edge case: payment succeeds after the hold expired → refund, using an idempotency key so retries are safe.

Challenge: Seat Holds and Bookings for One Show

Build the booking core for one show. The hall has rows rows named A, B, C, ... and cols seats per row numbered from 1, so seats look like A1, B4. A hold lasts hold_ttl time units: a hold made at time t ends at until = t + hold_ttl and is active while now < until. Write run_booking(rows, cols, hold_ttl, ops) and return one output line per command.

Command Output
hold <user> <t> <seat> <seat> ... held <user> <seats as given> until <until>
book <user> <t> booked <user> <seats>, or fail <user> no active hold
release <user> <t> released <user>, or fail <user> no active hold
available <t> available <n>: seats neither booked nor under an active hold

hold checks, in this order:

  1. Every seat id is valid, else error: bad seat <first bad seat>.
  2. The user has no active hold, else error: <user> already holds seats.
  3. Every seat is free (not booked, no active hold by anyone), else fail <user> <first unavailable seat>, and nothing is held (all or nothing).

book turns the user's active hold into a final booking (booked seats never expire). release drops the user's active hold. Times never go down.

Use classes: a Hold with active(now), a SeatLockProvider that stores holds and expires them when it looks at them, and a Show that keeps the final bookings.

Example (2 rows × 4 seats, holds last 10):

run_booking(2, 4, 10, ["hold asha 0 A1 A2", "hold ben 1 A2 A3", "book asha 5", "available 6"])
  -> ["held asha A1 A2 until 10", "fail ben A2", "booked asha A1 A2", "available 6"]

Solve it in the browser with tests, hints and an AI coach.

Practice problems

More in Low-Level Design

Previous: LLD: Design Splitwise (Expense Sharing) · Next: Consensus & Leader Election (Raft, Leases, Fencing)