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 Published 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

Numbers for a large hotel chain (assumed figures)
QuantityAssumptionResult
Hotels and rooms50,000 hotels, 5 million roomsthe inventory to manage
Bookings70% occupancy, average stay of 3 nightsabout 1.2 million bookings a day, about 14 a second on average
Searchesabout 30 availability checks per bookingabout 400 a second on average, more at seasonal peaks
Inventory rows20 room types per hotel, bookable 2 years ahead50,000 x 20 x 730 = 730 million rows
Inventory storageabout 50 bytes per rowabout 37 GB: modest for a relational database
Numbers for a large hotel chain (assumed figures). Scroll sideways on a small screen.

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)
The booking call carries a client-generated key so retries cannot double book.

4. Sketch the data model

Tables in the reservation database
TableKey and fieldsNotes
hotels, room_typeshotel and room type detailsMostly static; cached
room_type_inventory(hotel_id, room_type_id, date) -> total_rooms, reservedOne 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 ruleWritten by revenue staff
reservationsreservation_id, idempotency_key (unique), guest, hotel, room type, dates, status, totalStatus: PENDING, CONFIRMED, CANCELLED
room_assignmentsreservation_id -> room numberFilled at check-in, not at booking
Tables in the reservation database. Scroll sideways on a small screen.

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:

Concurrency control options
OptionHowFits when
Pessimistic lockSELECT ... FOR UPDATE on the night rows, then updateContention is high; costs lock waits and deadlock care with multi-night ranges
Optimistic versionRead rows with a version column; update only if the version is unchanged; retry on conflictContention is low; retries are cheap
Conditional updateOne UPDATE whose WHERE clause includes the capacity checkSimplest; the database applies each update atomically
Concurrency control options. Scroll sideways on a small screen.
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;
Reserve every night of a stay in one transaction (illustrative SQL with named parameters, not run).

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

  1. Guests
    • Website
    • Mobile app
  2. Edge
    • CDN for hotel content
    • API gateway
  3. Read path
    • Search and availability service
    • Availability cache
  4. Write path
    • Reservation service
    • Reservation database (inventory, rates, reservations)
    • Payment service
  5. Events
    • Booking events
    • Emails
    • Front-desk system
Search and booking paths for a hotel chain. Guests use the website or app through an API gateway. Search requests go to a search and availability service that reads hotel content and cached availability summaries, refreshed from inventory changes. Booking requests go to a reservation service that runs the inventory transaction against the reservation database, then calls a payment service to authorise the card. Confirmed bookings are published as events that update the availability cache, send confirmation emails and feed the hotel's front-desk system. Revenue staff update rates and inventory through an internal tool that writes to the same database.
  1. SearchRead cached availability per hotel and date range; it may be seconds stale, which is fine because the booking step rechecks.
  2. ReserveRun the transaction above. Status PENDING holds the inventory.
  3. 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.
  4. 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 reserved for 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 modes
FailureEffectMitigation
Client times out and retriesRisk of two reservationsSame idempotency key returns the first reservation
Payment succeeds, confirm write failsGuest charged with no bookingRetry the confirm with the same keys; reconcile payments against reservations daily
Primary database failsBookings stop; search continues from cache and replicasSynchronous replica in another zone and automatic failover
Overbooked night actually fillsA guest arrives to no roomBusiness process: walk the guest to a partner hotel; keep the overbook factor per hotel and season
Rate change during checkoutGuest sees one price and pays anotherQuote a price with an expiry and honour it at booking
Failure modes. Scroll sideways on a small screen.

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

The last room on a busy weekend
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.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP