0% found this document useful (0 votes)
136 views

System Design

process to system design

Uploaded by

hvalola
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
136 views

System Design

process to system design

Uploaded by

hvalola
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 18
6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium Design BookMyShow — A System Design Interview Question ‘Anu Upadhyay - Follow @min read » Jan2 © tisten (Share 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 how behind this gigantic website how engineers have used their brains to build the complex architecture of this system? What if we ask you to design this system within just 45 minutes (or less) of a short time (isit a joke..2?)...? 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. 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. tps simedium.com/@anwupadhyay1984/design-bookmyshow-a-system-design nterview.queston-tBa6adbdcSa? 18 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium © Once the nser selects the movie the nortal shonld disnlaw the cinemas running that mov * Users sh e 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. ‘tions. * The core thing of the portal is ticket bookings which means financial transa So the system should be secure and ACID compliant. + Responsive design (ReactJ$ 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 tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 28 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium work with the theatre's server to gat the seat allncation and sive it ta the ners, There are mainly t * Aspecif on 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. * Inthe 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 10- blocking calls from your server to the theatre's server. To achieve the better performance we should use async in python or Erlangs lightweight threads or Go Coroutines in Go! High-Level Architecture tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 38 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium nin with your member acec 3 : only store SS — a ort L___& ee EET Tem stn LL. co se Sea | et Oe | Ctr t | = _- seen fe |¢ £ rk 0s... rin Bae ea 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 system highly concurrent when we are scaling the app server horizontally. The load balancer can use multiple techniques to balance the load and these are... 1. Consistent Hashing 2. Round Robin 3. Weighted Round Robin 4, Least Connection Frontend Caching and CDN tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? a8 6/15/23, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium We do frontend caching using Varnish to reduce the Inad fram the hackend, infrastructu co, images, and other cc App Servers There will be multiple app servers and BookMyShow uses Java, Spring Boot, Swagger, and Hibernate for the app servers. We can also go with Python-based or Node] servers (Depending on requirements). We also need to scale these app servers horizontally to take the heavy load and to handle a lot of requests in parallel. Elastic Search Elastic search is used to support the search APIs on Bookmyshow (to search movies or shows). Elastic search is distributed and it has RESTful search APIs available in the system. It can be also used as an analytics engine that works as an App-level search engine to answer all the search queries from the front end. Caching To save the information related to the movies, seat ordering, theatres, etc, we need to use caching. We can use Memcache or Redis for caching to save all this information in Bookmyshow. Redis is open-source and it can be also used for the locking mechanism to block the tickets temporarily for a user. It means when a user is trying to book the ticket Redis will block the tickets with a specific TTL. Database ‘We need to use both RDBMS and NoSQL databases for different purposes. Let's analyze what we need in our system and which database is suitable for what kind of data... * RDBMS: We have mentioned that we need ACID property in our system. Also, we have countries, cities, theatres in cities, multiple screens in these theatres, and multiple rows of seats on each screen. So here it is clear that we need a proper relationship representation. Also, we need to handle the transaction. RDBMS is fit for these cases. The portal will be read-heavy so we need to shard the data by Geo or we need to use master-master slave architecture. Slaves can be used for reading and master for writing. + NoSQL: We also have a huge amount of data like movie information, actors, crew, comments, and reviews. RDBMS can not handle this much amount of data so we tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 518 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium need to nse the NaSOI. datahase which can he distribnted Cascandra can be a good choice t« Fdata in multiple lability and durabilit, . her nodes). * Use HDFS to run queries for analytics. Async Workers ‘The main task of the Async worker is to execute the tasks such as generating the pdf or png of the images for booked tickets and sending the notification to the users. For push notifications, SMS notifications, or emails we need to call third-party APIs. These are network IO and it adds a lot of latency. Also, these time-consuming tasks can not be executed synchronously. To solve this problem, as soon as the app server confirms the booking of the tickets, it will send the message to the message queue, a free worker will pick up the task, execute it asynchronously and provide the SMS notification, other notifications, or email to the users. RabbitMQ or Kafka can be used for Message Queueing Systems and Python celery can be used for workers. For browser notifications or phone Notifications use GCM/ APN. Business Intelligence and ML For data analysis of business information, we need to have a Hadoop platform. All the logs, user activity, and information can be dumped into Hadoop, and on top of it, we can run PIG/Hive queries to extract information like user behavior or user graph. ML is used to understand the user’s behavior and to generate movie recommendations etc. For real-time analysis, we can use Spark streaming. We can also figure out fraud detection and mitigation strategy using the Spark or Storm stream processing engine. Log Management ELK (ElasticSearch, Logstash, Kibana) stack is used for the logging system. All the logs are pushed into the Logstash. Logstash collects data from all the servers via Files/Syslog/socket/AMQP etc and based on a different set of filters it redirects the logs to Queue/File/Hipchat/Whatsapp/JIRA etc. Step By Step Working « The customer visits the portal and filters the location. To find the location we can use GPS (if it’s a mobile phone) or ISP (if it’s a laptop). Then the theatres and movies tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 618 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium released in that theatres will he snecested to the ncer Data will he nrovided from DB and1 * Users se all the nearby theatres. * Users select a particular date and time for a movie in his/her own choice of theatre. The available seat information will be fetched from the database and it will be displayed to the user. * Once the user selects the available seat, BMS locks the seat temporarily for the next 10 minutes. BMS interacts with the theatre DB and blocks the seat for the user. The ticket will be booked temporarily for the current user and for all the other users using different aggregators or apps the seat will be unavailable for the next 10 minutes. If the user is failed to book the ticket within that timeframe the seat will be released for the other aggregators. « Ifthe user continues with the booking he/she will check the invoice with the payment option and after the payment via the payment gateway, the app server will be notified about the successful payment. « After successful payment, a unique ID will be generated by the theatre and it will be provided to the app server. * Using that unique ID a ticket will be generated with a QR code and a copy of the ticket will be shown to the user. Also, a message to the queue will be added to send the invoice copy of the ticket to the user via SMS notification or email. The ticket will have all the details such as the movie, address of the theatre, timing, theatre number, ete. * At movie time, when the customer visits the theatre the QR code will be scanned and the customer will be allowed to enter the theatre if the ID will be matched on both customer's ticket and the theatre's ticket. APIs Needed © GetListOfCities() + GetListOfiventsByCity(Cityld) tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 18 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium © GetLocationsRwCitw/Citeta) * GetLoca * GetEven.. * GetShowTiming(eventid, locationid) * GetAvailableSeats(eventid, locationid, showtimeid) * VarifyUserSelectedSeatsAvailable(eventid, locationid, showtimeid, seats) « BlockUserSelectedSeats() * BookUserSelectedSeat() GetTimeoutForUserSelectedSeats() RDBMS Tables * Place (To save the hierarchal data for any given theatre-like country, state, city, and street) © Theatre * Screen * Tier (tier of seats) * Seats * Movie * Offers * Ticket User Relationship Between RDBMS Tables: * One to many: Place and theatre. * One to many: Theatre and screen tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? ane 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium © One to many: Screen and Tier One ton One to o.. One to many: User and Tickets One to many: Tickets and Seats NoSQL Tables There will be no relationship between these tables. Comments * Ratings * Movie Information « Trailers or Gallery © Artists * Cast and Crew + Reviews Analytics Data Technologies Used By Bookmyshow © User Interface: ReactJS & BootStrapJS Server language and Framework: Java, Spring Boot, Swagger, Hibernate Securit Spring Security Database: MySQL Server: tomcat Caching: In memory cache Hazelcast. * Notifications: RabbitMQ. A Distributed message queue for push notifications. tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? one 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium ¢ Payment APT: Ponnlar anes are Pavnal Strine Samare Deployn Code rep. Logging: Log4J Log Management: ELK Stack Load balancer: Nginx Alot of candidates get afraid of the system design round more than the coding round. The reason is... they don’t get an idea that what topics and tradeoffs they should cover within this limited timeframe. They need to keep in mind that the system design round is extremely open-ended and there's no such thing as a standard answer. For the same questions, the conversation with the different interviewers can be different. Your practical experience, your knowledge, your understanding of the modern software system, and how you express yourself clearly during your interview matter a lot to designing a system successfully. System Design Interview Software Development Programming Computer Science System Architecture CIO Written by Anu Upadhyay 210 Followers tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 108 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium Engineer at Infoaain India. Ex-GeeksForGeeks. httos://wwwlinkedin.com/in/anu-upadhvav/ inwith you .com) to view other men More from Anu upaunyay era = £o- oe ee Ci a ® Anuupadnyay System Design of Uber App—Uber System Architecture It's really easy to just tap a button on our mobile phone and get the cab available within few minutes whenever and wherever we want... 10min read + Apr 30, 2022 Sm Q2 tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 118 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium [RENNIN 1) Fetch data from cache | You are si (pu_@g., ed out. Sig inwith your member account .com) to view other member: only stories, Sig} WEEE 4 persists the data from DB in cane Application ppelics cache Database ® Anvupadhyay Caching—System Design Concept For Beginners Facebook, Instagram, Amazon, and Flipkart...these applications are the favorite applications for a lot of people and most probably these... t2minread » Apr2 3 Q n COUNT OF SUBCATEGORY Linked List Searchvsort aex Bit Manipulation/Math Dynamic Programming 40% 40% = Array/String 306% tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 1288 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium ® anvupaany in with your member other You are signed out Microsoft] (°¥[email protected]™) to view Bill Gates... It wuesn auc! u you ale o years Ulu UI ov years Ulu, peuiE KiUW Uns ame very Well and its contribution to this world. A. 8minread + Dec 15, 2022 o4 Q ni =a — i rm ® anuupadnyay System Design Netflix—A Complete Architecture Can you design Netflix in 45 minutes? 15min read - Apr9,2022 Swe Qi C See all from Anu Upadhyay ») tps simedium,com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 1388 6115923, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium System Design Interview Survival Guide Cache Senars Client Application Servers Databases & Arsian Ahmad in Level Up Coding System Design Interview Survival Guide (2023): Preparation Strategies and Practical Tips ‘System Design Interview Preparation: Mastering the Art of System Design. + 14min read + Jan 19 & 1% tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 148 6115923, 837 AM & sonn Raines Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium Be an Engineer, not a Frameworker Time to level up. + + 10minread - Mar8,2022 18k Openinapp 7 Q a ‘Search Medium iystories - 129 saves Leadership 30 stories - 59saves Good Product Thinking ‘istories . 126 saves Stories to Help You Level-Up at Work 19stories » 99.saves tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium DYN ~~ 4 I You are signed out. Sign in vn (pu__@g__.com) to (a) , PaREwR \ » ® saced Mohajeryami, PhO Solution Architect Interview Questions: The Top 25 Q8A + + 24minread » Jan 22 n sym Qs tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? 1618 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium ® Love sharms in row System De Developing a standing the key concepts aru wunpurents Galt Hane ue. @minread - Apr20 Sax Qa ct 7 Algorithms to KNOW beTore Your next System Design Interview. yo ESET Hea) Wxbnana ut | Menten) | Myetlnata} | Hr HeOae Pat) Consistent Hashing Merkle Tree & Asian Ahmad in Level Up Coding 7 Algorithms to Know Before Your Next System Design Interview Get your next system design interview off to a great start. + 6minread ~ Dec21,2022 ssa Q W tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? s18 6115123, 837 AM Design BookMyShow — A System Design Interview Question | by Anu Upadhyay | Medium 1 Write-aroune | ign (pu__@g__.com) to view other mem storie: Caching Layer Suitable Scenarios: * in-memory solution + Read heavy system + Datais net frequently ica updated ® Love Sharma in Dev Genius AComprehensive Guide to Distributed Caching An essential website requires a web server to receive requests and a database to write or read data, However, this simple setup will only.. + + 13minread +» Febs Hae Qe it, Sign in with your member account Key Metrics Cache Hit Latency ‘Throughput Invalidation Rate Memory Usage PU usage Network usage C ‘See more recommendations tps simedium.com/@anwupadhyay1984/design-bookmyshow-2-system-design nterview.queston-tBa6adbdc8a? LY 188

You might also like