Skip to content

How to design a hotel booking system

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A hotel booking system shows a chain's hotels and room types with each day's price, reserves rooms of a type for a date range, charges the guest, and lets them cancel. Bookings are rare, about 3 a second across 5,000 hotels, but in peak season many guests reach for the same rooms at the same moment, and the business caps overbooking at 10%. The answer turns on counting by room type rather than by room number, with one inventory row per hotel, room type and night, and on making the count check and the write a single database transaction, so two guests racing for the last room don't both get it. A reservation id minted before the guest clicks book, kept as the reservation table's unique key, makes a repeated click or a retried request land on the same booking.

Clarifying questions

AskWhy it mattersA typical answer

How many hotels and rooms, and how often do guests book?

The booking rate decides whether one relational database with ordinary transactions is enough or whether you need to split it. The browsing rate decides what needs a cache.

5,000 hotels and about 1 million rooms, 70% full with 3-day stays. That gives about 240,000 reservations a day, about 3 a second, with roughly 30 views a second of the order page and 300 of room detail pages.

Does a guest reserve a specific room number or a room type?

A specific room means one status row per room per night and a search for a free one; a room type means a single count per night to check. It changes the data model and the concurrency guard.

A room type. The hotel assigns the room number at check-in, so the system counts rooms of a type per night.

Is overbooking allowed, and by how much?

It sets the ceiling the booking transaction checks against. Without it you'd compare against the plain room count and lose revenue hotels expect from guests who cancel.

Yes, 10%. A night can take reservations up to 110% of the rooms of that type, and not one more.

When does the guest pay?

Paying at booking puts the payment call inside the booking path, which raises the question of a booking left half done if the charge fails or times out.

In full when they book. Treat the payment service as part of the booking flow.

Can a guest cancel, and can they change dates?

Cancel means giving inventory back for each night and refunding. Changing dates is a cancel plus a new booking, which is more state to get right.

Cancel yes. Changing a reservation is out of scope for this round.

Is search by location and dates in scope, and do prices change by day?

Search is a different problem (indexing by geography and availability). Daily prices mean a rate per room type per date, not one price per room type.

Search is out of scope; a follow-up if time allows. Prices can differ each day, and a rate service serves them. How they're set is not ours.

How fast does a booking have to confirm?

If a few seconds are fine, the booking can be one synchronous request that checks inventory, writes the reservation and charges the card, with room for a retry.

A few seconds to confirm is acceptable. Browsing pages should feel fast.

The requirements menu

RequirementScopeWhy

Show a hotel and its room types with the day’s price

Core

The read path that carries most of the traffic. It needs hotel data, a rate per room type per date, and a rooms-left count that may be a few seconds old.

Reserve rooms of a type for a date range, paying in full

Core

The write path and the heart of the round: a count check across each night of the stay, a reservation row, and a charge, done so that two guests don't both take the last room.

Cancel a reservation

Core

Cancellation returns rooms to each night's inventory and refunds the guest. It is the reverse of booking and uses the same transaction shape.

Let staff manage hotels, rooms and inventory

Core

Staff add hotels and room types, and take rooms off the market for maintenance, which changes the ceiling future bookings are checked against.

Hold rooms for a few minutes while the guest pays, releasing them on a timer

Optional

Worth raising if payments become their own service: a pending reservation that counts against inventory until it is paid or expires is how a booking avoids being left half done. In the first version the reservation is written as pending and charged right after the commit, so the pending state is already there; add the timer when a payment can take minutes rather than seconds.

Assign a specific room number at booking time

Optional

Tempting because guests sometimes ask for a room. Leave it: counting by type keeps one row per night to check, and hotels assign numbers at check-in anyway. Say that the model could add a room assignment table later.

List a guest's past and upcoming reservations

Optional

The reservation list endpoint exists, and it costs little: an index by guest on the reservation table, or a guest-to-reservations lookup once the data is split by hotel. Take it if asked; it's a good test of what sharding costs.

Refund rules when a guest cancels, such as a fee inside a cutoff window

Optional

If the interviewer wants a cancellation fee or a cutoff, it touches the payment service. Take it as a status plus a refund amount on the reservation; leave the policy engine out.

Guest accounts and sign-in

Out of scope

Ordinary account handling. Keep a guest id on each reservation so the list and cancel endpoints can check ownership, and stop there.

Confirmation emails and reminders

Out of scope

