Amazon: Design a Ticket Booking System
Design an event ticketing system where organizers publish events, many users search and browse, and bookings for the same seats never clash, even when a popular event's sales open.
Problem statement
This is Amazon's version of Design a Ticket Booking System, built from Amazon's interview reports.
Design an event ticketing system. Organizers create and manage events. Users search for events, open an event to see its details and free seats, book seats, and cancel bookings. Searching is far more common than booking, and a popular event can get a sudden rush when its sales open.
For this exercise, assume:
Organizers. An organizer creates an event as a draft with its name, description, images, category, venue and city, start time, seat list and one ticket price. Publishing the event makes it show up in search. Sales open at a time the organizer picks. After publishing, the organizer can still edit the name, description, images and category, but not the seats, price, venue or start time. Organizer changes should show in search and on the event page within about a minute.
Finding events. Users search upcoming events by city, category and date range, and can sort the results by popularity. Popularity is a score the system works out from recent page views and bookings. It may be up to an hour old. Most search and event page requests should answer within 200 ms.
Seats. Every seat in an event has a label, such as section, row and number. The event page lists which seats are free. That list may be a few seconds old, but booking must be exact: a seat is never held or sold to two people at once.
Booking. Users must be signed in to book. A user picks 1 to 6 free seats of one event. The system holds all of them for that user for 10 minutes, or none of them if any is already taken. The user pays within those 10 minutes to get a confirmed booking. Seats that are held but not paid for go back on sale within about a minute after the 10 minutes end.
Payment. Payment goes through an outside payment provider. A charge can succeed, be declined, or time out with no clear answer. Apps retry when a request times out. A user who was charged must end up with a confirmed booking, and a retry must never charge twice. Once a booking is confirmed, it must survive the crash of any single machine.
Cancelling. A user can cancel a confirmed booking before the event starts. Its seats go back on sale, and the payment provider is asked to refund the full amount.
Out of scope: refund rules such as deadlines or fees, changing an event's venue or start time, organizers cancelling events, more than one price per event, waiting lists for sold-out events, bot detection, and running in more than one region.
What to build
- Organizers can create an event with its details, seat list and price, publish it with a sales start time, and later edit its name, description, images and category.
- Users can search upcoming events by city, category and date range, sort them by popularity, and open an event to see its details and which seats are free.
- A signed-in user can hold 1 to 6 free seats of one event for 10 minutes, pay, and get a confirmed booking. A seat is never held or sold to two people at once, and a retry never charges twice.
- A user can cancel a confirmed booking before the event starts. Its seats go back on sale and a full refund is requested once.
At scale
- About 1 million upcoming events are listed at any time. At normal peak the site serves about 20,000 searches per second.
- Traffic is read-heavy: for about every 100 searches there are about 10 event page views and 1 booking attempt.
- When sales open for a popular event, it can get 100 times its normal traffic within a minute. Up to 100,000 users may try to book its 20,000 seats at once, sending up to about 5,000 hold requests per second, many for the same best seats.
- A payment call usually takes a few seconds, but it can time out after about 30 seconds with no answer.