THN Interview Prep

Design BookMyShow (LLD)

1. Requirements

  • Functional

    • Cities contain venues; shows run at events with seat maps.
    • Users select contiguous or best-available seats; hold briefly while paying.
    • Booking confirms seats and issues tickets; cancellation policy applies refunds.
  • Non-Functional

    • No double booking same seat for overlapping confirmation window.
    • Horizontally sharded by show id in production; object model stays consistent.
  • Assumptions / Out of Scope

    • Payment PSP integration stubbed; inventory authoritative in booking service.

2. Core Entities

EntityResponsibilityKey Attributes
CityRegion containername, venues
VenuePhysical locationidentifier, screens
ShowMovie or performancetitle, duration
ScreenHall with seatsidentifier, seatLayout
SeatBookable unitrowLabel, number, category
ShowRunTimetabled instanceshow, screen, startTime
BookingPurchased set of seatsuserId, seats, status
SeatHoldTemporary lockseats, expiresAt

3. Class Diagram

Loading diagram…

4. State / Sequence Diagram (where relevant)

Loading diagram…

5. Design Patterns Applied

6. Implementation

Go

package booking

type Seat struct {
    Identifier string
    RowLabel   string
    Number     int
}

type ShowRun struct {
    Identifier string
    ScreenID   string
    StartsAt   time.Time
}

type BookingService struct {
    Inventory SeatInventory
}

func (service *BookingService) HoldSeats(runID string, seatIDs []string) (holdToken string, err error) { /* ... */ }
func (service *BookingService) Confirm(holdToken string, paymentRef string) (*Booking, error) { /* ... */ }

JavaScript

class BookingService {
  constructor({ seatInventory, paymentClient }) {
    this.seatInventory = seatInventory;
    this.paymentClient = paymentClient;
  }
  async holdSeats({ runId, seatIds }) { /* ... */ }
  async confirmBooking({ holdToken, paymentMethod }) { /* ... */ }
}

7. Concurrency / Thread Safety

  • Collisions: Two users selecting same seat before hold.
  • Granularity: Transactional compare-and-set on seat status; short TTL holds with token.
  • Go: Mutex per ShowRun during hold creation or rely on DB constraints.

8. Extensibility & Followups

  • Dynamic pricing by seat category and show demand.
  • Waitlists when sold out.
  • Edge cases: partial payment failure after hold, show cancellation refunds en masse.

Last updated on

Spotted something unclear or wrong on this page?

On this page