Movie Ticket Booking System

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

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.

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?

Maintaining fairness

To accommodate traffic spikes on popular movie releases, a ticket booking system should be both scalable and highly ______.

<p>available</p> Signup and view all the answers

Match each API parameter for the 'SearchMovies' function with its description:

<p>api_dev_key = API developer key for throttling users based on quota. lat_long = Latitude and longitude to filter movies by. results_per_page = Number of results to return per page. sorting_order = Sorting order of the search results.</p> Signup and view all the answers

Which isolation level in SQL databases provides the highest level of protection against concurrency issues like dirty reads, non-repeatable reads, and phantom reads?

<p>Serializable (C)</p> Signup and view all the answers

Using 'MovieID' for database partitioning is generally a better approach than using 'ShowID' to distribute the load evenly across servers, especially for popular movies.

<p>False (B)</p> Signup and view all the answers

In the context of handling reservation expirations, what is the purpose of adding a buffer (e.g., five seconds) on the server-side timer?

<p>To safeguard against client-server time desynchronization</p> Signup and view all the answers

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.

<p>oldest</p> Signup and view all the answers

Match the component with its primary responsibility in the detailed component design of a movie ticket booking system:

<p>ActiveReservationsService = Keeps track of active reservations and removes expired reservations. WaitingUsersService = Manages waiting user requests and notifies users when seats become available. Web Servers = Manages user sessions and handles communication with users. Application Servers = Handles ticket management, data storage, and interacts with cache servers.</p> Signup and view all the answers

What is the primary function of the ActiveReservationService in a movie ticket booking system?

<p>To keep track of all active reservations and remove any expired ones. (A)</p> Signup and view all the answers

The WaitingUserService uses a Last-In-First-Out (LIFO) approach to manage waiting users, ensuring the most recent requests are served first.

<p>False (B)</p> Signup and view all the answers

What communication technique can clients use to stay updated on their reservation status from the WaitingUserService, particularly when waiting for seats to become available?

<p>Long polling</p> Signup and view all the answers

To handle concurrency and prevent two users from booking the same seat, SQL databases use ______ to lock rows before updating them.

<p>transactions</p> Signup and view all the answers

Match the potential outcome with its corresponding waiting page scenario:

<p>Required seats become available = User is taken to the theater map page to choose seats. All seats get booked = User is shown an error message. User cancels waiting = User is taken back to the movie search page. User waits for more than one hour = User's session expires, and the user is taken back to the movie search page.</p> Signup and view all the answers

What is the primary purpose of partitioning the ActiveReservationService and WaitingUserService based on 'ShowID' using Consistent Hashing?

<p>To ensure all reservations and waiting users of a show are handled by a specific set of servers. (C)</p> Signup and view all the answers

When the ActiveReservationsService crashes, the active reservations data cannot be recovered unless there is a master-slave configuration in place.

<p>False (B)</p> Signup and view all the answers

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?

<p>The servers holding waiting users of that show</p> Signup and view all the answers

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.

<p>booked(2)</p> Signup and view all the answers

Match each step in the ticket booking workflow with its potential outcome if seats cannot be reserved:

<p>Show is full = User is shown the error message. Seats are no longer available, but other seats are available = User is taken back to the theater map to choose different seats. No seats are available to reserve, but all seats are not booked yet = User is taken to a waiting page. User cancels the waiting = User is taken back to the movie search page.</p> Signup and view all the answers

Which of the following is NOT a typical parameter for the SearchMovies API?

<p>user_id (A)</p> Signup and view all the answers

The ReserveSeats API returns a detailed seating map to the user, indicating which seats are available and which are already reserved.

<p>False (B)</p> Signup and view all the answers

What type of data structure is recommended for storing every reservation for every show in the ActiveReservationsService, where the key is 'ShowID'?

<p>HashTable</p> Signup and view all the answers

The ActiveReservationsService interacts with an external ______ service to process user payments.

<p>financial</p> Signup and view all the answers

Match each term related to database transaction isolation levels with its definition:

<p>Dirty Reads = Reading data that has been modified but not yet committed. Non-repeatable Reads = Reading different values for the same row within a single transaction. Phantom Reads = Seeing new rows appear in a query during a transaction. Serializable = Highest isolation level ensuring safety from dirty, non-repeatable, and phantom reads.</p> Signup and view all the answers

