Podcast
Questions and Answers
Which factor most significantly challenges the design of a highly concurrent movie ticket booking system?
Which factor most significantly challenges the design of a highly concurrent movie ticket booking system?
- Implementing user authentication to personalize ticket booking options.
- Ensuring a wide selection of movie genres to cater to diverse user preferences.
- Managing multiple booking requests for the same seat at any given moment. (correct)
- Providing detailed movie descriptions and trailers to enhance user experience.
In designing a movie ticket booking system, prioritizing speed of transaction processing is more critical than ensuring ACID compliance for financial transactions.
In designing a movie ticket booking system, prioritizing speed of transaction processing is more critical than ensuring ACID compliance for financial transactions.
False (B)
Besides preventing abuse, what is another key rationale for restricting the number of seats a user can book at once in a movie ticket booking system?
Besides preventing abuse, what is another key rationale for restricting the number of seats a user can book at once in a movie ticket booking system?
Maintaining fairness
To accommodate traffic spikes on popular movie releases, a ticket booking system should be both scalable and highly ______.
To accommodate traffic spikes on popular movie releases, a ticket booking system should be both scalable and highly ______.
Match each API parameter for the 'SearchMovies' function with its description:
Match each API parameter for the 'SearchMovies' function with its description:
Which isolation level in SQL databases provides the highest level of protection against concurrency issues like dirty reads, non-repeatable reads, and phantom reads?
Which isolation level in SQL databases provides the highest level of protection against concurrency issues like dirty reads, non-repeatable reads, and phantom reads?
Using 'MovieID' for database partitioning is generally a better approach than using 'ShowID' to distribute the load evenly across servers, especially for popular movies.
Using 'MovieID' for database partitioning is generally a better approach than using 'ShowID' to distribute the load evenly across servers, especially for popular movies.
In the context of handling reservation expirations, what is the purpose of adding a buffer (e.g., five seconds) on the server-side timer?
In the context of handling reservation expirations, what is the purpose of adding a buffer (e.g., five seconds) on the server-side timer?
The ActiveReservationsService uses a data structure similar to a Linked HashMap or TreeMap to efficiently manage reservations, with the head pointing to the ______ reservation record.
The ActiveReservationsService uses a data structure similar to a Linked HashMap or TreeMap to efficiently manage reservations, with the head pointing to the ______ reservation record.
Match the component with its primary responsibility in the detailed component design of a movie ticket booking system:
Match the component with its primary responsibility in the detailed component design of a movie ticket booking system:
What is the primary function of the ActiveReservationService
in a movie ticket booking system?
What is the primary function of the ActiveReservationService
in a movie ticket booking system?
The WaitingUserService uses a Last-In-First-Out (LIFO) approach to manage waiting users, ensuring the most recent requests are served first.
The WaitingUserService uses a Last-In-First-Out (LIFO) approach to manage waiting users, ensuring the most recent requests are served first.
What communication technique can clients use to stay updated on their reservation status from the WaitingUserService, particularly when waiting for seats to become available?
What communication technique can clients use to stay updated on their reservation status from the WaitingUserService, particularly when waiting for seats to become available?
To handle concurrency and prevent two users from booking the same seat, SQL databases use ______ to lock rows before updating them.
To handle concurrency and prevent two users from booking the same seat, SQL databases use ______ to lock rows before updating them.
Match the potential outcome with its corresponding waiting page scenario:
Match the potential outcome with its corresponding waiting page scenario:
What is the primary purpose of partitioning the ActiveReservationService and WaitingUserService based on 'ShowID' using Consistent Hashing?
What is the primary purpose of partitioning the ActiveReservationService and WaitingUserService based on 'ShowID' using Consistent Hashing?
When the ActiveReservationsService crashes, the active reservations data cannot be recovered unless there is a master-slave configuration in place.
When the ActiveReservationsService crashes, the active reservations data cannot be recovered unless there is a master-slave configuration in place.
If a user's reservation expires, a message is broadcast to all WaitingUserService servers to determine the longest waiting user. What information does the Consistent Hashing scheme provide to identify these servers?
If a user's reservation expires, a message is broadcast to all WaitingUserService servers to determine the longest waiting user. What information does the Consistent Hashing scheme provide to identify these servers?
In the database, the 'Status' field in the 'Booking' table is updated to '______' once a booking is complete, and the reservation record is removed from the relevant show's Linked HashMap.
In the database, the 'Status' field in the 'Booking' table is updated to '______' once a booking is complete, and the reservation record is removed from the relevant show's Linked HashMap.
Match each step in the ticket booking workflow with its potential outcome if seats cannot be reserved:
Match each step in the ticket booking workflow with its potential outcome if seats cannot be reserved:
Which of the following is NOT a typical parameter for the SearchMovies
API?
Which of the following is NOT a typical parameter for the SearchMovies
API?
The ReserveSeats
API returns a detailed seating map to the user, indicating which seats are available and which are already reserved.
The ReserveSeats
API returns a detailed seating map to the user, indicating which seats are available and which are already reserved.
What type of data structure is recommended for storing every reservation for every show in the ActiveReservationsService
, where the key is 'ShowID'?
What type of data structure is recommended for storing every reservation for every show in the ActiveReservationsService
, where the key is 'ShowID'?
The ActiveReservationsService interacts with an external ______ service to process user payments.
The ActiveReservationsService interacts with an external ______ service to process user payments.
Match each term related to database transaction isolation levels with its definition:
Match each term related to database transaction isolation levels with its definition:
Which strategy is employed to allocate application servers for both the ActiveReservationService and WaitingUserService based upon the 'ShowID'?
Which strategy is employed to allocate application servers for both the ActiveReservationService and WaitingUserService based upon the 'ShowID'?
When WaitingUsersService crashes, the waiting users data can be easily recovered from the database as long as their requests were persisted.
When WaitingUsersService crashes, the waiting users data can be easily recovered from the database as long as their requests were persisted.
In the provided SQL code snippet for handling concurrency, what is the purpose of SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
?
In the provided SQL code snippet for handling concurrency, what is the purpose of SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
?
In addition to keeping data in the database, the ActiveReservationsService also keeps all reservations of a 'show' in ______ in a data structure.
In addition to keeping data in the database, the ActiveReservationsService also keeps all reservations of a 'show' in ______ in a data structure.
Match each API parameter for the ReserveSeats
function with its description:
Match each API parameter for the ReserveSeats
function with its description:
What is the significance of the Consistent Hashing scheme allocating three servers for any Show for load balancing in the ActiveReservationService and WaitingUserService?
What is the significance of the Consistent Hashing scheme allocating three servers for any Show for load balancing in the ActiveReservationService and WaitingUserService?
Using Long Polling, the server immediately notifies the client as soon as seats are available, regardless of whether the client has an active request.
Using Long Polling, the server immediately notifies the client as soon as seats are available, regardless of whether the client has an active request.
What is the potential consequence of partitioning the database by 'MovieID' when there is a highly popular movie?
What is the potential consequence of partitioning the database by 'MovieID' when there is a highly popular movie?
Within a database transaction using 'Serializable' isolation level, if we read rows, we get a ______ lock on them so that they cannot be updated by anyone else.
Within a database transaction using 'Serializable' isolation level, if we read rows, we get a ______ lock on them so that they cannot be updated by anyone else.
Match the step taken by a server holding a reservation that has expired, with its purpose:
Match the step taken by a server holding a reservation that has expired, with its purpose:
After a successful reservation, what action is taken by the server holding that reservation to optimize seat allocation for waiting users?
After a successful reservation, what action is taken by the server holding that reservation to optimize seat allocation for waiting users?
According to design considerations, the ticket-booking system handles partial ticket orders, allowing users to book whatever number of seats are currently available.
According to design considerations, the ticket-booking system handles partial ticket orders, allowing users to book whatever number of seats are currently available.
In the context of the SearchMovies
API, what does setting includeSpellcheck
to 'yes' achieve?
In the context of the SearchMovies
API, what does setting includeSpellcheck
to 'yes' achieve?
When a reservation expires, the system updates the Status
to ______ in the ‘Booking’ table.
When a reservation expires, the system updates the Status
to ______ in the ‘Booking’ table.
Match each status returned by the function ReserveSeats
with its description:
Match each status returned by the function ReserveSeats
with its description:
What is the potential risk of partitioning the database by MovieID
in a high-demand online ticket booking system?
What is the potential risk of partitioning the database by MovieID
in a high-demand online ticket booking system?
Using Dirty
transaction isolation level in SQL guarantees safety from Nonrepeatable and Phantoms reads.
Using Dirty
transaction isolation level in SQL guarantees safety from Nonrepeatable and Phantoms reads.
In a concurrent ticket booking system, what ACID property is most crucial for ensuring that seat reservations are handled correctly, preventing overbooking and ensuring financial integrity?
In a concurrent ticket booking system, what ACID property is most crucial for ensuring that seat reservations are handled correctly, preventing overbooking and ensuring financial integrity?
To prevent a client from timing out before the server in a ticket reservation system, a buffer of five seconds can be implemented on the ______.
To prevent a client from timing out before the server in a ticket reservation system, a buffer of five seconds can be implemented on the ______.
Match each component with its primary responsibility in handling ticket reservations.
Match each component with its primary responsibility in handling ticket reservations.
Flashcards
Online Movie Ticket Booking System
Online Movie Ticket Booking System
A system that allows customers to purchase movie tickets online.
Functional Requirement #1
Functional Requirement #1
Lists cities with affiliate cinemas.
Functional Requirement #2
Functional Requirement #2
Displays movies released in a selected city.
Functional Requirement #3
Functional Requirement #3
Signup and view all the flashcards
Functional Requirement #4
Functional Requirement #4
Signup and view all the flashcards
Functional Requirement #5 & 6
Functional Requirement #5 & 6
Signup and view all the flashcards
Functional Requirement #7
Functional Requirement #7
Signup and view all the flashcards
Functional Requirement #8
Functional Requirement #8
Signup and view all the flashcards
Functional Requirement #9
Functional Requirement #9
Signup and view all the flashcards
Non-Functional Requirement #1
Non-Functional Requirement #1
Signup and view all the flashcards
Non-Functional Requirement #2
Non-Functional Requirement #2
Signup and view all the flashcards
Design Consideration #2
Design Consideration #2
Signup and view all the flashcards
Design Consideration #3
Design Consideration #3
Signup and view all the flashcards
Design Consideration #4
Design Consideration #4
Signup and view all the flashcards
Design Consideration #5
Design Consideration #5
Signup and view all the flashcards
api_dev_key
api_dev_key
Signup and view all the flashcards
keyword
keyword
Signup and view all the flashcards
city
city
Signup and view all the flashcards
lat_long
lat_long
Signup and view all the flashcards
radius
radius
Signup and view all the flashcards
start_datetime
start_datetime
Signup and view all the flashcards
end_datetime
end_datetime
Signup and view all the flashcards
postal_code
postal_code
Signup and view all the flashcards
includeSpellcheck
includeSpellcheck
Signup and view all the flashcards
results_per_page
results_per_page
Signup and view all the flashcards
sorting_order
sorting_order
Signup and view all the flashcards
session_id
session_id
Signup and view all the flashcards
movie_id
movie_id
Signup and view all the flashcards
show_id
show_id
Signup and view all the flashcards
seats_to_reserve[]
seats_to_reserve[]
Signup and view all the flashcards
City-Cinema Relationship
City-Cinema Relationship
Signup and view all the flashcards
Cinema-Hall Relationship
Cinema-Hall Relationship
Signup and view all the flashcards
Movie-Show Relationship
Movie-Show Relationship
Signup and view all the flashcards
Show-Booking Relationship
Show-Booking Relationship
Signup and view all the flashcards
User-Booking Relationship
User-Booking Relationship
Signup and view all the flashcards
ActiveReservationsService
ActiveReservationsService
Signup and view all the flashcards
WaitingUsersService
WaitingUsersService
Signup and view all the flashcards
Linked HashMap
Linked HashMap
Signup and view all the flashcards
ActiveReservationsService Task
ActiveReservationsService Task
Signup and view all the flashcards
Serializable Isolation Level
Serializable Isolation Level
Signup and view all the flashcards
Within a transaction
Within a transaction
Signup and view all the flashcards
Recovering ActiveReservationsService
Recovering ActiveReservationsService
Signup and view all the flashcards
Master-Slave Configuration
Master-Slave Configuration
Signup and view all the flashcards
Database Partitioning
Database Partitioning
Signup and view all the flashcards
Consistent Hashing
Consistent Hashing
Signup and view all the flashcards
Study Notes
- A movie ticket booking system allows customers to purchase theatre seats online, browse movies, and book seats from anywhere.
Functional Requirements:
- List cities with affiliated cinemas.
- Display movies released in a selected city.
- Show cinemas running a selected movie and available show times.
- Allow users to choose a show and book tickets.
- Display the seating arrangement, with users able to select seats.
- Distinguish available seats from booked ones.
- Hold seats for users for five minutes before payment.
- Allow users to wait for seats that might become available.
- Service waiting customers in a first-come, first-served manner.
Non-Functional Requirements:
- Handle high concurrency gracefully and fairly.
- Ensure the system is secure and the database is ACID compliant due to financial transactions.
Design Considerations:
- The service does not require user authentication.
- Partial ticket orders are not supported; users get all desired tickets or none.
- Fairness is mandatory.
- Limit users to booking no more than ten seats at a time to prevent abuse.
- The system should be scalable and highly available to handle traffic spikes.
Capacity Estimation:
- 3 billion page views per month.
- 10 million tickets sold per month.
- 500 cities, each with ten cinemas on average.
- Each cinema has 2000 seats and two shows daily.
- Each seat booking requires 50 bytes of storage in the database (IDs, seat details, etc.).
- Movie and cinema info takes 50 bytes.
- Daily data storage: 2GB.
- Five-year data storage: 3.6TB.
System APIs
- SOAP or REST APIs can expose service functionality.
SearchMovies
- Used to search movie shows with parameters:
- api_dev_key (string): API developer key for throttling.
- keyword (string): Keyword to search on.
- city (string): City to filter movies by.
- lat_long (string): Latitude and longitude to filter by.
- radius (number): Radius of the area in which we want to search for events.
- start_datetime (string): Filter movies with a starting datetime.
- end_datetime (string): Filter movies with an ending datetime.
- postal_code (string): Filter movies by postal code / zipcode.
- includeSpellcheck (Enum: “yes” or “no”): Include spell check suggestions.
- results_per_page (number): Number of results to return per page (max 30).
- sorting_order (string): Sorting order of the search result.
- Returns a JSON list of movies and their shows with details like MovieID, ShowID, Title, Description, Duration, Genre, Language, ReleaseDate, Country, StartTime, EndTime, and Seat availability and pricing.
ReserveSeats
- Used to reserve seats with parameters:
- api_dev_key (string): API developer key.
- session_id (string): User session ID to track reservation.
- movie_id (string): Movie to reserve.
- show_id (string): Show to reserve.
- seats_to_reserve (number): An array of seat IDs to reserve.
- Returns a JSON status of the reservation:
- "Reservation Successful".
- "Reservation Failed - Show Full".
- "Reservation Failed - Retry, as other users are holding reserved seats".
Database Design:
- Each city can have multiple cinemas.
- Each cinema will have multiple halls.
- Each movie will have many shows, and each show will have multiple bookings.
- A user can have multiple bookings.
High-Level Design:
- Web servers manage user sessions.
- Application servers handle ticket management.
- Data stored in databases and cache servers.
Detailed Component Design:
-
Ticket booking workflow:
- User searches for a movie and selects one.
- Available shows are displayed.
- User selects a show.
- User selects the number of seats.
- If seats are available, the user is shown a theatre map.
- User selects seats, and the system tries to reserve them.
-
If seats cannot be reserved:
- The user is shown an error if the show is full.
- If other seats are available, the user is taken back to the theatre map.
- If no seats are available but some are in the reservation pool, the user can wait.
- If seats become available, the user is taken to the theatre map.
- If all seats get booked or there are fewer seats in the reservation pool than the user intends to book, the user is shown the error message.
- The user can cancel waiting.
- A user can wait a maximum of one hour.
- If seats are reserved successfully, the user has five minutes to pay.
ActiveReservationsService:
- Tracks active reservations and removes expired ones.
- Keeps reservations of a show in memory using a Linked HashMap or TreeMap.
- Stores reservations in the Booking table in the database with a Timestamp column for expiry.
- Works with external financial services for payments.
- Signals WaitingUsersService upon booking completion or reservation expiry.
WaitingUsersService:
- Tracks all waiting user requests.
- Keeps waiting users of a show in memory using a Linked HashMap or TreeMap.
- Uses Long Polling to keep clients updated on their reservation status.
Reservation Expiration:
- ActiveReservationsService tracks expiry based on reservation time.
- A five-second buffer is added on the server to prevent early timeouts.
Concurrency:
- Transactions in SQL databases can prevent booking the same seat by multiple users.
- Transaction Isolation Levels can lock rows before updating.
Fault Tolerance:
- If ActiveReservationsService crashes, active reservations can be read from the Booking table.
- A master-slave configuration can allow a slave to take over.
- Master-slave setup for databases to make them fault-tolerant.
Data Partitioning:
- Partitioning by ShowID distributes load among servers better than partitioning by MovieID. -Web servers manage user sessions and communication. -Consistent Hashing allocates application servers for ActiveReservationService and WaitingUserService based on ShowID.
- When a reservation expires:
- The database is updated.
- The reservation is removed from the Linked HashMap.
- The user is notified.
- A message is broadcast to WaitingUserService servers to find the longest-waiting user.
- A message is sent to the WaitingUserService server to process the request if seats are available.
- When a reservation is successful:
- A message is sent to all servers holding waiting users of that Show.
- Servers query the database to find available seats (a database cache helps).
- Waiting users wanting more seats than available are expired.
- WaitingUserService iterates through the Linked HashMap of waiting users.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.