Data Structures and Algorithms

Low-Level Design of BookMyShow: Object-Oriented Concepts in Action

Imagine booking a movie ticket on BookMyShow during a blockbuster release—millions of users are racing to secure their seats, and the system handles it all without a hitch. How does it do that? The answer lies in its low-level design (LLD), a detailed blueprint that uses object-oriented programming (OOP) principles to create a robust, scalable, and maintainable system. In this post, we’ll explore how BookMyShow’s LLD is crafted, diving into its classes, design patterns, database schema, and concurrency mechanisms. Whether you’re preparing for a technical interview or curious about system design, this guide will provide deep insights and actionable knowledge.

To master system design or other technical skills, sign up for our free courses or get the latest updates by clicking here.

Introduction to BookMyShow

BookMyShow is India’s leading online ticketing platform, enabling users to book tickets for movies, plays, sports events, and more. It connects users with theaters and event organizers, offering a seamless experience for discovering events, selecting seats, and making payments. Behind this user-friendly interface is a complex system that must handle user management, event searches, ticket bookings, payment processing, and notifications—all while ensuring high performance and reliability.

Understanding Low-Level Design

Low-level design (LLD) is the phase of software development where a high-level system design is translated into detailed components, such as classes, interfaces, and their interactions. Unlike high-level design, which focuses on the overall architecture, LLD dives into the nitty-gritty of how the system will be implemented, including code structure, data models, and algorithms. For BookMyShow, LLD involves designing classes for entities like users, movies, theaters, shows, seats, bookings, and payments, and defining how they work together to deliver a seamless experience.

Understanding Low-Level Design

To learn more about data structures and algorithms that underpin such designs, explore our DSA Course.

Object-Oriented Principles in System Design

Object-oriented programming (OOP) is a programming paradigm that uses objects to represent real-world entities. Its core principles are:

  • Encapsulation: Bundling data and methods within a class to protect data integrity.
  • Abstraction: Hiding complex implementation details and exposing only essential features.
  • Inheritance: Allowing new classes to inherit properties and behaviors from existing ones.
  • Polymorphism: Enabling objects of different classes to be treated as instances of a common superclass.

These principles ensure that BookMyShow’s code is modular, reusable, and easy to maintain, making it ideal for a system that needs to evolve with new features and user demands.

Designing BookMyShow: Step-by-Step

Let’s break down the process of designing BookMyShow using OOP principles, following a structured approach to object-oriented analysis and design (OOAD).

Identifying Actors

Actors are the users or external systems that interact with BookMyShow. The key actors are:

  • Customer: Books tickets and manages their profile.
  • Customer Care Representative: Handles customer support queries.
  • Front Desk Assistant: Verifies tickets at the venue.
  • Theater Administrator: Manages theater details and show schedules.
  • System Administrator: Oversees the system, managing user roles and configurations.

Each actor may correspond to a class or role within the system, influencing how functionalities are designed.

Use Cases

Use cases define the system’s functionalities from the user’s perspective. For BookMyShow, key use cases include:

  1. List cities with affiliate cinemas: Display available cities for ticket booking.
  2. Search movies and events: Filter by city, date, language, genre, or title.
  3. Select seats: View and choose available seats for a show.
  4. Book tickets: Complete the booking process with payment.
  5. Send notifications: Deliver booking confirmations via email or SMS.
  6. Manage theater information: Add, update, or remove theaters and shows.
  7. User management: Handle registration, login, and profile updates.
Designing BookMyShow_ Step-by-Step

Entities and Classes

Based on the use cases, we identify the main entities to be modeled as classes:

  • User: Represents customers, admins, or other roles.
  • Movie: Stores movie details like title, genre, and duration.
  • Theater: Contains theater information, including location and screens.
  • Screen: Represents a specific hall within a theater.
  • Show: Defines a movie screening at a specific time and screen.
  • Seat: Represents individual seats with types like regular or premium.
  • Booking: Manages ticket reservations for users.
  • Payment: Handles payment transactions.
  • Notification: Sends confirmations and reminders.

