[Design] 设计售票系统

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值