Which strategy is employed to allocate application servers for both the ActiveReservationService and WaitingUserService based upon the 'ShowID'?

<p>Consistent Hashing (B)</p> Signup and view all the answers

When WaitingUsersService crashes, the waiting users data can be easily recovered from the database as long as their requests were persisted.

<p>False (B)</p> Signup and view all the answers

In the provided SQL code snippet for handling concurrency, what is the purpose of SET TRANSACTION ISOLATION LEVEL SERIALIZABLE?

<p>To guarantee safety from concurrency issues</p> Signup and view all the answers

In addition to keeping data in the database, the ActiveReservationsService also keeps all reservations of a 'show' in ______ in a data structure.

<p>memory</p> Signup and view all the answers

Match each API parameter for the ReserveSeats function with its description:

<p>api_dev_key = API developer key for throttling users based on quota. session_id = User's session ID to track this reservation. movie_id = Movie to reserve. seats_to_reserve = An array containing seat IDs to reserve.</p> Signup and view all the answers

What is the significance of the Consistent Hashing scheme allocating three servers for any Show for load balancing in the ActiveReservationService and WaitingUserService?

<p>It allows efficient distribution of the workload for that Show across multiple servers. (A)</p> Signup and view all the answers

Using Long Polling, the server immediately notifies the client as soon as seats are available, regardless of whether the client has an active request.

<p>False (B)</p> Signup and view all the answers

What is the potential consequence of partitioning the database by 'MovieID' when there is a highly popular movie?

<p>It could cause a lot of load on that server</p> Signup and view all the answers

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.

<p>write</p> Signup and view all the answers

Match the step taken by a server holding a reservation that has expired, with its purpose:

<p>Update database = Remove the Booking (or mark it expired) and update the seats' Status in ‘Show_Seats’ table. Remove reservation from Linked HashMap = Release the memory held by the reservation. Notify the user = Inform the user that their reservation has expired. Broadcast a message = Inform all WaitingUserService servers to find the longest waiting user of that show.</p> Signup and view all the answers

After a successful reservation, what action is taken by the server holding that reservation to optimize seat allocation for waiting users?

<p>It sends a message to all servers holding the waiting users of that Show, so that those servers can expire all the waiting users that need more seats than the available seats. (B)</p> Signup and view all the answers

According to design considerations, the ticket-booking system handles partial ticket orders, allowing users to book whatever number of seats are currently available.

<p>False (B)</p> Signup and view all the answers

In the context of the SearchMovies API, what does setting includeSpellcheck to 'yes' achieve?

<p>Includes spell check suggestions in the response</p> Signup and view all the answers

When a reservation expires, the system updates the Status to ______ in the ‘Booking’ table.

<p>expired(3)</p> Signup and view all the answers

Match each status returned by the function ReserveSeats with its description:

<p>“Reservation Successful” = Indicates the seats were successfully reserved, and the user can proceed to payment. “Reservation Failed - Show Full” = Indicates that all seats for the selected show have already been reserved, and no more bookings are possible. “Reservation Failed - Retry, as other users are holding reserved seats” = Indicates that the reservation failed because some seats are temporarily held by other users, and the user should retry.</p> Signup and view all the answers

What is the potential risk of partitioning the database by MovieID in a high-demand online ticket booking system?

<p>It may result in uneven load distribution, potentially overloading servers during popular movie releases. (B)</p> Signup and view all the answers

Using Dirty transaction isolation level in SQL guarantees safety from Nonrepeatable and Phantoms reads.

<p>False (B)</p> Signup and view all the answers

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?

<p>Atomicity</p> Signup and view all the answers

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 ______.

<p>server</p> Signup and view all the answers

Match each component with its primary responsibility in handling ticket reservations.

<p>Web Servers = Manage user sessions and communication with the users Application Servers = Handle ticket management, data storage in databases, and work with cache servers to process reservations ActiveReservationService = Keep track of all active reservations and remove any expired reservation from the system WaitingUserService = Keep track of all the waiting user requests and notify the user when the required number of seats become available</p> Signup and view all the answers

Flashcards

Online Movie Ticket Booking System

