Functions
- The system should allow customers to
search
for movies and cinemas based on their locations (cities) - When a cinema is selected, should list all available movies (with rankings, prices, types, etc.)
- When a movie is selected, should list all cinemas and their available shows
- When a cinema, a movie and a show are all selected, the customer should be able to select from multiple available seats
- The customer should be able to
hold
the selected seats for 5 mins to finalize payment - The customers making transactions should be serviced in a
first-come-first-serve
manner - The service should be reliable (handle
concurrent requests
) and secure (ACID
) - The system should be highly
scalable
to handle the surge in traffic (release of popular movies)
Capacities
Assume we have:
- 500 cities
- 20 cinemas in each city
- 1000 seats/cinema on average
- 20 shows/day on average
- 50% placing rate on average
Number of tickets per day = 500 * 20 * 1000 * 20 * 50% = 100M
Assume for each booking request we need:
- cinema_id 2 bytes
- movie_id 4 bytes
- customer_id 4 bytes
- show_id 8 bytes
- seat_id 8 bytes
- timestamp 8 bytes
- 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
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.
- Partition by showId; Consistent Hashing
- Caching