Design Bookmyshow

Ashutosh Kumar Singh
5 min readNov 6, 2024

--

Step 1: Clarify and Document Requirements

BookMyShow should fulfill the following requirements:

  1. User Registration & Login: Users can register, log in, and manage their profile.
  2. Search Movies and Events: Users can browse and filter movies/events by city, date, language, and genre.
  3. Select Seats: Users can view available seats for a show, choose seats, and hold them temporarily.
  4. Booking and Payment: Users can complete the booking process by making a payment.
  5. Notification: Send booking confirmations via email or SMS.

Non-functional requirements:

  • Concurrency: Support multiple users selecting seats simultaneously.
  • Scalability: The system should scale to handle high traffic.
  • Fault Tolerance: If a component fails, the system should recover gracefully.

Step 2: Core Modules and Design Patterns

To build a maintainable and scalable system, we’ll use design patterns to address specific needs in each module.

  1. User Management: Manages user profile, registration, and login.
  • Pattern: Singleton Pattern for UserService ensures only one instance of the user service is created.

2. Search and Browsing: Allows users to search movies and filter by various criteria.

  • Pattern: Factory Pattern to create different search filters and Strategy Pattern to implement different search algorithms (e.g., search by city, genre, etc.).

3. Seat Selection and Booking: Handles seat selection, locking, and booking.

  • Pattern: Observer Pattern for seat locking to notify the system of locked or released seats.
  • Pattern: Command Pattern for handling booking actions in a consistent, queue-able format.

4. Payment Processing: Integrates with a third-party payment service.

  • Pattern: Adapter Pattern to abstract external payment gateway interactions.

5. Notification Service: Sends booking confirmation and reminders.

  • Pattern: Observer Pattern to manage notifications as background tasks, decoupling them from the main booking flow.

Step 3: Class Design and Relationships

1. User Management

  • User class to represent each user.
  • UserService class to manage registration, login, and profile updates.

Classes:

class User {
private String userId;
private String name;
private String email;
private String phone;
private List<Booking> bookingHistory;
    public void viewBookingHistory() { /* Implementation */ }
}
class UserService {
private static UserService instance; // Singleton instance
private UserService() {} // Private constructor for Singleton public static UserService getInstance() {
if (instance == null) {
instance = new UserService();
}
return instance;
}
public User register(String name, String email, String phone) { /* Implementation */ }
public User login(String email, String password) { /* Implementation */ }
}

2. Movie and Theater Browsing

  • Movie class stores details like title, genre, language, and rating.
  • Theater and Screen classes represent the structure of each theater and its screens.

Classes:

class Movie {
private String movieId;
private String title;
private String genre;
private String language;
private double rating;
}
class Theater {
private String theaterId;
private String name;
private String location;
private List<Screen> screens;
}
class Screen {
private String screenId;
private String screenNumber;
private List<Seat> seats;
public List<Seat> getAvailableSeats(Show show) { /* Implementation */ }
}

3. Seat and Show Management

  • Show class holds information on each specific movie show.
  • Seat class represents individual seats with status (available, locked, or booked).
  • Pattern: Observer PatternSeat is observed by the SeatLockService to notify when a seat is locked/unlocked.

Classes:

class Show {
private String showId;
private Movie movie;
private Theater theater;
private Screen screen;
private Date startTime;
private Date endTime;
    public List<Seat> getAvailableSeats() { /* Implementation */ }
}
class Seat {
private String seatId;
private String seatNumber;
private SeatStatus status; // Enum (Available, Locked, Booked)
private double price;
public void lockSeat() { /* Notify observer about lock */ }
public void releaseSeat() { /* Notify observer about release */ }
}

Step 4: Booking Management and Seat Locking Mechanism

  • Booking and SeatLockService manage booking operations.
  • Pattern: Command Pattern to handle booking as a separate task with a queue for processing payments.

Classes:

