Design an online ticket booking system
MicrosoftSoftware Engineer · Technical ScreenLast updated
This question tests the ability to design a distributed system that manages high-concurrency inventory, specifically focusing on consistency models, race condition prevention during seat selection, and reliable payment processing.
Design an Online Ticket Booking System
Design a scalable backend system for an online platform that allows users to browse events, select seats, and purchase tickets. The system must handle high traffic during popular event launches and ensure that no two users can book the same seat simultaneously.
Requirements
Functional Requirements:
- Users can view a list of events and see seat availability.
- Users can select seats and hold them for a limited time (e.g., 10 minutes) before purchasing.
- Users can complete a payment to confirm their ticket purchase.
- If the payment is not completed within the hold time, the seat is released back to the inventory.
Non-Functional Requirements:
- Consistency: Strong consistency is required for seat inventory; overbooking must be impossible.
- Scalability: The system must handle massive spikes in traffic during "on-sale" events (e.g., 100k requests per second).
- Availability: High availability for browsing; graceful degradation is acceptable during peak demand.
- Auditability: Every transaction must be logged to prevent fraud and reconcile inventory.
Deliverables
- High-level architecture diagram (described in text).
- API design for seat selection and booking.
- Database schema choices (SQL vs. NoSQL) and why.
- Strategy for handling concurrency during the booking flow.
Hints
Hint 1
Consider using a distributed locking mechanism or a database-level atomic operation to ensure only one user can claim a specific seat ID.
Hint 2
Decouple the booking process into a state machine: Available -> Held -> Confirmed/Expired.
Hint 3
For high-traffic events, consider using a message queue or a wait-room pattern to smooth out incoming request bursts before hitting your database.
Follow-up questions
- How would you handle a situation where the payment gateway service is slow or intermittent during a checkout process?
- How would you optimize the system for users querying the seat map to reduce load on the primary inventory database?
- If a user refreshes the page, how do you ensure their existing 'held' seat state is recovered correctly?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.