A system that allows customers to purchase movie tickets online.

Functional Requirement #1

Lists cities with affiliate cinemas.

Functional Requirement #2

Displays movies released in a selected city.

Functional Requirement #3

Shows cinemas running a selected movie and show times.

Signup and view all the flashcards

Functional Requirement #4

Allows users to choose a show and book tickets.

Signup and view all the flashcards

Functional Requirement #5 & 6

Displays seating arrangement, distinguishing available from booked seats.

Signup and view all the flashcards

Functional Requirement #7

Allows a temporary lock on seats before payment.

Signup and view all the flashcards

Functional Requirement #8

Allows users to wait for seats that might become available.

Signup and view all the flashcards

Functional Requirement #9

Services waiting customers fairly (first-come, first-serve).

Signup and view all the flashcards

Non-Functional Requirement #1

Handles multiple booking requests for the same seat gracefully and fairly.

Signup and view all the flashcards

Non-Functional Requirement #2

Ensures security and ACID compliance for financial transactions.

Signup and view all the flashcards

Design Consideration #2

All tickets must be available, no partial orders.

Signup and view all the flashcards

Design Consideration #3

Fairness is mandatory for the system.

Signup and view all the flashcards

Design Consideration #4

Restricting users from booking more than ten seats at a time.

Signup and view all the flashcards

Design Consideration #5

The system should be scalable and highly available.

Signup and view all the flashcards

api_dev_key

API developer key for registered accounts, used for throttling.

Signup and view all the flashcards

keyword

Keyword to search on.

Signup and view all the flashcards

city

City to filter movies by.

Signup and view all the flashcards

lat_long

Latitude and longitude to filter by.

Signup and view all the flashcards

radius

Radius of the area in which we want to search for events.

Signup and view all the flashcards

start_datetime

Filter movies with a starting datetime.

Signup and view all the flashcards

end_datetime

Filter movies with an ending datetime.

Signup and view all the flashcards

postal_code

Filter movies by postal code / zipcode.

Signup and view all the flashcards

includeSpellcheck

Yes, to include spell check suggestions in the response.

Signup and view all the flashcards

results_per_page

Number of results to return per page; maximum is 30.

Signup and view all the flashcards

sorting_order

Sorting order of the search result.

Signup and view all the flashcards

session_id

User’s session ID to track this reservation.

Signup and view all the flashcards

movie_id

Movie to reserve.

Signup and view all the flashcards

show_id

Show to reserve.

Signup and view all the flashcards

seats_to_reserve[]

An array containing seat IDs to reserve.

Signup and view all the flashcards

City-Cinema Relationship

Each City can have multiple Cinemas.

Signup and view all the flashcards

Cinema-Hall Relationship

Each Cinema will have multiple halls.

Signup and view all the flashcards

Movie-Show Relationship

Each Movie will have many Shows.

Signup and view all the flashcards

Show-Booking Relationship

Each Show will have multiple Bookings.

Signup and view all the flashcards

User-Booking Relationship

A user can have multiple bookings.

Signup and view all the flashcards

ActiveReservationsService

Keeps track of active reservations and removes expired ones.

Signup and view all the flashcards

WaitingUsersService

Keeps track of waiting user requests, notifies when seats become available.

Signup and view all the flashcards

Linked HashMap

A data structure that allows jumping to any reservation to remove it when booking is complete, maintains order.

Signup and view all the flashcards

ActiveReservationsService Task

Removes expired reservations and processes payments.

Signup and view all the flashcards

Serializable Isolation Level

In SQL, guarantees safety from Dirty, Nonrepeatable, and Phantoms reads.

Signup and view all the flashcards

Within a transaction

We read rows, we get a write lock on them so that they can’t be updated by anyone else

Signup and view all the flashcards

Recovering ActiveReservationsService

Reading active reservations from the Booking table after a crash.

Signup and view all the flashcards

Master-Slave Configuration

A backup setup to take over when the main server fails.

Signup and view all the flashcards

Database Partitioning

Distributing database load across multiple servers, based on ShowID.

Signup and view all the flashcards

Consistent Hashing

Allocates application servers based on ShowID for load balancing.

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.

Quiz Team
Use Quizgecko on...
Browser
Browser