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.