Introduction
What is BookMyShow
It is a platform which allows users to book an ticket to events like movie, concert, shows etc.
Steps to tackle this question
-
Requirements
- Functional requirements: These are the core functionalities of our system
- Non Functional requirements: These are the qualities of our system
Entities
These are the data bodies that would be used to help us understand what kind of data is being moved in our systemAPIs
These are the endpoints that would be used to fulfill our functional requirements and other functions to help services communicate between each otherHLD
This design would satisfy our functional requirementsDeep Dive:
This is where we are going to full fil our Non functional requirements
With the roadmap ready, let's get started
1. Requirements
Functional Requirements
We want our systems to fulfill the below core functionalities
- Search for shows/movies/events in their city
- View the details of the event(this refers to all the above mentioned)
- Book a ticket for the event
Non-functional requirements
Here we will try to decide the quality of our system
- We want consistency in our booking service since we don't want multiple people to book the same seats for an event
- Availability for searching an event
- Low latency for searching
- Scalability to handle surges, maybe to book a ticket to a famous convert(like book tickets for the cold play concert in india, boy that was an experience)
- Prioritize reads >> writes since we would mostly searching and looking at events when compared to booking tickets
2. Entities
We are now going to decide which data types are we going to use in our system
- Event - Use to store details about a events
- User - store details about the user
- Ticket - Store the information about the event reservation
- Performer - Store details about then performer who is going to perform at an event
- Venue - Details about a particular venu, ex: Capacity, location, amenities etc
3. APIs
Now we are going to define the endpoints that are going to satisfy our functional requirements
For search/view an event
Request:
GET /events/:eventId
Response:
Event, Performer, Venue, Tickets[]
Search for an event
Request:
GET /search?term={searchTerm}&location={locationOfEvent}&type={typeOfEvent}&...
Response:
Partial<Event>[]
We get a list of partial Event types so that we get the basic idea about the event and if we want to know more details then we can click on the event and that will hit the /events/:eventId
for more details
Book a ticket
This is going to be a little tricky since we don't want multiple users to book the same seats we are going to use 2 phase to tackle this.
Phase 1 - we lock the seats for some time so that user can book the seats within some time let's say x mins. If booking fails then we open the tickets to other users.
Request:
POST /booking/reserve
header: JWT session token
body: {
ticketId: "ad98384109ffe0"
}
Phase 2 - User books the ticket and we mark the seats booked
Reqeust:
POST /booking/confirm
header: JWT session token
body: {
ticketId,
paymentDetails (3rd party payment provider details)
}
Now that we have decided on the Entities and APIs, let get into High level design
4. High Level Design
5. Deep dive
Now that we have satisfied a functional requirements we can go deep diving into a non functional requirements
The area of improvements are
- Improving the search speed which is the low latency search
Introducing elasticsearch for querying the events which stores the events against tokenized terms (term: [event1, event2 ...])
we can use the event CRUD service to update the data in both database and the elastic search but that would add complexity to our event CRUD service since it would be updating both the elasticsearch and the database'
In order to better handle this updation of data we will use change data captures which is CDC. So first we will make an update to database and then eventually the database will utilize CDC and send that data to elasticsearch
We can also cache popular events which will reduce the search time
- Scalability to handle surges from popular event
Problem: if a user is checking seats for a popular event then they might face an issue because a lot of people are checking that event at the same time so this can lead to users having delayed response or no response at all
Possible Solutions
- Long Polling
- Websockets
- SSE
So in order to tackle the issue of multiple uses trying to book seats for popular event we can take the approach of using virtual queue where N users will be inserted into the queue. Once the users are in the queue we can have something like an SSE which will send an event to the user mentioning that now they can book their ticket.
The waiting queue can be configured to only be used for popular events, so this way we don't have to use queue every time.
Updated HLD diagram
That's all folks hope you had a great time reading this blog and I hope to see you again and if you have any suggestions or questions please comment down below.
Top comments (0)