Relationships Between Classes

The relationships between classes define how they interact:

  • A Theater has multiple Screens.
  • A Screen contains multiple Seats.
  • A Show is associated with one Movie, one Screen, and specific StartTime and EndTime.
  • A Booking links a User to a Show and one or more Seats.
  • A Payment is tied to a Booking.
  • A Notification is sent to a User after a booking or other events.

These relationships ensure that the system’s components work cohesively.

Key Classes and Their Responsibilities

Here’s a detailed look at the key classes and their roles in BookMyShow’s LLD:

  • User Class:

    • Attributes: userId, name, email, phone, role (e.g., customer, admin)
    • Methods: register(), login(), updateProfile(), getBookingHistory()
  • Movie Class:

    • Attributes: movieId, title, genre, language, duration, rating
    • Methods: getDetails(), searchMovies(filter)
  • Theater Class:

    • Attributes: theaterId, name, location, list of screens
    • Methods: addScreen(), removeScreen(), getAvailableShows()
  • Screen Class:

    • Attributes: screenId, theaterId, name, capacity
    • Methods: getSeats(), addSeat()
  • Show Class:

    • Attributes: showId, movieId, theaterId, screenId, startTime, endTime
    • Methods: getAvailableSeats(), bookSeats(seatIds)
  • Seat Class:

    • Attributes: seatId, screenId, seatNumber, type (regular, premium, accessible, recliner), status (available, booked, locked)
    • Methods: lockSeat(), releaseSeat(), confirmBooking()
  • Booking Class:

    • Attributes: bookingId, userId, showId, seatIds, status (pending, confirmed, checked_in, canceled), paymentId
    • Methods: initiateBooking(), confirmBooking(), cancelBooking()
  • Payment Class:

    • Attributes: paymentId, bookingId, amount, status (unpaid, pending, completed, declined, canceled, refunded), method (cash, credit_card)
    • Methods: processPayment(), refund()
  • Notification Class:

    • Attributes: notificationId, userId, message, type (email, SMS), status
    • Methods: sendNotification(), trackStatus()

For hands-on practice with coding such systems, consider our Web Development Course.

Design Patterns Applied

Design patterns provide reusable solutions to common problems in software design. BookMyShow leverages several patterns:

  • Singleton Pattern: Ensures a single instance of services like UserService or ConfigurationManager, useful for managing global states.
  • Factory Pattern: Creates objects like payment gateways (e.g., PayPal, Stripe) based on user selection.
  • Strategy Pattern: Implements different search algorithms (e.g., by city, genre) for flexible filtering.
  • Observer Pattern: Notifies users when seats are booked or released, or when a show is about to start.
  • Command Pattern: Encapsulates booking actions, enabling undo/redo functionality.
  • Adapter Pattern: Integrates third-party payment gateways with the system’s payment service.

For example, the Observer Pattern is critical for seat locking: when a user locks seats, the system notifies other users if those seats become available again.

Database Schema

The database schema for BookMyShow includes tables that map to the main entities:

Table

Fields

User

userId (PK), name, email, phone, role

Movie

movieId (PK), title, genre, language, duration, rating

Theater

theaterId (PK), name, location

Screen

screenId (PK), theaterId (FK), name

Seat

seatId (PK), screenId (FK), seatNumber, type, price

Show

showId (PK), movieId (FK), theaterId (FK), screenId (FK), startTime, endTime

Booking

bookingId (PK), userId (FK), showId (FK), status, paymentId (FK)

Payment

paymentId (PK), bookingId (FK), amount, status, method

Notification

notificationId (PK), userId (FK), message, type, status

Database Schema

This schema ensures efficient data storage and retrieval, supporting the system’s functionalities.

Concurrency and Scalability Considerations