A notification pipeline that reads reservation events. Say an event leaves the reservation service on confirm and cancel, then park it.

Phone bookings

Out of scope

A staff client that calls the same reservation API would cover it, so nothing in the design changes. Name it and move on.

Search by location and dates: a follow-up if time allows

Out of scope

A geospatial and availability index is its own system. If time remains, say how it would read the inventory cache rather than the database.

How the daily price is set: the rate service only serves it

Out of scope

Pricing is a revenue-management problem. The design reads a rate per room type per date and stops there.

Non-functional requirements

RequirementWhat it forces

No overbooking beyond the 10% the business allows

The count check and the write to the inventory row for each night happen inside one database transaction, comparing rooms reserved plus rooms requested with 110% of the rooms of that type, guarded by a lock or a version check so a second writer doesn't slip in between. A cached count is for display; it doesn't get to approve a booking.

High concurrency in peak season

Many guests hit the same hotel's rows for the same nights, so the guard has to cope with contention: short transactions, locks taken in a fixed order or a version check with a retry, and no long-lived holds. Splitting data by hotel spreads hotels across machines but does nothing for the single hotel everyone wants, so the per-row guard still matters.

A few seconds to confirm a reservation is acceptable

The booking can be one synchronous request: check inventory, write the reservation, charge the card, reply. There's room for a retry after a version conflict and for a payment call inside the budget, so no queue or asynchronous confirmation is needed for the first version.

About 3 reservations a second on average

Writes are light, so one relational database with ACID transactions holds reservations and inventory, and a distributed lock service would add moving parts without a need. The effort goes into correctness under contention and into the read path, where room pages at about 300 a second outnumber bookings by a hundred to one.

Estimates

QuantityWorkingResultWhat it sizes

Reservations a day, a second, and rows a year

1 million rooms × 70% occupancy ÷ 3-day stays ≈ 233,333 a day, rounded to 240,000; ÷ 100,000 seconds in a day ≈ 2.4, call it 3 a second; 240,000 × 365 ≈ 88 million reservation rows a year

About 240,000 reservations a day, about 3 a second, about 88 million rows a year

The write load, which a single relational database takes in stride, and the reservation table, which wants an archive job for past stays.

Page views a second from the booking funnel

Assume 10% of visitors continue at each of the two steps before booking: 3 bookings a second × 10 = 30 order-page views; × 10 again = 300 room-detail views

About 30 order-page views and 300 room-detail views a second

The read path: about a hundred reads per write, which is why availability and hotel data get a cache and the database keeps the writes.

Inventory rows kept two years ahead

5,000 hotels × 20 room types × 2 years × 365 days = 73 million rows

73 million rows

The room_type_inventory table: large enough to index with care, small enough for one database.

Inventory table size

Assume about 100 bytes a row for two ids, a date, two counts, a version and index overhead: 73 million × 100 bytes ≈ 7.3 GB

Roughly 7.3 GB

Why sharding is not needed for storage at the chain's scale; it comes later for request load, not bytes.

Bookings per hotel per day

240,000 reservations a day ÷ 5,000 hotels = 48 a day per hotel, about two an hour

About 48 a day for an average hotel

How often two bookings for the same hotel collide: rarely on average, which favors an optimistic version check over row locks. Peak season at a popular hotel is the exception.

Rows one booking touches

A 3-day stay covers 3 nights, so 3 inventory rows (one per night) plus 1 reservation row, all in one transaction

3 inventory rows and 1 reservation row for an average stay

How many rows the lock or version check covers, and why locking them in date order matters: two stays that overlap on some nights contend on just those rows.

Overbooking ceiling for a room type

A type with 100 rooms × 110% = 110 reservations a night; the check is reserved + requested ≤ 110

Up to 110 reservations for 100 rooms on one night

The comparison inside the booking transaction, and the constraint the database can enforce as a backstop.

Load per shard at booking.com scale

30,000 requests a second ÷ 16 shards by hotel id ≈ 1,875 requests a second on each shard

About 1,875 requests a second on each of 16 shards

The number of shards the design grows to once request load, not storage, is the limit.

Core entities

EntityWhat it holds

Hotel

One row per property in the chain: where it is and what staff can edit about it.

Room type

A class of room at one hotel, such as a king or a twin; what guests reserve.

Room

A physical room with a number; kept for staff and check-in, not for booking.

Room type rate

