Design a Distributed Hotel & Ticket Reservation System
Design a booking system for hotel rooms and flash-sale tickets that many people use at once, and that never sells the same room twice.
Think of hotel booking like reserving concert seats. When you click a seat, an egg timer starts for 10 minutes — that is a temporary lock. Nobody else can take the seat while you fill out your credit card details.
- Clients
- Guest
- Entry
- API gateway
- Services
- Booking service
- Inventory service
- Queues, caches
- Room holds
- Booking events
- Data, outside
- Bookings database
- Payment provider
1. Requirements and scope
- View available rooms for given date ranges.
- Reserve room with 10-minute payment hold.
- Process payment and confirm booking; auto-release room if payment times out.
- Zero overbooking guarantee (Strict Serializability / CP model).
- High availability for search browsing (AP model).
- Flash-sale resilience under 100,000 concurrent booking attempts.
2. Back-of-the-envelope numbers
- Writes: 20,000 booking attempts a second, at peak (29%)
- Reads: 50,000 searches a second (71%)
Balanced: reads and writes are close. Both paths need care, so neither can be slow.
3. API
4. Data model and storage
ROOM_INVENTORY: (room_type_id, date, total_inventory, reserved_count, version) PRIMARY KEY (room_type_id, date)
5. The design, in three versions
Version 1: Pessimistic Row Locking in Monolith
SQL SELECT FOR UPDATE locks room inventory row during booking transaction.
Distributed Hotel & Ticket Reservation System: Version 1: Pessimistic Row Locking in Monolith Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Services
3. Data, outside
The steps in words0 of 3 steps shown
Guest to Booking service
A guest books the last room for Friday.
Booking service to Bookings database
One transaction locks the room row, checks it is free, and books it.
Booking service to Guest
The guest gets the booking.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathBook a room
- Client
- Reservation service
- Inventory service
- Payment gateway
- Outbox
- Kafka
Client to Reservation service
The user asks to hold a double room for 3 nights. The request carries an idempotency key.
Reservation service to Inventory service
The service lowers the free count for each of the 3 nights in one transaction. The update succeeds only if every night still has a room.
Reservation service to Client
It returns a hold that lasts 10 minutes.
Reservation service to Payment gateway
The user pays. The service calls the payment provider with the same idempotency key.
Reservation service to Outbox
On success it marks the booking confirmed and writes an event row in the same transaction.
Outbox to Kafka
A relay publishes the event. Other services send the email and update search.
Read pathSearch for free rooms
- Client
- Search service
- Redis cache
- Read replica
Client to Search service
The user searches for a double room for 3 nights.
Search service to Redis cache
The service reads the cached free counts for those dates.
Search service to Read replica
On a cache miss, it reads a database replica and fills the cache with a short TTL.
Search service to Client
It returns the list. A count may be a few seconds old; the hold step does the real check.
What breaks, and what happens then
Two users try to book the last room
- What users see
- Both press "book" in the same second.
- What the design does
- The count update is conditional, so only one succeeds. The other user sees "no longer available".
Payment fails or the user leaves
- What users see
- A room stays held with nobody paying.
- What the design does
- The hold expires after 10 minutes, and a worker adds the room back to the free count.
The payment succeeds but the confirmation is lost
- What users see
- The user is charged, but no booking is shown.
- What the design does
- The retry carries the same idempotency key, so the charge is not repeated. A reconciler compares payments with bookings and fixes any gap.
A flash sale sends 100,000 attempts at once
- What users see
- The inventory database could be overwhelmed.
- What the design does
- Requests wait in a queue and are worked through at a steady rate. Sold-out dates are answered from the cache.
6. Deep dives
7. Follow-up questions
- How do you release held rooms if a user abandons checkout? (Answer: Redis key expiration notification or scheduled delay queue worker triggers inventory increment).
What it costs
Bookings are few, about one a second on average, so the database is small. The cost is search traffic and the short flash-sale peaks. Cache search results, and queue the peak so the database is not sized for it.
Another way to design it
For a flash sale, you can put every buyer in a queue and let a few through at a time. Stock is then never oversold, with no clever locking. Buyers wait in line, and they can see their place.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 1 reservation a second on average, spiking to 20,000 a second of booking attempts in a flash sale. It explains the 10-minute hold and goes deep on one part, such as double booking.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. Booking must never double-sell a room, but browsing availability can be a little stale. Can a hotel also block a room directly, say for maintenance, outside the guest booking flow? I will design search for speed and booking for correctness, treating a hotel's own block the same as a guest hold.
Guests search for a room, place a hold, and pay to confirm it. Once payment succeeds, the room is booked, so I will start on the reservation API and the inventory table.
Shows: Unclear questionsThe difference: The weak answer never asks whether a hotel can also block a room directly, such as for maintenance, which must respect the same no-double-booking guarantee.
Estimates
100,000 reservations a day is about 1 a second on average, so this is a light write load most of the time. The stated flash-sale peak of 20,000 a second is concurrent booking attempts for the same limited rooms, not confirmed bookings. So I will design for contention, not raw throughput.
The flash-sale peak of 20,000 a second means 20,000 confirmed bookings a second. So I will size the database to write that many successful reservations every second.
Shows: DepthThe difference: Most flash-sale attempts fail, since only a few rooms exist. 20,000 a second is concurrent attempts, not confirmed bookings, which the strong answer sizes for instead.
Core design
The API places a hold, then confirms it after payment. Inventory is a row per room type and date, holding a total and a reserved count. That way I can check one specific night, not one number for the whole room type.
I would keep one row per room type with a total rooms count and a reserved count, and check it before confirming a booking.
Shows: DepthThe difference: One row per room type cannot tell nights apart. It cannot track a stay from March 1 to 5 against a stay from March 3 to 7.
Deep dive
The hard part is two guests racing to book the last room. Reading the reserved count, checking it is under the total, then writing it back as two separate steps lets both holds pass. A single conditional update, raising the count only where it is still under the total, does the check and the write as one atomic step.
I would read the reserved count, check it is below the total rooms, and then write the new count back as a second step.
Shows: DepthThe difference: Two guests can both read the same count before either writes back, so both holds pass and the room is double-booked. One atomic update avoids that race.
Failures and trade-offs
If the confirm-booking call is retried after a timeout, a second confirm could double-charge the guest or create two bookings. An idempotency key tied to the hold stops that. I also expire an abandoned hold after 10 minutes, releasing the room back to inventory.
If the confirm call times out, I would retry it until it succeeds, so the guest is not stuck without a confirmed booking.
Shows: ScopeThe difference: Retrying without an idempotency key can create a second booking or charge. The strong answer ties the retry to the hold so a repeat is harmless.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design a Distributed Hotel & Ticket Reservation System Design a booking system for hotel rooms and flash-sale tickets that many people use at once, and that never sells the same room twice. What users must be able to do: - View available rooms for given date ranges. - Reserve room with 10-minute payment hold. - Process payment and confirm booking; auto-release room if payment times out. How well it must work: - Zero overbooking guarantee (Strict Serializability / CP model). - High availability for search browsing (AP model). - Flash-sale resilience under 100,000 concurrent booking attempts. Numbers to assume: - 5,000 hotels, 1 Million rooms total, 100,000 reservations made daily. Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 1 reservation a second on average, spiking to 20,000 a second of booking attempts in a flash sale. It explains the 10-minute hold and goes deep on one part, such as double booking. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]