List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
100 Million Daily active users
Read QPS = 100M/100k = 1000
During peak hours = 2 * QPS = 2000
Write will be 1% of users who buys ticket
write QPS = 10
During peak hours = 20
So it is a read heavy system
Define what APIs are expected from the system...
GET /v1/theatres/:locationId
Retrieve list of theatres for this location
Response:
data: [
{
theatreId:
address:{
}
email:
phone:
}
]
GET /v1/movies/:theatreId
We need to provide theatreId and it will return all the movies running in this theatre
Response:
data: [
{
movieId:
movieName:
timeslot:
}
]
GET /theaters/{theaterId}/movies/{movieId}/seats?datetime={dateTime}
This will give the information about seats for a specific theatre and for a specific movie running in that theatre
Response:
{
"theaterId": 123,
"movieId": 456,
"dateTime": "2024-09-25T18:30:00",
"seats": [
{
"position": "A1",
"occupied": true
},
{
"position": "A2",
"occupied": false
},
{
"position": "A3",
"occupied": true
},
{
"position": "B1",
"occupied": false
}
]
}
POST /v1/seats/hold
This request will to hold the seat for the specific movie
Request params
POST /tickets/hold
Content-Type: application/json
{
"theaterId": "123",
"movieId": "456",
"datetime": "2024-09-25T19:30:00",
"seatId": "A1"
}
It will return response based on the availability
200 OK:
{
ticketId:
Status: held
}
400 Bad Request:
If the theatreId, movieId is invalid
500 Internal server error
If not able to hold the seat please try again
GET /ticket/:ticketId/status
It will return the status of the ticket
POST /v1/payment
It will be available to make payment
Request Body:
{
ticketId:
info:{
creditcard no:
expiry date:
cvv no:
}
Response:
200 OK if the payment successful
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...
Theatre
Show
Seat
Movie
Bookings
Database Choices
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...
Client: The client customer used to book a ticket. It could be a web app or mobile app.
Load Balance: Balance the traffic from client evenly to different servers. The load could be balanced with path based, round robin or consistent caching approaches.
Api Gateway: Api Gateway will be responsible with authentication, rate limiting and others.
CDN: Store static files, for example movie preview images, movie tailor and theater images. When user request static data, the request will be routed to the CDN which physically close to the client.
Info Service: Info service will be responsible to read request from clients. For example, get theater info, get movie info and get seat info.
Ticket Service: Ticket service will be responsible to update the database to hold a ticket and query a ticket status.
Task Scheduler: The task scheduler will be responsible to schedule a time after user hold a ticket. If the user didn't pay the ticket in a certain time (5 min or 10 min), the task scheduler will be responsible to update the status of the ticket.
SQL Database: The database will be responsible to store the information of the theater, movie, seat and ticket.
Database Cache: Will cache the SQL Database to read data faster.
Notification Service: Notification service will be responsible to send ticket confirmation notification to the client through SMS, email or push notifications.
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...
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...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?