class Booking {
private String bookingId;
private User user;
private Show show;
private List<Seat> seats;
private BookingStatus status; // Enum (Reserved, Confirmed, Cancelled)
private Payment payment;
    public void reserveSeats() { /* Lock seats and create booking */ }
public void cancelBooking() { /* Release seats and update status */ }
public void confirmBooking() { /* Complete booking */ }
}
class SeatLockService {
private Map<String, Seat> lockedSeats = new HashMap<>();
public void lockSeat(Seat seat, int timeout) {
/* Implementation: lock seat and set timer */
}
public void releaseSeat(Seat seat) {
/* Implementation: release lock */
}
}

Step 5: Payment Processing

  • Pattern: Adapter Pattern to integrate with different payment providers.
  • The PaymentService acts as an adapter to different payment gateways.

Classes:

interface PaymentGateway {
boolean processPayment(double amount);
}
class PaymentService {
private PaymentGateway gateway;
public PaymentService(PaymentGateway gateway) {
this.gateway = gateway;
}
public boolean makePayment(double amount) {
return gateway.processPayment(amount);
}
}

Step 6: Notification System

  • Pattern: Observer Pattern — Notifications are queued and sent asynchronously.
  • The NotificationService class observes booking actions and sends notifications as necessary.

Classes:

class Notification {
private String notificationId;
private User user;
private String message;
private NotificationType type; // Enum (EMAIL, SMS)
}
class NotificationService {
public void sendNotification(Notification notification) {
/* Implementation to send SMS or email */
}
}

Step 7: Database Design

  1. User Table: user_id, name, email, phone
  2. Booking Table: booking_id, user_id, show_id, status, payment_id
  3. Movie Table: movie_id, title, genre, language, rating
  4. Theater Table: theater_id, name, location
  5. Screen Table: screen_id, theater_id
  6. Seat Table: seat_id, screen_id, status, price
  7. Show Table: show_id, movie_id, theater_id, screen_id, start_time, end_time
  8. Payment Table: payment_id, booking_id, amount, status
  9. Notification Table: notification_id, user_id, message, type

Step 8: Sequence Diagram (for Booking Process)

  1. User selects movie, theater, and showtime.
  2. System fetches available seats and displays them.
  3. User selects seats, which SeatLockService locks temporarily.
  4. User proceeds to payment. On success, Booking status updates, and seat statuses are set to booked.
  5. NotificationService sends confirmation via SMS/email.

Step 9 . APIs for BookMyShow

Here are the essential APIs for the BookMyShow system:

1. User APIs

  • Register User
    POST /api/users/register
  • Request: { "name": "John Doe", "email": "john@example.com", "phone": "1234567890" }
  • Response: { "userId": "u123" }
  • Login User
    POST /api/users/login
  • Request: { "email": "john@example.com", "password": "password" }
  • Response: { "userId": "u123", "token": "jwt-token" }

2. Movie APIs

  • Get Movies in City
    GET /api/movies?city={cityName}
  • Response: { "movies": [{ "movieId": "m123", "title": "Movie Title" }, ...] }
  • Get Movie Details
    GET /api/movies/{movieId}
  • Response: { "movieId": "m123", "title": "Movie Title", "genre": "Action" }

3. Theater and Show APIs

  • Get Showtimes for a Movie in City
    GET /api/shows?movieId={movieId}&city={cityName}
  • Response: { "shows": [{ "showId": "s123", "theater": "Theater Name", "startTime": "18:00" }, ...] }
  • Get Seat Availability for Show
    GET /api/seats?showId={showId}
  • Response: { "seats": [{ "seatId": "seat123", "status": "available" }, ...] }

4. Booking APIs

  • Lock Seats
    POST /api/bookings/lock
  • Request: { "showId": "s123", "seatIds": ["seat123", "seat124"], "userId": "u123" }
  • Response: { "lockId": "lock123", "status": "locked" }
  • Confirm Booking
    POST /api/bookings/confirm
  • Request: { "lockId": "lock123", "paymentId": "p123" }
  • Response: { "bookingId": "b123", "status": "confirmed" }

5. Payment API

  • Initiate Payment
    POST /api/payments
  • Request: `{ "bookingId": "b123", "amount

This detailed design covers primary components and patterns needed for a maintainable and scalable system like BookMyShow. Each pattern serves to decouple, modularize, or extend system components, making it well-suited for growth and high concurrency.

--

--

Ashutosh Kumar Singh
Ashutosh Kumar Singh

No responses yet