Functions

  1. The system should allow customers to search for movies and cinemas based on their locations (cities)
  2. When a cinema is selected, should list all available movies (with rankings, prices, types, etc.)
  3. When a movie is selected, should list all cinemas and their available shows
  4. When a cinema, a movie and a show are all selected, the customer should be able to select from multiple available seats
  5. The customer should be able to hold the selected seats for 5 mins to finalize payment
  6. The customers making transactions should be serviced in a first-come-first-serve manner
  7. The service should be reliable (handle concurrent requests) and secure (ACID)
  8. The system should be highly scalable to handle the surge in traffic (release of popular movies)

Capacities

Assume we have:

  1. 500 cities
  2. 20 cinemas in each city
  3. 1000 seats/cinema on average
  4. 20 shows/day on average
  5. 50% placing rate on average

Number of tickets per day = 500 * 20 * 1000 * 20 * 50% = 100M

Assume for each booking request we need:

  1. cinema_id 2 bytes
  2. movie_id 4 bytes
  3. customer_id 4 bytes
  4. show_id 8 bytes
  5. seat_id 8 bytes
  6. timestamp 8 bytes
  7. payment info 16 bytes

Storage per request = 50 bytes
Storage per day = 50bytes * 100M = 5GB

in 5 years, we need:
Storage in 5 years = 5GB * 1800 = 9TB

API

We need a searchMovie api and a orderTicket api

APIs

searchMovie(String keyWord, String cinema, String city, Time startTime, Time endTime, int rating, int resultPerPage, long userId, boolean sortOrder)

orderTicket(long api_dev_key, long sessionId, long orderId)

Models

Movie(long id, String name, String type, String description, int duration, Date releaseDate, String language, String genre, String country, Seat[] seats)

Seat(long id, String type, double price, boolean status, long orderId)

Show(long id, long movieId, long hallId, long cinemaId, Time startTime, Time endTime)

Hall(long id, long cinemaId, int totalSeats, String name)

Cinema(long id, String name, long cityId, String city, String State, String zip, Address address)

User(long id, String userName, String password, String email, String phone)

Order(long id, String status, long userId, long movieId, long showId, long hallId, long cinemaId, long[] seats, Time orderTime, int paymentType, long transactionId)

Design

clients --(requests)-- load balancer --(distribute)-- web servers -- application servers --(cache servers)-- databases

Reservation service

solution: Map<showId, LinkedHashMap<orderId, timestamp>>

Waiting List service

solution: put current waiting order request in queue, when there's reservation expired, send notification to the head of the queue; clients can use long polling to keep themselves updated

Data Partition

Think about the workflow.

  1. Partition by showId; Consistent Hashing
  2. Caching

linspiration
161 声望53 粉丝