Design Ticketmaster with Score: 8/10
by alchemy1135
System requirements
Functional:
- User Registration and Login:
- Users should be able to create an account and log in to the platform.
- Browse Movies and Shows:
- Users should be able to browse through a list of movies and showtimes.
- Users should be able to view details about each movie, such as the plot summary, cast, genre, and trailer.
- Ticket booking:
- Users should be able to list different cities where its affiliate cinemas are located.
- Once the user selects the city, the service should display the movies released in that particular city.
- Once the user selects a movie, the service should display the cinemas running that movie and its available show times.
- The user should be able to choose a show at a particular cinema and book their tickets.
- The service should be able to show the user the seating arrangement of the cinema hall. The user should be able to select multiple seats according to their preference.
- The user should be able to distinguish available seats from booked ones.
- Booking information:
- Users should receive a confirmation of their booking via email or SMS.
- Users should be able to re-generate their confirmation booking and get it sent via email after booking.
- Order Management:
- Admins should be able to view and manage all ticket bookings.
- Admins should be able to track payments, issue refunds, or cancel bookings.
- Admins should be able to add new movies, show timings, etc.
- Reviews and Ratings:
- Users should be able to rate and review movies they have watched.
- Other users should be able to view these ratings and reviews to make informed decisions.
Non-Functional:
- Performance:
- The system should handle a high volume of simultaneous user requests during peak hours without significant performance degradation.
- Web pages should load within 3 seconds to ensure a responsive user experience.
- Scalability:
- The system should be scalable to accommodate an increasing number of users, movies, and cinemas without a significant decrease in performance.
- The architecture should support horizontal scaling to add more servers or resources as the user base grows.
- Reliability:
- The platform should have a high level of reliability, with an uptime of at least 99.9%.
- Implement regular backups to prevent data loss in case of system failures.
- Security:
- User data, including personal information and payment details, must be encrypted during transmission (SSL/TLS).
- Availability:
- Ensure 24/7 availability of the platform, with minimal scheduled downtime for maintenance.
- Use load balancing and failover mechanisms to distribute traffic and prevent single points of failure.
- Data Integrity:
- Implement data validation and integrity checks to prevent errors and inconsistencies in the database.
- Transactions, especially those related to bookings and payments, should be ACID-compliant.
- Auditability:
- Maintain detailed logs of user activities, system events, and errors for auditing and troubleshooting purposes.
- Logs should be securely stored and accessible only to authorized personnel
Capacity estimation
Assumptions:
- Let us assume 100,000 daily active users
- Peak Hours: during peak hours, there could be a 3x increase in traffic compared to the average.
- 10,000 events (globally) are listed on the website at any given time.
Estimations
- Concurrent Users: Assuming 20% of the DAU are active concurrently, we can estimate around 20,000 concurrent users during peak hours.
- Transactions per Hour: With 20,000 concurrent users making 2 transactions each, the platform needs to handle around 40,000 transactions per hour during peak hours.
- Tickets per Transaction: Assuming an average of 2 tickets per transaction, the platform needs to handle around 80,000 ticket bookings per hour during peak hours.
Storage Estimations: Here are some simple storage calculations
User Data: Considering we have 1,00,000 users, we grow by 40% per year, each user record is 100KB. So, at the end of 5 years, we will have 1.1M users
Storage Required = 1.1M * 100KB = 1100000 * 100 KB = 110 GB
Media Storage: let’s assume, we have 500 unique events per month that have media video file and each file is 25MB file.
Storage Required = 500 * 12 months * 5 years * 25 MB = 750 GB
API design
API Design
- get_list_of_cities:
- Description: Retrieve a list of cities where the platform's affiliate cinemas are located.
- Input: None
- Output: List of cities with their respective IDs.
- get_list_of_events_by_city:
- Description: Retrieve a list of events (movies or shows) available in a specific city.
- Input: CityId - ID of the city for which events are to be retrieved.
- Output: List of events with their details.
- get_locations_by_city:
- Description: Retrieve the locations (cinemas) within a specified city.
- Input: CityId - ID of the city for which locations are to be retrieved.
- Output: List of locations with their details.
- get_locations_by_event_and_city:
- Description: Retrieve the locations where a specific event is being screened in a given city.
- Input: CityId - ID of the city, EventId - ID of the event.
- Output: List of locations with their details.
- get_events_by_location_and_city:
- Description: Retrieve the events scheduled at a particular location within a specific city.
- Input: CityId - ID of the city, LocationId - ID of the location.
- Output: List of events with their details.
- get_show_timing:
- Description: Retrieve the show timings for a specific event at a particular location.
- Input: EventId - ID of the event, LocationId - ID of the location.
- Output: List of show timings with details.
- get_available_seats:
- Description: Retrieve the available seats for a specific event, location, and showtime.
- Input: EventId - ID of the event, LocationId - ID of the location, ShowtimeId - ID of the show timing.
- Output: List of available seats with their status.
- verify_user_selected_seats_available:
- Description: Verify if the user-selected seats are still available for booking.
- Input: EventId - ID of the event, LocationId - ID of the location, ShowtimeId - ID of the show timing, Seats - List of selected seat IDs.
- Output: Confirmation of seat availability.
- block_user_selected_seats:
- Description: Temporarily block the user-selected seats to prevent others from booking them.
- Input: EventId, LocationId, ShowtimeId, Seats.
- Output: Success/Failure status.
- book_user_selected_seat:
- Description: Confirm the booking of the user-selected seats.
- Input: EventId, LocationId, ShowtimeId, Seats, User Information.
- Output: Booking confirmation details.
- get_timeout_for_user_selected_seats:
- Description: Retrieve the timeout duration for the user-selected seats to complete the booking process.
- Input: EventId, LocationId, ShowtimeId, Seats.
- Output: Timeout duration in seconds.
Database design
For the tables required in this design, refer to the class diagram, the list of classes is not exhaustive but this is a good number of tables to start with.
Database Choices
- Relational Database for User, Booking, and Payment Data:
- Reasoning: User data and booking information require strong consistency and relational structure to maintain data integrity and enforce ACID properties.
- Database Type: Relational Database (e.g., PostgreSQL, MySQL).
- CAP Theorem Focus: Consistency is prioritized to ensure accurate and reliable user information and booking details.
- NoSQL Database for Event, Location, Reviews, and Comments Data:
- Reasoning: Event details and location information may vary and evolve, requiring a flexible schema and scalability, making NoSQL databases suitable.
- Database Type: NoSQL Database (e.g., MongoDB, Cassandra).
- CAP Theorem Focus: Partition tolerance and availability are crucial to handle potential changes in data structure and support scalable operations.
- Document Store for Search Data:
- Reasoning: Search data benefits from a document-oriented storage approach, enabling fast and efficient retrieval of movie and event-related information.
- Database Type: Document Store (e.g., Elasticsearch).
- CAP Theorem Focus: Availability is emphasized for quick and responsive search capabilities.
- Media Database for Media Files:
- Reasoning: Multimedia files, such as movie trailers, require efficient storage and retrieval, making media databases suitable for this purpose.
- Database Type: Media Database (e.g., Amazon S3, MongoDB with GridFS).
- CAP Theorem Focus: Emphasis on Availability and Partition Tolerance to ensure media files are accessible and retrievable.
- Key-Value Store for Metadata and Quick Lookups of popular events:
- Reasoning: Metadata and quick lookups can benefit from a key-value store for simplicity and fast access to specific information.
- Database Type: Key-Value Store (e.g., Redis).
- CAP Theorem Focus: Emphasis on Availability and quick lookups, while still maintaining Partition Tolerance.
Data Partitioning Strategy:
- Best Strategy: Hash-Based Partitioning.
- Reasoning: Hash-based partitioning ensures even distribution of data and avoids hotspots, which is essential for a system dealing with various entities like users, events, and bookings. It provides a balanced approach to data distribution across partitions.
Regional or Geographical Partitioning:
- Applicability: Consider regional or geographical partitioning for tables that have location-based data, such as Events or Locations.
- Reasoning: Regional partitioning can enhance performance by allowing the system to focus on a specific geographical region when serving requests related to events, locations, or cinemas. This is especially useful for platforms that have a global presence.
Partitioning Adjustments:
- Applicability: Required as specific tables grow disproportionately.
- Reasoning: Periodically reassess the partitioning strategy, especially for tables like Bookings or Events, and adjust as needed to maintain optimal data distribution and prevent hotspots.
Sharding Strategy:
- Best Strategy: Range-Based Sharding for Events or Bookings, Hash-Based Sharding for Users or Reviews.
- Reasoning:
- Range-Based Sharding: Suitable for tables where data can be logically grouped, such as Events based on date ranges or Bookings based on booking IDs.
- Hash-Based Sharding: Ideal for tables where uniform distribution of data is crucial, preventing hotspots. For example, Users or Reviews tables can benefit from hash-based sharding.
Scaling Strategy
- Horizontal Scaling:
- Applicability: Essential as the system grows and experiences increased demand.
- Reasoning: With a large user base and varying levels of activity, horizontal scaling by adding more database nodes or servers helps distribute the load and handle increased concurrency effectively.
- Read/Write Separation:
- Applicability: Suitable when there is a clear distinction between read and write workloads.
- Reasoning: By directing read operations to read replicas and write operations to the primary database, the system can efficiently handle more concurrent users and improve overall responsiveness.
High-level design
- User Interface (UI):
- Components:
- Home Page
- Movie/Event Listings
- User Authentication & Registration
- Booking and Payment Interface
- User Profile Management
- Application Layer:
- Components:
- Ticketing Service:
- Manages ticket booking, availability, and seat selection.
- Event Service:
- Handles event details, trailers, and metadata.
- User Service:
- Manages user profiles, authentication, and reviews.
- Location Service:
- Handles cinema locations and city details.
- Booking Engine:
- Components:
- Real-time Booking System
- Seat Selection and Availability Management
- Integration with Payment Gateway
- Database Layer:
- Databases:
- Relational Database (Users, Bookings, Payment Information)
- NoSQL Database (Events, Locations, Reviews)
- Document Store (Search Data, Metadata)
- Media Database (Trailers, Media Files)
- Backend Services:
- Components:
- Event Scheduler: Manages show timings and schedules.
- Review Aggregator: Aggregates and displays user reviews.
- Notification Service: Sends confirmations, reminders, and updates.
- External Integrations:
- Components:
- Payment Gateway Integration
- Cinema Partner APIs (for real-time seat availability)
- User Authentication (OAuth, JWT)
- Infrastructure and Scalability:
- Components:
- Load Balancers for distributing traffic
- Caching (Redis/Memcached) for frequently accessed data
- Horizontal Scaling with Clusters for databases
- CDN for media files and trailers
- Monitoring and Analytics:
- Components:
- Logging and Monitoring Tools (e.g., ELK Stack)
- Analytics Dashboard for User Behavior
- Performance Metrics for Scalability Assessment
- Security:
- Components:
- SSL/TLS for secure data transmission
- User Authentication and Authorization Mechanisms
- Regular Security Audits and Vulnerability Assessments
- Message Queue (e.g., Kafka):
- Facilitates asynchronous event processing.
- Allows decoupling of services, enabling scalability and fault tolerance.
- Scheduler Service:
- Manages scheduled jobs, such as updating show timings or sending notifications.
- Integrates with the message queue for event-driven processing.
- Search Engine (e.g., Elasticsearch):
- Indexes and provides efficient searching for events, locations, and metadata.
- Supports fast and relevant search results for users.
- Search API:
- Exposes an API for communication between the application layer and the search engine.
- Handles search queries and returns results to the user interface.
Request flows
Here is a simple sequence diagram that shows the sequence flow of a user booking a movie ticket.
Detailed component design
For the detailed component diagram, we will discuss the following important scenarios,
How do we handle the conflict when multiple users select the same seat while booking a ticket?
- Conflict Resolution Strategy:
- When multiple users attempt to book the same seat simultaneously, a reservation system can be implemented within the Ticketing Service.
- Use a transactional approach within the database to ensure atomicity. When a user initiates the seat selection process, mark the selected seats as temporarily reserved. If the transaction fails or times out, the seats are released, preventing conflicts.
- A reasonable timeout period could be in the range of a few minutes (e.g., 5-10 minutes).
- Consider the typical time it takes for users to select seats, enter payment information, and confirm the booking.
- During Peak hours this timeout can be reduced to prevent seat hoarding.
- Database Choice Impact:
- A relational database with support for transactions (ACID properties) is essential for this scenario.
- It allows for the atomic execution of operations, ensuring that either all seat reservations are successful or none, preventing inconsistencies.
How to handle cases where a user may exit the ticket booking process midway, particularly regarding seat reservations or session handling to maintain booking consistency
- Session Timeout and Seat Release:
- To handle scenarios where the user exits the process midway, we can implement session management with a defined timeout.
- If a user is inactive for a specified period during the booking process, the session expires, and any temporary seat reservations associated with that session are released.
- We can also implement a periodic garbage collection mechanism to identify and remove stale or expired sessions. This ensures that temporary seat reservations associated with inactive or incomplete sessions are released and do not persist indefinitely.
- Along with this, the Notification service can notify users about session expiration and seat release through in-app messages or email reminders to improve transparency and manage user expectations.
- Database Choice Impact:
- The relational database plays a crucial role in this scenario by storing session information, including temporary seat reservations, in a structured and transactional manner.
- Transactions ensure atomicity, allowing the system to roll back seat reservations if the user exits the booking process midway, maintaining the consistency of the data.
How the system would handle sudden spikes in traffic or ensure high availability during peak hours?
- Load Balancing: Implement load balancing across multiple servers to evenly distribute incoming traffic.Preventing any single server from becoming a bottleneck and ensuring optimal resource utilization.
- Horizontal Scaling and Auto-Scaling in Cloud Environment: Leverage auto-scaling features provided by cloud platforms to automatically adjust the number of server instances based on demand. Ensures that the system can dynamically scale up or down to handle varying levels of traffic, maximizing availability and minimizing costs during low-traffic periods.
- Read/Write Separation: Implement read/write separation by directing read operations to read replicas and write operations to the primary database. This enhances database performance by distributing read and write workloads, ensuring high availability and efficient resource utilization.
- CDN for Media Files: Use a Content Delivery Network (CDN) for storing and serving media files, such as movie trailers. This reduces latency by delivering media content from geographically distributed servers, ensuring faster loading times for users worldwide.
What are the Background services required and how will they work?
We will need multiple background services for this system, all these services will be scheduled using a Scheduling Service and a Queue (Apache Kafka). Multiple other services can also put messages in this queue to trigger a particular workflow inside these background service. Below are 2 such services.
- Review Aggregation:
- A dedicated Review Aggregator service can periodically fetch and aggregate user reviews from the Review Database.
- The service can use scheduled jobs or event-driven mechanisms to efficiently process and update the aggregated review scores for each movie.
- Notification Service:
- A Notification Service can be responsible for sending notifications to users, such as booking confirmations or reminders.
- It can subscribe to events from the Ticketing Service or Booking Engine, triggering notifications based on booking status changes.
- This service can also be triggered by the User when they want a copy of their booking or payment invoice emailed to them.
What happens when a payment fails for a user?
- Payment Failure Handling:
- If a payment fails during the booking process, the Booking Engine should initiate a rollback to cancel the booking transaction.
- The user should be notified about the payment failure, and the booked seats should be released for others to book.
- Database Choice Impact:
- The choice of a database supporting transactions is critical here. If the payment confirmation and seat booking are part of a single transaction, a failure in any step results in a rollback, maintaining consistency.
Trade-offs/Tech choices
- Simplicity in Current Design:
- Our current database design follows a straightforward approach using a relational database (SQL) for structured data like user information and bookings.
- This simplicity ensures ease of management and straightforward transactions, catering to the immediate requirements of the ticket booking system.
- Potential Hybrid Approach for Enhancement:
- As the platform evolves, a hybrid approach combining SQL and NoSQL databases could be considered for enhanced scalability and flexibility.
- SQL databases can handle transactional data, while NoSQL databases accommodate dynamic and unstructured data like event details and reviews, providing a balanced solution for future scalability.
Future improvements
- Introduce Caching Mechanism:
- Implement a distributed caching system to store frequently accessed data, enhancing response times and reducing database load, especially for static information like movie details and city locations.
- Implement Asynchronous Processing:
- Introduce message queues for asynchronous processing of tasks such as payment confirmations and notifications, improving system responsiveness and fault tolerance by decoupling time-consuming operations from user interactions.
- Enhance User Personalization:
- Integrate a recommendation engine that analyzes user preferences and behavior, providing personalized movie suggestions, thereby enriching the user experience and increasing engagement.
- Real-time Analytics Dashboard:
- Develop a real-time analytics dashboard to monitor user behavior, system performance, and booking trends, empowering administrators with valuable insights for data-driven decision-making and continuous system optimization.