Clean coding in Bookmyshow
It’s really easy to search for your favorite movie in a theatre, check the seat availability, and, book the ticket on the BookMyShow app within just 5-10 minutes without much effort…
We all know the services of BookMyShow (after all we all love to watch the movies…lolz) and how it works, but can you imagine that behind this gigantic website how engineers have used their brains to build the complex architecture of this system?
And what if we ask you to design this system within just 45 minutes (or less) of a short time (is it a joke..??)…? We are not joking but if you’re someone who is preparing yourself to get into the top tech giant companies, you may face the system design round in interviews (especially for the role of senior engineer), and designing a system like BookMyShow is quite a common question of this round.
In this blog, we will discuss how to design an online ticket booking system like BookMyShow but before we go further we want you to read the article “How to crack system design round in interviews?”. It will give you an idea that what this round looks like, what you are expected to do, and what mistakes you should avoid in front of the interviewer. Along with this, you can also get mentored by industry experts by enrolling in the Mastering System Design Course and cracking SDE, SSE, Architect, Technical PM, and SDM job questions.
1. Define Goals and Requirements
Tell your interviewer that you’re going to support the below features. If the interviewer wants to add some more features he/she will mention that.
- The portal should list the different cities where the theatres are located. (RDBMS)
- Once the user selects the city it should display the movies released in that particular city to that user.
- Once the user selects the movie, the portal should display the cinemas running that movie and the available shows.
- Users should be able to select the show at a particular theatre & book the tickets (third-party payment support).
- Send a copy of tickets via SMS notification or Email. (workers and GCM)
- Movies suggestions when login (Hadoop and spark streaming with ML to get recommendation engine), real-time notifications to the user about new movie releases & other stuff.
- The portal should display the seating arrangement of the cinema hall to the user.
- Users should be able to select multiple seats according to their choice.
- Users should be able to hold the seats for 5-10 minutes before he/she finalized the payment.
- The portal should serve the tickets in a First In First Out manner
- Comments and rating (Cassandra)
- The system should be highly concurrent because there will be multiple booking requests for the same seat at the same time.
- The core thing of the portal is ticket bookings which means financial transactions. So the system should be secure and ACID compliant.
- Responsive design (ReactJS and Bootstrap) to run on devices of various sizes like mobile, tablet, desktop, etc.
- Movie information.
2. How does Bookmyshow Talk to Theatres?
When you visit any third-party application/movie tickets aggregator using the mobile app or website, you see the available and occupied seats for a movie show in that theatre. Now the question is how these third-party aggregators talk to the theatres, get the available seat information, and display it to the users. Definitely, the app needs to work with the theatre’s server to get the seat allocation and give it to the users. There are mainly two strategies to allocate seats to these aggregators.
- A specific number of seats will be dedicated to every aggregator and then these seats will be offered to the users. In this strategy, some seats are already reserved for these aggregators, so there is no need to keep updating the seat information from all the theatres.
- In the second strategy, the app can work along with the theatre and other aggregators to keep updating the seat availability information. Then the ticket will be offered to the users.
3. How to Get The Seat Availability Information?
There are mainly two ways to get this information…
The aggregators can connect to the theatre’s DB directly and get the information from the database table. Then this information can be cached and displayed to the user.
Use the theatre’s server API to get the available seat information and book the tickets.
What will happen if multiple users will try to book the same ticket using different platforms? How to solve this problem?
The theatre’s server needs to follow a timeout locking mechanism strategy where a seat will be locked temporarily for a user for a specific time session (for example, 5-10 minutes). If the user is not able to book the seat within that timeframe then release the seat for another user. This should be done on a first come first serve basis.
If you’re using the theatre’s server API then you will be making a lot of requests or IO-blocking calls from your server to the theatre’s server. To achieve better performance we should use async in Python or Erlangs lightweight threads or Go Coroutines in Go.
High-Level Architecture
BookMyShow is built on microservice architecture. Let’s look at the components individually.
Load Balancer
A load balancer is used to distribute the load on the server and to keep the ystem highly concurrent when we are scaling the app server horizontally. The load balancer can use multiple techniques to balance the load and these are…
- Consistent Hashing
- Round Robin
- Weighted Round Robin
- Least Connection
APIs Needed
- GetListOfCities()
- GetListOfEventsByCity(CityId)
- GetLocationsByCity(CityId)
- GetLocationsByEventandCity(cityid, eventid)
- GetEventsByLocationandCity(CityId, LocationId)
- GetShowTiming(eventid, locationid)
- GetAvailableSeats(eventid, locationid, showtimeid)
- VarifyUserSelectedSeatsAvailable(eventid, locationid, showtimeid, seats)
- BlockUserSelectedSeats()
- BookUserSelectedSeat()
- GetTimeoutForUserSelectedSeats()
Technologies Used By Bookmyshow
- User Interface: ReactJS & BootStrapJS
- Server language and Framework: Java, Spring Boot, Swagger, Hibernate
- Security: Spring Security
- Database: MySQL
- Server: Tomcat
- Caching: In memory cache Hazelcast.
- Notifications: RabbitMQ. A Distributed message queue for push notifications.
- Payment API: Popular ones are Paypal, Stripe, Square
- Deployment: Docker & Ansible
- Code repository: Git
- Logging: Log4J
- Log Management: ELK Stack
- Load balancer: Nginx
PerfectionGeeks specializes in developing high-quality ticket booking apps like BookMyShow, offering seamless user experiences and advanced features. Get in touch with them for a detailed cost estimate!
ReplyDelete