Design a Movie Ticket Booking System
What is the Movie Ticket Booking Problem?
Section titled “What is the Movie Ticket Booking Problem?”Design a movie ticket booking system that allows customers to search for movies, view showtimes, select seats, make bookings, and process payments. The system should handle concurrent seat bookings, manage seat availability with different seat types and pricing, and support booking confirmation and cancellation.
In this problem, you’ll design a system that handles multiple theaters, movies, and shows, while ensuring that seat reservations are fair, atomic, and time-limited.
Problem Overview
Section titled “Problem Overview”Design a system where users can browse movies, select shows in nearby theaters, and book specific seats while handling simultaneous requests gracefully.
Core Requirements
Section titled “Core Requirements”Functional Requirements:
- Search & Browse: View movies and available showtimes across different theaters and screens.
- Seat Layout: Display available seats with row and number for a selected show.
- Reservation: Temporarily reserve selected seats; prevent double booking through thread-safe operations.
- Booking & Payment: Complete bookings by processing payment, transitioning seats from Reserved to Booked.
- Cancellation: Support booking cancellation, releasing seats back to the Available pool.
- Seat Types: Support different types (Regular, Premium, VIP) with specific pricing strategies.
- Expiration: Automatically release reserved seats if payment is not completed within a time limit (e.g., 10 mins).
- Social Features: Provide functionality to find adjacent seats for group bookings.
- Notifications: Notify customers when previously unavailable seats become available.
Non-Functional Requirements:
- Modular OOD: Clear separation of concerns between theaters, shows, seats, and bookings.
- Concurrency: Absolute prevention of race conditions or double-bookings during seat selection.
- Flexibility: Easy to add new pricing models, loyalty programs, or seat types.
- Reliability: The core booking logic should be robust, testable, and maintainable.
What’s Expected?
Section titled “What’s Expected?”1. System Architecture
Section titled “1. System Architecture”The system coordinates between the BookingService, TheaterService, and PaymentProcessor.
2. Key Classes to Design
Section titled “2. Key Classes to Design”classDiagram
class Theater {
-String name
-List~Screen~ screens
}
class Show {
-Movie movie
-DateTime startTime
-Map~Seat, SeatStatus~ seats
+getAvailableSeats()
}
class Booking {
-String id
-Show show
-List~Seat~ seats
-BookingStatus status
+confirm()
+cancel()
}
class Seat {
-String id
-SeatType type
-double price
}
Theater "1" *-- "many" Screen
Screen "1" *-- "many" Show
Show "1" *-- "many" Seat
Booking "1" o-- "many" Seat
System Flow
Section titled “System Flow”Seat Booking Flow
Section titled “Seat Booking Flow”Key Design Challenges
Section titled “Key Design Challenges”1. Double Booking Prevention
Section titled “1. Double Booking Prevention”If two users click “Book” on the same seat at the same time, the system must only allow one to proceed.
Solution: Use Optimistic Locking or Distributed Locks. In a single-server setup, use a ConcurrentHashMap of seat locks. For a distributed system, use Redis to set a TTL lock on the seat ID.
2. Handling Timeouts
Section titled “2. Handling Timeouts”If a user reserves a seat but their internet fails or they change their mind, that seat shouldn’t be “stuck” in a reserved state forever.
Solution: Implement a TTL (Time To Live) mechanism. When a seat is reserved, schedule a task (using a ScheduledExecutorService or a TTL in Redis) that releases the seat if the payment isn’t confirmed within 10 minutes.
3. Dynamic Seat Pricing
Section titled “3. Dynamic Seat Pricing”Seats in the front row should cost more, and prices might increase as the showtime approaches.
Solution: Use the Strategy Pattern. Create a PricingStrategy that takes the SeatType and ShowTime as inputs. This allows you to change pricing logic (e.g., holiday surcharges) without touching the seat or show classes.
What You’ll Learn
Section titled “What You’ll Learn”By solving this problem, you’ll master:
- ✅ Resource Locking - Managing shared resources in high-contention scenarios.
- ✅ State Management - Coordinating multi-step transaction flows.
- ✅ Timeout Logic - Implementing robust expiration mechanisms.
- ✅ Scalable Inventory - Modeling complex nested entities (Theater > Screen > Show > Seat).
View Complete Solution & Practice
Section titled “View Complete Solution & Practice”Ready to see the full implementation? Open the interactive playground to access:
- 🎯 Step-by-step guidance through the 8-step LLD approach
- 📊 Interactive UML builder to visualize your design
- 💻 Complete Code Solutions in Python, Java, C++, TypeScript, JavaScript, C#
- 🤖 AI-powered review of your design and code
Related Problems
Section titled “Related Problems”After mastering Movie Ticket Booking, try these similar problems:
- Hotel Management - Long-term resource reservation.
- Airline Reservation - Complex seat maps and pricing.
- Parking Lot - Real-time slot allocation.