System design interview: design a hotel reservation system
A hotel reservation system lets guests search for available rooms and book a stay without two people getting the last room. The core of the design is an inventory table holding, for each hotel, room type and night, how many rooms exist and how many are booked; a booking updates every night of the stay in one transaction with a condition that the count stays under the limit, and an idempotency key makes retries safe.
By Evin JohnPublished 7 min read
1. Clarify the requirements
Find out whether you are building a single hotel chain's system or a marketplace that lists other hotels. The rest of this page assumes a large chain that owns its inventory.
- Functional: search hotels by city and dates; see available room types and prices; book a stay for one or more nights; pay now or at the hotel; modify or cancel within the policy; hotel staff manage rates and inventory.
- Non-functional: never sell more rooms than allowed for any night; a booking request is safe to retry; search is fast and may be slightly stale; the booking path favours correctness over raw speed.
- Out of scope unless asked: dynamic pricing models, loyalty points, channel managers syncing other booking sites, reviews.
2. Estimate the scale
| Quantity | Assumption | Result |
|---|---|---|
| Hotels and rooms | 50,000 hotels, 5 million rooms | the inventory to manage |
| Bookings | 70% occupancy, average stay of 3 nights | about 1.2 million bookings a day, about 14 a second on average |
| Searches | about 30 availability checks per booking | about 400 a second on average, more at seasonal peaks |
| Inventory rows | 20 room types per hotel, bookable 2 years ahead | 50,000 x 20 x 730 = 730 million rows |
| Inventory storage | about 50 bytes per row | about 37 GB: modest for a relational database |
Fourteen bookings a second is tiny. You could serve the write path from one well-provisioned relational database with replicas; the read path (search) is where caching earns its place.
3. Define the API
GET /v1/availability?hotel_id=812&check_in=2027-03-04&check_out=2027-03-07&guests=2
-> { room_types: [ { room_type_id, name, nightly_rates: [...], available: true } ] }
POST /v1/reservations
Idempotency-Key: 9f2c4e1a-...
{ hotel_id, room_type_id, check_in, check_out, guests, rate_plan_id, payment_method }
-> 201 { reservation_id, status: "CONFIRMED", total: { amount, currency } }
DELETE /v1/reservations/{reservation_id} (cancel, applies the rate plan's policy)4. Sketch the data model
| Table | Key and fields | Notes |
|---|---|---|
| hotels, room_types | hotel and room type details | Mostly static; cached |
| room_type_inventory | (hotel_id, room_type_id, date) -> total_rooms, reserved | One row per night; the only rows the booking path contends on |
| rate_plans and rates | (hotel_id, room_type_id, date, plan) -> amount, currency, cancellation rule | Written by revenue staff |
| reservations | reservation_id, idempotency_key (unique), guest, hotel, room type, dates, status, total | Status: PENDING, CONFIRMED, CANCELLED |
| room_assignments | reservation_id -> room number | Filled at check-in, not at booking |
Keep inventory, rates and reservations in one relational database (sharded by hotel_id if it grows), so a booking is a local transaction. A stay never spans two hotels, so one hotel's rows always live together.
5. Booking without overselling
The race: two guests check availability for the last room on 5 March, both see one left, both book. Reading and then writing in application code cannot prevent it. Three ways to handle it:
| Option | How | Fits when |
|---|---|---|
| Pessimistic lock | SELECT ... FOR UPDATE on the night rows, then update | Contention is high; costs lock waits and deadlock care with multi-night ranges |
| Optimistic version | Read rows with a version column; update only if the version is unchanged; retry on conflict | Contention is low; retries are cheap |
| Conditional update | One UPDATE whose WHERE clause includes the capacity check | Simplest; the database applies each update atomically |
BEGIN;
INSERT INTO reservations (reservation_id, idempotency_key, hotel_id, room_type_id,
check_in, check_out, status)
VALUES (:rid, :key, :hotel, :room_type, :check_in, :check_out, 'PENDING');
-- a duplicate :key violates the unique index: return the existing reservation instead
UPDATE room_type_inventory
SET reserved = reserved + :rooms
WHERE hotel_id = :hotel AND room_type_id = :room_type
AND date >= :check_in AND date < :check_out
AND reserved + :rooms <= FLOOR(total_rooms * :overbook_factor); -- e.g. 1.05
-- application: if rows updated <> number of nights, ROLLBACK (some night is full)
COMMIT;The row count check is the important line. A stay from 4 to 7 March touches three rows; if only two were updated, one night was full and the whole transaction must roll back. An index range scan on (hotel, room type, date) usually walks the nights in ascending order, so overlapping bookings tend to lock rows in the same order and deadlocks stay rare; if the database reports one anyway, retry the transaction.
Compare this with ticket booking, where each seat is unique and the hard part is a crowd arriving in the same minute. Here the unit is a count, the stay spans several rows, and load is steady.
6. The architecture
- Guests
- Website
- Mobile app
- Edge
- CDN for hotel content
- API gateway
- Read path
- Search and availability service
- Availability cache
- Write path
- Reservation service
- Reservation database (inventory, rates, reservations)
- Payment service
- Events
- Booking events
- Emails
- Front-desk system
- SearchRead cached availability per hotel and date range; it may be seconds stale, which is fine because the booking step rechecks.
- ReserveRun the transaction above. Status PENDING holds the inventory.
- PayAuthorise the card with the reservation ID as the payment's idempotency key. On success mark CONFIRMED; on failure release the nights and mark CANCELLED.
- NotifyPublish a booking event for the cache, the confirmation email and the hotel's systems.
7. Deep dives
- Idempotency. The client creates the key once per booking attempt and reuses it on every retry. A unique index on it turns a duplicate into a lookup of the first result. Payment calls reuse the reservation ID the same way; the details are in design a payment system.
- Abandoned PENDING reservations. If payment never completes, a sweeper releases nights held longer than, say, 15 minutes by decrementing
reservedfor each night and marking the reservation expired. - Cancellations and changes. A cancel decrements each night. A date change is a cancel plus a new reservation inside one transaction, so the guest never loses their original nights if the new ones are full.
- Availability cache. Cache summaries per hotel and month, update them from booking events, and expire them after a short TTL as a safety net. A stale "available" is caught by the booking transaction; a stale "sold out" loses a sale, so refresh hot hotels more often. The general patterns are on caching.
- Splitting into services. If inventory and reservations live in different services with different databases, the booking becomes a distributed transaction. A saga (reserve inventory, create reservation, compensate on failure) works, but say plainly that one database is simpler at this volume.
8. What breaks, and what you do about it
| Failure | Effect | Mitigation |
|---|---|---|
| Client times out and retries | Risk of two reservations | Same idempotency key returns the first reservation |
| Payment succeeds, confirm write fails | Guest charged with no booking | Retry the confirm with the same keys; reconcile payments against reservations daily |
| Primary database fails | Bookings stop; search continues from cache and replicas | Synchronous replica in another zone and automatic failover |
| Overbooked night actually fills | A guest arrives to no room | Business process: walk the guest to a partner hotel; keep the overbook factor per hotel and season |
| Rate change during checkout | Guest sees one price and pays another | Quote a price with an expiry and honour it at booking |
9. Trade-offs to discuss
- One database or many services. One database gives simple transactions and is enough for tens of bookings a second; microservices add independent scaling and a distributed consistency problem.
- Pessimistic or optimistic. Locks queue contending writers; optimistic checks retry them. With low contention most of the year, conditional updates are the simplest choice.
- Fresh or fast search. Exact availability on every search costs database reads; cached summaries are fast and occasionally wrong. The booking transaction is the final check either way.
10. How to talk through it in the interview
Fictional example
- Interviewer
- Two guests book the last deluxe room for Friday and Saturday at the same moment. What happens?
- Candidate
- Each runs one transaction that updates the Friday and Saturday rows with a condition that reserved stays under the limit. The database applies the two updates to each row one after another. The second guest's update matches no row for at least one night, so the application sees fewer rows than nights, rolls back and returns sold out.
- Interviewer
- Their phone retries the request after a timeout. Do they get two rooms?
- Candidate
- No. The retry carries the same idempotency key, the insert hits the unique index, and I return the reservation from the first attempt.
- Model inventory per room type per night before drawing services.
- Show the row-count check for multi-night stays; it is the detail most candidates miss.
- Bring up idempotency before the interviewer asks about retries.
Practicing this design with Natively
This prompt is mostly about explaining one transaction clearly, so practise saying it in a few sentences. Run a mock on a call with Natively and you get a transcript of how you described the inventory update, suggested follow-up points such as abandoned holds or rate changes, and a diagram of the booking flow if you ask for one. Reviewing it later shows whether the row-count check ever made it into your answer.
Questions people ask
How do you prevent double booking in a hotel reservation system?
Store inventory as a count per hotel, room type and night, and reserve a stay with one transaction that updates each night only if the booked count stays under the limit. If fewer rows update than there are nights, roll back and report the room type as sold out.
How is a hotel reservation system different from ticket booking?
Ticket booking sells unique seats, often to a crowd in the same minute, so seat holds and waiting rooms dominate. Hotels sell a count of interchangeable rooms per room type over several nights at a steady rate, so the focus is multi-night atomic updates, overbooking rules and safe retries.
How does overbooking work in system design?
The business sets a factor, such as a few percent above the real room count, per hotel or season. The booking update's condition compares reserved rooms with the room count times that factor, so the database enforces the business limit rather than the physical one.
Why use an idempotency key for reservations?
Mobile clients time out and retry. The client sends the same key on every attempt, a unique index on it rejects the duplicate insert, and the service returns the original reservation instead of creating a second one.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
