System design for Online movie ticket booking system
In this tutorial we shall look at the system design for online movie ticket booking system.
A basic ticket booking system will work as below:
A user will go to that ticket booking website and book a ticket. The booking website will go to the theater database and books the ticket and return the status message to the user.
Basic flow:
So how does the ticket booking website know about the tickets availability and the status of the tickets?
This can be done by using any one of two methods explained below:
Method 1: Connect to Theatres DB
In this method, you can directly connect to theater database.
Method 2: Use Theatre API
In this method, the theater will expose the API like “get_total_ticket_count()”, “book_ticket()”. You can use those API for ticket booking.
Some of the characteristics of a ticket booking platform is discussed below:
1. Highly concurrent
2. ResponsiveUI
3. Distributed across multiple cities
4. Payment Integration
5. Movie Suggestions
6. Comments and Ratings
7. Movie Info
8. Send confirmed tickets my SMS, email and WhatsApp
1. Highly concurrent:
A highly successful ticket booking system will book around one hundred thousand tickets a day. Along with that it will also be users visiting the website for checking out the reviews and scanning for seats. Hence there will be too many reads and writes, hence there is a need for highly concurrent system.
2. ResponsiveUI: As users will be coming from different platform, like mobile, PC, laptop etc. The UI should be responsive to make user experience better. You can build a responsive UI for website and multiple mobile applications for multiple platforms.
3. Distributed across multiple cities
As there are multiple cities, the booking system should scale to support multiple cities.
4. Payment Integration
Now a days there are multiple ways to pay for a service, like debit card, credit card, wallets etc. The service should be able to support all these platforms. A easy way to integrate with a 3rd party service that supports all the payment system.
5. Movie Suggestions
Here by looking at the movie taste of the user, platform has to suggest up coming movies according to user taste.
6. Comments and Ratings
The user should be able to comment and rate the movie.
7. Movie Info
This section should give the information about the movie cast, crew and additional info about that particular movie.
8. Send confirmed tickets my sms, email and whatsapp
once the user successfully books a ticket, the system should send a copy of the ticket via SMS, email or whatsapp.
Below is the basic system design for online movie ticket booking platform.
Let us understand how all these system will work together:
Suppose a user is booking a ticket from mobile or PC, the request will first go to a loadbalancer server.
Load balancer can use consistence hashing or round robin technique to decide how the requests should be distributed across multiple app servers.
Next is to use caching. Caching will help to improve the user experience. You can use varnish or CDN for this service. These service will reduce the load on the app server by caching the content based on location, popularity etc.
App servers are scaled horizontally to handle load. Java, python or NodeJS based server are recommended.
For searching of the data, all the data can be loaded in elastic search server. This is recommended as it is distributed and highly available. This can also be used as an analytics engine.
Cache is used to store data related to movie info, ratings and comments.
Choosing DB is not a easy task. Here for this system we need to use both traditional RDBMS and NoSQL DB.
Where to use RDBMS?
We need RDBMS to achieve ACID properties and also to store relation between the tables. As we serve multiple cities and each city has multiple theater and each theater can have multiple screens, it make sense to use RDBMS. As the data gets increased only when we add new cities or new theaters, it can be managed easily.
As the data should be distributed across the locations, sharding of data is required. For this we can go with Master-slave-slave architecture. In this architecture, Master will be used for writing the latest data and slaves are used to read the data form the master.
Where to use NoSQL?
As each movie will have reviews, trailers, ratings, these data will increase as the movie increases. This data can be considered as big data. Hence in this case we need to use NoSQL. Cassandra can be used.
Async Workers:
As the user books a ticket, we need to send the ticket in multiple formats like HTML for email, PDF as attachment for email, image format for whatsapp. So the processing takes time. Instead of handling this service in app server, it can be delegated to async workers without blocking the app servers.
Recommendation Engine: We can use Hadoop to hold the data from a user and use that data as an input to PIG or HIVE queries to extract information that will help to build a recommendation engine.
So this completes the high level system design for a online movie ticket booking platform.