The price of one room type for one night; served by the rate service, set elsewhere.

Room type inventory

The row the whole design protects: how many rooms of a type exist and how many are reserved for one night at one hotel.

Reservation

One booking by one guest for some rooms of a type over a date range, with its payment state.

Guest

Whoever books. Accounts are out of scope, so this is a stub the reservation points at.

The API

EndpointNotes

GET /v1/hotels/{id} and GET /v1/hotels/{id}/rooms/{id}

The hotel page and the room detail page. Hotel and room data change rarely, so they cache well; the room detail page also asks the rate service for the price per night and shows a rooms-left count that may lag the database by a moment. Take a date range as query parameters for the price and the count.

POST /v1/reservations { startDate, endDate, hotelID, roomTypeID, roomCount, reservationID }

The booking. The client sends a reservationID it received when the guest reached the review page; it is the primary key of the reservation table, so a repeated click, or a retry after a timeout, returns the existing booking instead of making a second one. A sold-out night returns 409 Conflict with which night failed; success returns 201 Created with the reservation and its payment state.

GET /v1/reservations and GET /v1/reservations/{id}

The signed-in guest's list, and one reservation by id. Both check that the caller owns the reservation (or is staff). The list reads an index by guest; once data is split by hotel, it reads a guest-to-reservations lookup instead.

DELETE /v1/reservations/{id} → cancel

Sets the status to canceled and subtracts room_count from total_reserved for each night of the stay, in one transaction, then asks the payment service for the refund. Deleting is idempotent: canceling an already canceled reservation returns the same result rather than an error.

POST, PUT and DELETE /v1/hotels and /v1/hotels/{id}/rooms for staff only

Staff endpoints behind staff authentication, usually reachable from an internal network rather than the public gateway. Adding or removing rooms, or taking one off the market, changes total_inventory for the affected nights, which the booking check reads on its next run.

The high-level design

browsebookGuestAPI gatewayHotelsReservationsDatabase

Step 1 of 4

Two services and one database

Start with the two jobs. A hotel service answers GET /v1/hotels/{id} and the room detail page; a reservation service takes POST /v1/reservations and the cancel. Both sit behind an API gateway that handles authentication and routing. One relational database holds hotels, room types, rooms, the per-night inventory and the reservations. Relational fits here because the data is clearly structured, bookings are rare at about 3 a second, and the booking needs ACID transactions so an inventory update and its reservation row commit together or not at all. The inventory table has one row per hotel, room type and night, with the rooms that exist and the rooms reserved: 73 million rows two years ahead, roughly 7.3 GB at a hundred bytes a row, so storage is not what would push this toward sharding. A daily job adds the rows for new dates as the calendar advances, so a row exists to count against.

browsebookCDCGuestAPI gatewayHotelsReservationsRatesPaymentsDatabaseRedis cache
The whole design

What breaks first

The deep dives

Two guests, one last room. Two guests reserve the last room of a type for the same night, in the same second. Walk one booking through the reads and writes, and say what stops the second one, and what happens when the same guest clicks book twice.

A concept that helps here: Optimistic and pessimistic lockingA concept that helps here: Idempotency keysA concept that helps here: Transactions and isolation levels

Growing to booking.com scale. The site grows to about 30,000 requests a second while bookings and room checks still land on one database. Which box breaks first, how do you split the data, and what does a guest see when the copy they read from lags?

A concept that helps here: Sharding and partition keysA concept that helps here: Change data captureA concept that helps here: Sagas and two-phase commit

Concepts this guide uses

Sources

  1. Alex Xu, System Design Interview volume 2, chapter 23: Hotel reservation system (notes at books.dwf.dev)
  2. Alex Xu, System Design Interview volume 2, chapter 23: reading notes (yongjie.netlify.app)
  3. PostgreSQL documentation: Explicit locking
  4. PostgreSQL documentation: Constraints
  5. dev.to (susumun): optimistic and pessimistic locking compared
  6. Wikipedia: Optimistic concurrency control
  7. Stripe API reference: Idempotent requests
  8. Microsoft Azure Architecture Center: Saga distributed transactions pattern
  9. Microsoft Azure Architecture Center: Compensating Transaction pattern
  10. Wikipedia: Two-phase commit protocol
  11. Debezium: Why Debezium
  12. Debezium: Frequently asked questions
  13. System Design Academy: Design a hotel reservation system
Sign in to report a mistake