2Brute2Best
πŸ”₯0
P16

Design BookMyShow With Concurrent Seat Locking

Hard High-frequency interview topic Pro OnlyFacadeStateConcurrency std::jthread std::mutex
⚑ 30-Second Interview Cheat SheetP16 · 45-Min Design Plan
3 Patterns Combined
1. Scope Boundaries

In a 45-minute LLD interview, this problem is the gold standard for high-concurrency reservation systems under flash-sale loads. Scope the architecture to: multiple cinemas/screens/shows, atomic all-or-nothing multi-seat locking, inline TTL-based hold expiration, non-blocking external payment processing, and checkout pipeline orchestration via a Facade. Distributed Redis locks or database write-ahead logging can be discussed as scale-out extensions.

2. Core Noun Entities
BookingFacadestateful-class
SeatLockManagerstateful-class
ShowSeatdata-struct
PaymentGatewayinterface
3. Hotspot β†’ Pattern
End-to-end checkout orchestration across locking, payment, and ticketing β†’ Facade Pattern (BookingFacade)
Seat reservation lifecycle and temporary hold expiry β†’ State / TTL Pattern (ShowSeat states: Available, Held, Booked)
Pluggable payment provider integration β†’ Strategy Pattern (PaymentGateway interface)
01

Problem statement & clarifying requirements

Design a movie ticket booking platform like BookMyShow that supports multiple cinemas, screens, and shows. The core challenge is handling concurrent seat reservations under heavy flash-sale traffic: when hundreds of users race to book the exact same seats, the system must guarantee zero double-bookings, provide an atomic temporary seat hold with a Time-To-Live (TTL) during payment, and automatically release held seats if payment times out or fails.

Questions you should ask the interviewer first
β€œWhat happens when multiple users attempt to reserve the same seat simultaneously?”

Seat locking must be strictly atomic and mutually exclusive. Exactly one user acquires the lock; all competing requests fail immediately with a conflict signal.

β€œHow should temporary seat locks behave if the customer abandons payment?”

Each lock has a configurable TTL (e.g. 5–10 minutes). If confirmation does not arrive before the deadline, the seat automatically transitions back to available without requiring an explicit background cleanup sweep.

β€œCan a user book multiple seats in a single request?”

Yes. Multi-seat reservations follow all-or-nothing atomicity. If even one requested seat is unavailable, none are held.

β€œHow are payments and ticket generation decoupled from seat inventory?”

A BookingFacade coordinates the checkout pipeline: holding inventory, delegating payment to a gateway, confirming the seat status upon success, and issuing a serialized ticket.

02

First, sketch the design yourself

Spend 5 minutes listing the classes, who owns whom, and which interface hides the part that changes.

  1. 1.

    Distinguish between permanent booking and temporary hold: a seat cannot jump straight from Available to Booked because online payments take seconds to complete.

  2. 2.

    Avoid coarse-grained global locks across the entire cinema: scope synchronization to the specific show or seat partition using thread-safe data structures.

  3. 3.

    Decouple domain subsystems: the caller screen should interact with a single unified Facade interface rather than orchestrating lock managers, payment gateways, and ticket databases manually.

03

How to think through this problem (5-step walkthrough)

Step 1 Β· Scope the 45-minute target & core boundary

In a 45-minute LLD interview, this problem is the gold standard for high-concurrency reservation systems under flash-sale loads. Scope the architecture to: multiple cinemas/screens/shows, atomic all-or-nothing multi-seat locking, inline TTL-based hold expiration, non-blocking external payment processing, and checkout pipeline orchestration via a Facade. Distributed Redis locks or database write-ahead logging can be discussed as scale-out extensions.

Step 2 Β· Extract candidate nouns (and reject false classes)

Not every noun in the prompt deserves its own class. Separate dumb data structs from stateful managers, and turn trivial nouns into fields or enums.

BookingFacade
Stateful Class / Manager

Facade orchestrating end-to-end checkout: coordinates seat locking, payment gateway charges, seat confirmation, and ticket issuing while shielding clients from subsystem complexity.

SeatLockManager
Stateful Class / Manager

Thread-safe manager maintaining seat availability per show, enforcing atomic all-or-nothing locking and evaluating inline TTL expirations under a mutex.

ShowSeat
Value Struct

Domain record representing a seat in a show, tracking state (Available, Held, Booked), current holder user ID, and lock expiration deadline timestamp.

PaymentGateway
Abstract Interface

Strategy interface abstracting third-party payment processing (processPayment()), returning transaction receipts without holding inventory mutexes.

Ticket
Value Struct

Immutable value struct confirming a completed booking with booking ID, show reference, confirmed seat IDs, and payment details.

SeatHoldTimerThread
Reject as Class β†’ Field / Method

Trap noun β€” beginner candidates often spawn a background std::thread per held seat with a sleep_for(TTL) to release it. With thousands of concurrent users, this exhausts OS thread limits; seat lock expiration must be evaluated inline lazily by timestamp comparison (now > lockExpiration) under the lock.

Step 3 Β· Draft the naive design & spot what breaks

A naive implementation locks seats one-by-one in a loop (for (auto id : seatIds) lockSeat(id)). If User A locks seat 1 and User B locks seat 2 while both want seats [1, 2], a deadlock occurs or seats are left partially locked when one fails. Furthermore, holding a mutex while calling an external HTTP payment gateway causes thread starvation, bringing the entire booking portal to a complete crawl during flash sales.

Step 4 Β· Map change hotspots to design patterns
End-to-end checkout orchestration across locking, payment, and ticketing→ Facade Pattern (BookingFacade)

Exposing raw seat locks and payment APIs directly to API controllers leads to scattered rollback code and leaked locks upon payment failure.

Seat reservation lifecycle and temporary hold expiry→ State / TTL Pattern (ShowSeat states: Available, Held, Booked)

Treating seats as a binary boolean isBooked ignores the temporary hold window required while users complete payment authorization.

Pluggable payment provider integration→ Strategy Pattern (PaymentGateway interface)

Directly coupling checkout to a specific payment provider prevents unit testing with mock gateways and makes adding alternate providers difficult.

Step 5 Β· Lock down C++23 ownership, invariants & concurrency
  • βœ“

    All-or-nothing atomic seat locking: When a user requests multiple seats, all seats must be verified as available before any seat's status is mutated to Held. If any seat is unavailable or held by another user with an active TTL, the entire batch fails with zero side effects.

  • βœ“

    Zero mutex retention during external I/O: The SeatLockManager mutex is held only for microseconds during the in-memory state transition from Available β†’ Held or Held β†’ Booked. It is never held while calling PaymentGateway::processPayment().

  • βœ“

    Lazy inline TTL evaluation: A seat marked Held whose lockExpiration timestamp is less than now() is treated as immediately Available by subsequent locking attempts, avoiding wasteful background timer threads.

04

Entities & design patterns used

Brute2Best Pro Content

Unlock Full UML Diagram & C++23 Solution

The complete UML diagram, production-ready C++23 code, follow-up extensions, and design pitfall analysis are part of Brute2Best Pro. All 7 foundation chapters are 100% free.

All 440 visual dry runs & algorithms
Interactive step-by-step playback with pointer & array state transitions
52 comprehensive LLD chapters
Interactive UML diagrams, real-world stories (Food Delivery, Trading, RPG), and practice solutions
40 C++ basics labs & hardware memory models
Vtables, byte layouts, assembly insights, and multi-threading race conditions
Production-ready C++23 source code
Modern idioms, clean contracts, time/space complexity derivations, and interview takeaways

First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.

Systems Integration

Related C++ Systems & Algorithmic Foundations

Deep dive into underlying layers