BookMyShow must handle high concurrency, especially during peak times like movie releases. Key considerations include:

  • Seat Locking Mechanism: Seats are locked for a short period (e.g., 10 minutes) when a user selects them, preventing double bookings. The Observer Pattern can notify other users when locks expire.
  • Database Transactions: Booking and payment processes are atomic to maintain data integrity.
  • Caching: Frequently accessed data, like movie details or theater information, is cached using tools like Redis to reduce database load.
  • Load Balancing: Traffic is distributed across multiple servers using tools like Nginx to handle high loads.
  • Microservices Architecture: The system is split into independent services (e.g., user service, booking service) that can be scaled separately.
Concurrency and Scalability Considerations

For a deeper dive into scalability and performance optimization, check out our System Design Course.

APIs for BookMyShow

To support its functionalities, BookMyShow relies on a set of RESTful APIs. Here are some essential APIs:

API

Description

POST /api/users/register

Registers a new user with name, email, and phone.

POST /api/users/login

Authenticates a user and returns a session token.

GET /api/movies?city={cityName}

Lists movies available in a specified city.

GET /api/shows?movieId={movieId}&city={cityName}

Lists shows for a movie in a city.

GET /api/seats?showId={showId}

Retrieves available seats for a show.

POST /api/bookings/lock

Locks selected seats for a user for a limited time.

POST /api/bookings/confirm

Confirms a booking after payment.

POST /api/payments

Processes a payment for a booking.

These APIs ensure smooth interaction between the front-end and back-end, built using technologies like ReactJS and Spring Boot. For more on building such APIs, explore our Web Development Course.

Technologies Used

BookMyShow’s tech stack includes:

  • Front-End: ReactJS, Bootstrap for a responsive UI.
  • Back-End: Java, Spring Boot, Hibernate for robust server-side logic.
  • Database: MySQL for structured data storage.
  • Caching: Hazelcast or Redis for performance optimization.
  • Notifications: RabbitMQ for sending emails and SMS.
  • Payment APIs: PayPal, Stripe, Square for secure transactions.
  • Deployment: Docker, Ansible for scalable infrastructure.
  • Logging: Log4J, ELK Stack for monitoring and debugging.

For those interested in data-driven systems, our Data Science Course covers relevant technologies.

Conclusion

Designing a system like BookMyShow requires a deep understanding of object-oriented principles, design patterns, and system architecture. By carefully defining actors, use cases, and classes, and applying patterns like Singleton, Factory, and Observer, we can create a system that is modular, scalable, and maintainable. Concurrency mechanisms like seat locking and scalability techniques like caching and load balancing ensure a seamless user experience.

If you’re preparing for technical interviews or want to master system design, our System Design Course and Crash Course offer hands-on practice and expert guidance.

FAQs

What is low-level design in system design?

Low-level design (LLD) involves breaking down a high-level system design into detailed components like classes and interfaces, focusing on implementation details.

 

OOP principles like encapsulation, abstraction, inheritance, and polymorphism create modular and reusable code for entities like movies, bookings, and payments.

What design patterns are used in BookMyShow’s system?

Patterns like Singleton, Factory, Strategy, Observer, Command, and Adapter handle tasks like global state management, object creation, and third-party integrations.

It uses a seat locking mechanism, temporarily reserving seats for a user and releasing them if the booking isn’t completed within a set time.

What technologies power BookMyShow’s system?

Technologies include ReactJS for the front-end, Spring Boot for the back-end, MySQL for the database, and tools like Redis and RabbitMQ for caching and notifications.

DSA, High & Low Level System Designs

Buy for 60% OFF
₹25,000.00 ₹9,999.00

Accelerate your Path to a Product based Career

Boost your career or get hired at top product-based companies by joining our expertly crafted courses. Gain practical skills and real-world knowledge to help you succeed.

Reach Out Now

If you have any queries, please fill out this form. We will surely reach out to you.

Contact Email

Reach us at the following email address.

arun@getsdeready.com

Phone Number

You can reach us by phone as well.

+91-97737 28034

Our Location

Rohini, Sector-3, Delhi-110085

WhatsApp Icon

Master Your Interviews with Our Free Roadmap!

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.