System requirements
Functional:
List functional requirements for the system (Ask the chat bot for hints if stuck.)...
- Create a user profile and view current tickets
- Ability to search for movie theaters near you and upcoming movies
- Ability to select seats
- A holding page that reserves the seat for you for a few minutes while you fill out payment information
- (admin) add new movies and theaters
Non-Functional:
List non-functional requirements for the system...
- Consistency - only one person can book a seat at a time
- Security (user authentication)
- Latency - some latency when processing payment is ok
- Scalability - Handle traffic spikes for popular movies
Capacity estimation
Estimate the scale of the system you are going to design...
10,000 visitors per day
Around 1 read per second
500 daily users that purchase a ticket
Less than one write per second
API design
Define what APIs are expected from the system...
GET /v1/movies - returns the movies nearby
POST /v1/reservation - Reserve a ticket to a movie. The reservation is a hold on a ticket until the payment is processed
POST /v1/ticket - Reserves the actual ticket
(admin)
post /v1/movies
post /v1/theater
Database design
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
Here are the entities that the system will need to track
- User profiles - names, emails, address, ticket history
- Theaters and Movies - a collection of movies and theaters along with the theater locations and movie times
- Available seats for a movie
- Purchased tickets
- Reservations - these are a short term hold on a ticket. It is crucial that only one person hold a reservation at a time
The user profiles, theaters, movies and purchased tickets can all be stored in a SQL database. We can use Postgres because it supports geosharding which will be helpful for finding theaters near you.
The reservation system and available seats can be stored in a Redis cache because we need faster writes to help avoid conflicts. We can utilize Redis increment functionality to when reserving a ticket.
High-level design
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
- Load balancer to distribute API calls to servers
- API gateway to handle authentication
- Rate Limiter to avoid one user overwhelming the server
- Search Movie server - handles query requests for movies
- Reservation server - handles ticket reservations
- User and Movie database - Postres DB that stores user profile and general movie data
- CDN - stores static images and videos such as movie previews
- Reservation Cache - handles
Request flows
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Detailed component design
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Trade offs/Tech choices
Explain any trade offs you have made and why you made certain tech choices...
Another option is to use a SQL database for reservations and utilize transactions in order avoid conflicts on the reservation. However, when we scale the database and add partitions, transactions will be much slower with a two phase commit. This is why I have decided to utilize the Redis approach for Reservations.
Failure scenarios/bottlenecks
Try to discuss as many failure scenarios/bottlenecks as possible.
Future improvements
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?
Include more details about the Admin APIs