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
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
| Ask | Why it matters | A 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. |
Non-functional requirements
| Requirement | What 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
| Quantity | Working | Result | What 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
| Entity | What 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
| Endpoint | Notes |
|---|---|
| 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. |
| 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 |
| 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. |
| 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. |
| 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
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.
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.
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?
Concepts this guide uses
Sources
- Alex Xu, System Design Interview volume 2, chapter 23: Hotel reservation system (notes at books.dwf.dev)
- Alex Xu, System Design Interview volume 2, chapter 23: reading notes (yongjie.netlify.app)
- PostgreSQL documentation: Explicit locking
- PostgreSQL documentation: Constraints
- dev.to (susumun): optimistic and pessimistic locking compared
- Wikipedia: Optimistic concurrency control
- Stripe API reference: Idempotent requests
- Microsoft Azure Architecture Center: Saga distributed transactions pattern
- Microsoft Azure Architecture Center: Compensating Transaction pattern
- Wikipedia: Two-phase commit protocol
- Debezium: Why Debezium
- Debezium: Frequently asked questions
- System Design Academy: Design a hotel reservation system