Design a Hotel Reservation System
A hotel chain wants guests to search for rooms, see prices, and book, with one rule that must never break: two guests never get the same room for the same night. This lesson designs the reservation system around a simple inventory table of room types by date, updated with conditional writes, plus idempotent booking requests, short holds during payment, and a read-optimised search path.
What you will learn
- Book room types, not specific rooms: inventory is a count per hotel, room type and night.
- A multi-night stay reserves every night in one transaction, with a conditional update on each row.
- Every booking request carries an idempotency key, so a retried click never books twice.
- Hold inventory briefly during payment, with the expiry stored in the data, not in a timer.
- Search reads cached, slightly stale availability; the booking write is the only place that must be exact.
- Shard by hotel: every booking touches one hotel, so transactions stay on one database.
In this lesson
- The question
- Step 1: Clarify the requirements
- Step 2: Back-of-the-envelope estimates
- Step 3: The API
- Step 4: The data model
- Step 5: Booking without double bookings
- Step 6: Holds and payment
- Step 7: Idempotent requests
- Step 8: Overbooking
- Step 9: Prices for a stay
- Step 10: Search and caching
- Step 11: One booking, end to end
- Step 12: Scaling
- Step 13: Failures and cancellations
- Step 14: The parts people forget
- Step 15: The follow-up questions
- Recap
The question
Welcome to lesson twenty-four of the InterviewDryRun system design course. Today we design a hotel reservation system: guests search for rooms, compare prices, and book a stay, and the hotel never sells the same room twice for the same night.
It is a popular question because the scale is modest but the correctness bar is high. Most candidates can draw a search service and a database. Fewer can explain exactly how two guests trying to book the last room at the same moment are kept apart, or what happens when the payment succeeds and the confirmation request times out. Those details are the interview.
Max asks
“Design room search and booking for a hotel chain with no double bookings.”
That is how Max, our AI interviewer, asks it. Notice: a hotel chain, so thousands of hotels, not a global marketplace with millions of private listings. And no double bookings, which is the invariant everything else bends around. Repeat the invariant back to the interviewer in your own words before you draw anything.
The plan: requirements and numbers, then the API and the data model, with a key decision about rooms versus room types. Then concurrency: how a booking claims inventory safely. Then holds and payments, idempotency, overbooking, search and caching, scaling, a booking walked end to end, failures, and the follow-up questions.
Step 1: Clarify the requirements
- 01SearchCity or hotel, dates, guests; see available room types and prices
- 02BookChoose a room type, pay, get a confirmation
- 03ManageView, change or cancel a reservation
- 04Hotel staffSet prices, inventory, block rooms
- 05Check-inAssign an actual room on arrival
Start with questions.
Guests search by city or by a specific hotel, with check-in and check-out dates and the number of guests, and see which room types are available, with a price for the stay. Then they choose one, pay, and receive a confirmation.
Guests can view, change and cancel reservations, under the hotel's cancellation policy. Hotel staff set prices per room type and date, and can take rooms out of service for repairs.
Ask one important question: does the guest book a specific room, room four-twelve, or a room type, a deluxe king? For hotels, the answer is almost always a room type. The actual room is assigned at check-in. That one answer simplifies the whole design, and we will see why in the data model.
- 01No double bookingsNever sell more rooms than exist, beyond policy
- 02Consistent bookingsStrong consistency on the booking path
- 03Fast searchUnder a few hundred milliseconds
- 04AvailableSearch should stay up even if booking is degraded
- 05Modest scaleThousands of hotels, not billions of events
The qualities.
Correctness of bookings comes first: never sell more rooms of a type, on a night, than the hotel has, plus any overbooking the hotel allows on purpose. That needs strong consistency on the booking path. Search, on the other hand, can show availability that is a few seconds old, because the booking step re-checks anyway.
So we already have a split: a read path that is large, fast, and allowed to be slightly stale, and a write path that is small, careful and exact. State that split, and the rest of the answer follows from it.
Step 2: Back-of-the-envelope estimates
Let us size it.
Say five thousand hotels with two hundred rooms each, one million rooms in total. If occupancy is seventy percent and the average stay is three nights, about two hundred and thirty thousand new bookings a day, round it to a quarter of a million.
A quarter of a million bookings a day is about three a second on average, perhaps thirty a second at a busy peak, like a holiday sale. That is a small number for a relational database. Say it out loud, because it gives you permission to use transactions freely on the booking path.
Searches are far more frequent. People look at many dates and hotels before booking, so a ratio of a hundred or more searches per booking is common, giving around a thousand searches a second, with bursts during sales. So reads outnumber writes by orders of magnitude, which points at caching and read replicas for search.
And the inventory data is small. One row per hotel, room type and night, for, say, ten room types and two years ahead, is five thousand times ten times seven hundred and thirty, about thirty-six million rows. That fits on one database comfortably, though we will still shard by hotel for isolation and growth.
Step 3: The API
GET /v1/search?city=…&checkIn=2026-12-20&checkOut=2026-12-23&guests=2
→ [ { hotelId, roomTypeId, nightlyPrices, total, left: "3" } ]
POST /v1/reservations Idempotency-Key: 9f2c…
{ hotelId, roomTypeId, checkIn, checkOut, guests }
→ { reservationId, status: HELD, holdExpiresAt, total }
POST /v1/reservations/{id}/confirm { paymentToken } → CONFIRMED
POST /v1/reservations/{id}/cancel → CANCELLEDThe API has a search side and a booking side.
Search takes a location or hotel, dates and the number of guests, and returns available room types with prices for the stay. Sometimes it shows only three left, which is useful for the guest and cheap for us, because we already have the count.
Booking is two steps. The first creates a reservation in a held state, which reserves the inventory for a few minutes while the guest pays. The second confirms it with a payment token. Splitting it this way keeps a slow payment from holding a database transaction open, and it means a guest never pays for a room that has just gone.
Notice the idempotency key header on the create call. The client generates a unique key when the guest presses book, and sends the same key if it retries. We will come back to why that header is the most important line in this API.
Step 4: The data model
| Table | Key | Columns |
|---|---|---|
| hotel | hotelId | name, city, policies, time zone |
| room_type | hotelId, roomTypeId | name, capacity, total rooms |
| room_type_inventory | hotelId, roomTypeId, date | total, reserved, version |
| rate | hotelId, roomTypeId, date | price, currency, rules |
| reservation | reservationId | guest, dates, type, status, total, idempotency key |
Here is the decision from the requirements. Because guests book room types, we do not need to track which physical room is free on which night. We only need counts.
Hotels and room types are slowly changing reference data. A room type says, for example, deluxe king, sleeps two, forty rooms in this hotel.
The heart of the model is the room type inventory table: one row per hotel, room type and night, with the total rooms available that night and the number already reserved. Total can differ from the room type's count when rooms are out of service. Availability for a night is simply total minus reserved.
Rates are kept per night, because prices change by date, and reservations record the guest, dates, room type, status and the price agreed at booking time. Keep the agreed price on the reservation: if the rate changes tomorrow, this guest's price must not.
Why is this model so good? Because checking availability for a three-night stay is reading three rows, and booking it is updating three rows. Compare tracking individual rooms: you would have to find one specific room free on all three nights, which is a harder search, and room swaps at the desk would ripple through the data. Counts per room type are simpler, and they match how hotels actually sell. Interviewers tend to reward candidates who notice that the real-world rule simplifies the data.
Step 5: Booking without double bookings
| Approach | How | Trade-off |
|---|---|---|
| Pessimistic lock | SELECT … FOR UPDATE, then update | simple; holds locks, can deadlock |
| Optimistic version | update where version = v | no locks; retries under contention |
| Conditional update | update where reserved + n <= total | one statement; the usual answer |
| Database constraint | CHECK (reserved <= total) | a final safety net |
Now the core. Two guests try to book the last deluxe king for the twentieth of December at the same moment. Both searched and saw one left. Only one may succeed.
Option one is pessimistic locking: read the inventory rows with a lock, check availability, update, commit. It is correct, but locks are held while the application thinks, and two transactions locking nights in different orders can deadlock. Lock rows in date order if you choose this.
Option two is optimistic: read the row with its version number, then update it only if the version is still the same. If someone else changed it, retry. It works well when conflicts are rare, which they are for most hotels on most nights.
Option three, the one I would choose, is a conditional update that expresses the invariant directly: add one to reserved, only where reserved plus one is still at most total. The database checks and updates in one atomic step. If the update changes zero rows, the room type is sold out for that night.
And as a safety net, put a check constraint on the table, reserved never more than total, so even a bug in the application cannot oversell. Defence in depth for the one invariant that matters.
BEGIN
for night in [Dec 20, Dec 21, Dec 22]:
UPDATE room_type_inventory
SET reserved = reserved + 1
WHERE hotel = 7 AND room_type = 'DK' AND date = night
AND reserved + 1 <= total * overbook_factor
if rows_changed == 0: ROLLBACK → 'sold out'
INSERT reservation (…, status = HELD, hold_expires = now + 10 min)
COMMITA stay has several nights, so the booking must succeed for all of them or none. Do the conditional updates for each night inside one transaction, in date order. If any night returns zero rows changed, roll back the whole transaction and tell the guest that the dates are no longer available.
Because every row touched belongs to one hotel, this is a transaction on a single database, which is fast and simple. That is the reason we will shard by hotel later: it keeps every booking inside one shard, with no distributed transactions.
Step 6: Holds and payment
- 01HoldInventory reserved, reservation HELD, expires in 10 min
- 02PayPayment authorised with the provider, outside the transaction
- 03ConfirmHELD → CONFIRMED only if not expired
- 04ExpireSweeper releases expired holds; inventory back
Why a held state? Because payment is slow and can fail. A guest takes a minute to type card details, and the payment provider may take seconds more. We cannot keep a database transaction open for that long.
So the first step reserves the inventory in a short transaction and records the reservation as held, with an expiry time ten minutes ahead. The guest now has the room for ten minutes, and nobody else can take it.
The guest pays. The payment service authorises the card, outside any database transaction. Then confirm: one conditional update moves the reservation from held to confirmed, only if it is still held and the hold has not expired. If it expired in the meantime, the confirmation fails and the payment authorisation is released, so the guest is never charged for a room they did not get.
Holds that expire must give their inventory back. A sweeper runs every minute, finds held reservations whose expiry has passed, and for each one, in a transaction, marks it expired and subtracts one from reserved for each night. The expiry is a column in the data, not a timer in a process, so a crashed server never strands a room. Same idea as seat holds in the ticket booking lesson.
One subtle point: the sweeper and a late confirmation can race. Both use conditional updates on the reservation status, held to expired versus held to confirmed, so exactly one of them wins, and the loser does nothing. Every state change in this system is a conditional update on the expected current state. Saying that sentence once, clearly, covers a whole class of follow-up questions.
Step 7: Idempotent requests
POST /v1/reservations Idempotency-Key: 9f2c… reservation.idempotency_key UNIQUE on request: existing = find reservation by key if existing: return existing // same answer, no new hold else: hold inventory + insert, in one transaction
Now the most common real-world bug in booking systems. The guest presses book. The request reaches our server, the room is held, but the response is lost because the phone's connection dropped. The app retries. Without care, the retry holds a second room, and the guest is charged twice.
The fix is the idempotency key. The client generates a unique key when the guest starts the booking and sends it with every attempt. We store it on the reservation with a unique constraint.
When a request arrives, we look up the key. If a reservation already exists with it, we return that reservation, unchanged. If not, we hold inventory and insert the reservation in the same transaction. If two copies of the request race, the unique constraint lets only one insert succeed; the other transaction rolls back, including its inventory update, and then returns the winner's reservation.
Use the same idea on the confirm call, and when talking to the payment provider: send the reservation id as the payment's idempotency key, so a retried payment request never charges twice. Every external call that changes money or inventory should be safe to repeat. Interviewers often ask, what if the client retries, and this is the complete answer.
Step 8: Overbooking
- 01WhyNo-shows and late cancellations leave rooms empty
- 02HowAllow reserved up to total × 1.05, per room type and night
- 03Who decidesRevenue managers, per hotel and season
- 04When it goes wrongWalk the guest: free room at a nearby hotel
A twist that impresses interviewers: real hotels overbook on purpose. A few percent of guests cancel late or never show up, so a hotel with a hundred rooms might accept a hundred and five bookings for a busy night.
In our model this is one number: an overbooking factor per hotel, room type and date, or a fixed number of extra rooms. The conditional update compares reserved with total times that factor. The invariant becomes: never exceed the allowed limit, which is still enforced atomically.
Revenue managers set the factor from history: how many no-shows does this hotel see on Saturdays in December? The system only enforces the limit. Mention that a pricing and forecasting team owns the number, and keep it out of the booking logic.
And when everyone does show up, the hotel walks a guest: it pays for a room at a nearby hotel. That is a business process, not a bug. It shows that no double bookings, in the real world, means no double bookings beyond what the hotel chose. Asking the interviewer whether overbooking is in scope shows real product sense.
Step 9: Prices for a stay
- 01Rate per nightWeekends, holidays and seasons differ
- 02Rate plansRefundable, non-refundable, breakfast included
- 03Total = sum of nightsPlus taxes and fees, shown up front
- 04Locked at holdThe reservation stores the agreed total
Before search, a word on prices, because a stay has a price per night, and those prices move.
Each room type has a rate for each night, set by the hotel's revenue team, often changing daily as demand changes. A three-night stay from Friday costs Friday's rate plus Saturday's plus Sunday's, which is why the rate table is keyed by night, just like inventory.
Hotels also sell the same room type under several rate plans: a cheaper non-refundable rate, a flexible rate that can be cancelled until the day before, a rate with breakfast. The plan does not change the inventory, only the price and the cancellation rules. So inventory stays one count per room type and night, and the plan is recorded on the reservation.
Show the full total, including taxes and fees, before the guest pays, and lock it at the moment of the hold by storing it on the reservation. Prices are read on the search path from the same cache as availability, so a price change reaches search within seconds, and the hold step reads the real rate from the database. If the two differ, the guest sees the new total before paying. Keeping inventory and price as separate tables, both keyed by night, keeps each simple, and lets the revenue team change prices without ever touching the counts that protect the invariant.
Step 10: Search and caching
Search is the read path, a thousand requests a second, and it can be a little stale.
A search for a city and dates first finds candidate hotels with a search index: hotels in that city, with the right amenities, sorted by relevance or distance. That index changes rarely and is easy to replicate.
For each candidate hotel, we need availability for each room type on each night of the stay. Reading that from the primary database a thousand times a second would load it for no reason. Instead, keep an availability cache keyed by hotel, room type and date, holding the count left and the price.
Keep the cache fresh from the database's change stream: every committed change to an inventory row publishes an event, and the cache updates within a second or so. A guest might see one left when it has just gone. That is acceptable, because the booking path checks the real database, and the guest gets a clear message if the room is gone.
This is the pattern to name: the search path is eventually consistent and cached, the booking path is strongly consistent and goes to the source of truth. It is the same split as in the ticket booking lesson, and as in most systems where many people look and few buy.
Step 11: One booking, end to end
| Time | Guest A | Guest B |
|---|---|---|
| 0 s | search: deluxe king, 1 left | search: deluxe king, 1 left |
| 40 s | press book, key k-A | |
| 40.05 s | 3 nights updated; HELD | press book, key k-B |
| 40.06 s | Dec 21 update changes 0 rows; rollback | |
| 40.07 s | 'sold out for these dates' | |
| 95 s | card authorised; CONFIRMED | picks another hotel |
Let us walk one booking through the whole system.
Two guests search the same hotel for the twentieth to the twenty-third of December. Both see one deluxe king left, from the cache. Both are telling the truth: there is one.
Guest A presses book, with idempotency key k-A. The booking service, on the shard that owns this hotel, starts a transaction, and updates the three inventory rows one after another, each only if reserved plus one is within the limit. All three succeed. It inserts the reservation, held, expiring in ten minutes, and commits.
Guest B's request arrives a few milliseconds later. Its transaction updates the first night, then waits on the row for the twenty-first, which A's transaction is changing. When A commits, B's update re-checks the condition, finds the night full, and changes zero rows. B's transaction rolls back, including the first night, and B sees that the room type is sold out for those dates.
A types card details. Fifty-five seconds later the payment is authorised, using the reservation id as the payment's idempotency key, and the reservation moves from held to confirmed. The confirmation email goes out from an event. The cache already shows zero left. No locks were held while anyone typed, and the invariant held throughout.
Step 12: Scaling
- 01Shard by hotelEvery booking stays on one shard
- 02Read replicas and cacheFor search and reservation views
- 03Hot hotelsA sale at one resort: queue bookings per hotel
- 04Archive old dataPast nights move to cheaper storage
This system is modest in scale, but let us show how it grows.
Shard the inventory and reservations by hotel id. Every booking touches one hotel, so every transaction stays on one shard. With five thousand hotels, a handful of shards is plenty, and adding hotels means adding shards. Do not shard by date: a stay crosses dates, and you would need distributed transactions.
Reads scale with replicas and the cache. Reservation lookups, my trips, read from replicas, with the reservation id telling us the shard.
What about a flash sale at one popular resort, with thousands of guests booking in the same minute? All of them contend for the same few rows. The database handles a few hundred conditional updates a second on one row, but if that is not enough, put a short queue in front of that hotel's bookings and process them one by one, telling guests they are in line. Most hotels will never need it; say it as the answer for the hot case.
And move past nights out of the hot tables. Inventory rows for dates that have passed are never booked again, so archive them to cheaper storage for reports, keeping the working set small.
Step 13: Failures and cancellations
- 01Response lostClient retries with the same key; same answer
- 02Payment succeeds, confirm failsRetry confirm; reconcile payments hourly
- 03Booking server crashes mid-holdTransaction rolled back, or hold expires
- 04Primary database failsSynchronous replica takes over
- 05CancellationRelease each night in one transaction; refund by policy
What breaks, and how the design copes.
A lost response is handled by the idempotency key, as we saw. If payment succeeds but the confirm step fails, the client retries confirm, which is idempotent. And a reconciliation job compares the payment provider's records with our reservations every hour: any payment without a confirmed reservation is either confirmed, if the hold is still valid, or refunded.
If a booking server crashes in the middle of a hold, the database rolls back the open transaction, so no inventory is lost. If it crashes after committing a hold but before replying, the guest retries with the same key and gets the hold back. Either way, the inventory is consistent.
Use synchronous replication for the booking database, so a confirmed reservation is never lost in a failover. And cancellation is the reverse of booking: in one transaction, move the reservation to cancelled and subtract one from reserved for each night, then refund according to the hotel's policy, using the reservation id as the refund's idempotency key.
Step 14: The parts people forget
- 01Hotel time zonesA night is the hotel's local date
- 02Changes to a stayAdd a night = hold the new night first
- 03Third-party channelsTravel sites sell the same inventory
- 04Audit trailEvery inventory change logged
A few points that turn a correct answer into a strong one.
Dates. A night belongs to the hotel's local calendar. Store dates as plain dates in the hotel's time zone, not as timestamps, or a guest in another country may book the wrong night.
Changes. Extending a stay by one night means holding the new night first, then updating the reservation. Changing room type means holding the new type before releasing the old one, in one transaction, so the guest never ends up with nothing.
Other channels. Hotels also sell through travel websites. Those channels must book through the same inventory, usually via an API with the same holds and idempotency keys, or the hotel will oversell. And keep an audit log of every inventory change, with who made it and why, because hotels will ask how the count for a night became what it is.
Step 15: The follow-up questions
Max asks
“What if guests must book a specific room, for example a room with a view?”
Then inventory moves to a per-room, per-night table, and holding a stay means finding one room free on every night, then reserving those rows. Keep the room type counts as well, for fast search. Most hotels handle special requests as preferences on a room type booking, assigned at check-in, so I would suggest modelling the view as its own room type, which keeps the simple count model.
Max asks
“Why not use a distributed lock service to protect the inventory?”
A lock service adds another system that can fail or time out, and a lock can expire while the holder still thinks it holds it. Here the data for one booking lives on one database, which already provides atomic conditional updates and transactions. Using the database's own guarantees is simpler and safer. I would reach for a distributed lock only if the data spanned several stores.
Max asks
“How would you handle a sudden spike of searches during a holiday sale?”
Search is read-only and cached, so it scales by adding search servers and cache replicas. Cache whole search results for popular city and date combinations for a few seconds. Rate limit abusive clients. If the cache falls behind, guests may see slightly stale counts, which is fine, because the booking path re-checks. The booking database is protected because only bookings, not searches, reach it.
Max asks
“How do you make sure prices don't change between search and payment?”
When the hold is created, compute the total from the rates at that moment and store it on the reservation. Payment charges that stored total, so a rate change during payment does not affect this guest. If the price changed between search and the hold, show the new price before the guest pays and ask them to confirm, which is a simple version check.
Recap
- 010 to 5: requirementsRoom types, not rooms; no double bookings
- 025 to 10: estimates30 bookings/s at peak; 1,000 searches/s
- 0310 to 20: API and modelInventory per hotel, type and night
- 0420 to 35: bookingConditional updates, holds, idempotency keys
- 0535 to 45: search and scaleCached reads, shard by hotel, failures
On the clock: five minutes on requirements, with the invariant never sell more than the allowed rooms, and the insight that guests book room types. Five minutes of numbers: few bookings, many searches.
Ten minutes on the API and the inventory table, one row per hotel, room type and night.
Fifteen minutes on booking: conditional updates in one transaction for all nights, holds with expiry in the data, idempotency keys and overbooking. And ten minutes on cached search, sharding by hotel and failures. If you explain why the booking path is exact and the search path is not, you will stand out.
Concurrency questions are much easier to answer when you have explained them out loud before. You can practice this exact question with Max, our AI interviewer, at interview dry run dot com. It is free to start, and you get a scored report with what to fix. The written lesson, with every diagram, is on the site too. See you in lesson twenty-five.
Now say it out loud
Watching an answer is not the same as giving one. Max asks this exact question, pushes back when an answer is vague and keeps time, then scores you per skill.
Practice with MaxFree: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.