Hotel Reservation: Scope
A hotel has a fixed number of rooms, and that one fact cuts most of this problem down before you draw. These ten minutes find out how far. You ask what a guest is really buying and when they pay, you derive the bookings from the rooms and not from a guess, and you let search set the read path.
Six Questions Before the First Table
Six answers change the board. Each line gives the change and what this lesson agrees.
- Does a guest book a room type, or one particular room? One row per room per night is 292 million rows, and one count per type per night is 12 million. Agreed: a type, and the desk assigns the room at check-in.
- How many hotels and rooms, and how far ahead do you sell? This sets the rows and caps the bookings, because a hotel sells no more than it has. Agreed: 8,000 hotels, 100 rooms each, 4 room types, 365 nights ahead, and stays of 2 nights on average.
- How does search compare with booking? This sets the read path. Agreed: a hundred searches per booking.
- When does the guest pay? Paying up front means keeping a room for someone who has not paid yet. Agreed: up front, by card.
- Is "never sold twice" literal, or does the hotel oversell on purpose? This decides whether a count's floor is zero or a business number. Agreed: literal for now, and the deep dive reopens it.
- Can one booking span two hotels? A yes puts a transaction across partitions in the core path. Agreed: no. A trip across hotels is two reservations, and if the second is refused the trip cancels the first, as Chapter 5's saga does.
The first answer saves the most, and the interviewer may ask what it gives up. A row per room would say which room a guest has, and nobody asked for that. The count loses nothing, because on any night the guests in house are no more than the rooms, so whoever arrives finds one free.
The payment answer needs a sentence of its own, because you are about to defer it. Try this: "Paying up front means something has to keep the room while the card goes through. I'll call that the hold, and I'm parking it for the deep dive."
What You Agree On
Four things are functional: search availability by city and dates, reserve a room type for a run of nights, cancel, and see your own reservations.
Four promises sit beside them. No room is sold past the count, under any concurrency or retry. A confirmed reservation survives the loss of any machine. Search may lag by seconds, and booking may not. And when the store cannot be sure, booking refuses, the per-operation choice of Chapter 4's CAP and PACELC, Precisely, because two answers on the last room cost a guest their night.
Four things you leave out, and say so: pricing and rate rules, loyalty, the desk's room assignment, and the payment system behind the card call, which is Chapter 24's. The interviewer can still pull any of them back at this point, and it costs nothing yet.
The Numbers the Rooms Allow
Start from the rooms, because they cap everything written. Eight thousand hotels at 100 rooms is 800,000 rooms. At 2 nights a stay, a full chain takes at most 400,000 new stays a day, before the few that are cancelled and sold again. Assume that ceiling. Over about 100,000 seconds, it is 4 bookings a second, and 8 at a peak of twice the average. The rooms cap the writes, so the write rate decides nothing.
One hotel's share is the number to keep. Eight a second over 8,000 hotels is one booking every 1,000 seconds at peak. So contention is about the last room and the sale, never ordinary traffic.
Search is where the load is. A hundred times 8 is 800 searches a second at peak. Assume a city shows 25 hotels, each checked for 4 room types over 2 nights. That is 200 checks a search, and 160,000 checks a second at peak. This number moves the design.
Inventory comes out small. Eight thousand hotels, 4 types and 365 nights make about 12 million counts. Assume 100 bytes each, and that is about 1.2 gigabytes. The table everyone fights over is small.
Reservations are the largest thing kept. Four hundred thousand a day for 5 years is about 730 million. Assume about 1 kilobyte each. That is 730 gigabytes, and about 2.2 terabytes across three machines. Assume 2 terabytes a node, so the 730 gigabytes fit one node. Keep that result, because the interviewer is going to ask you to split this data.
Bandwidth gets a sentence and moves nothing: 800 searches a second at an assumed 10 kilobytes a reply is 8 megabytes a second, against the 1.25 gigabytes a second of a 10-gigabit link.
API and Entities
A GET on availability, with a city and dates, returns hotels and room types with what is free. A POST to reservations carries the hotel, the type, the dates and a request ID, a value the page makes so that a repeat can be recognised. It returns the reservation or a refusal. A DELETE on a reservation's ID cancels it, if it belongs to the signed-in guest. A GET on that ID reads that one, for its owner, from its partition, and a GET on reservations lists the guest's own. A reservation's ID begins with its hotel, and that pays off when the data is split. Paying gets a call of its own when the hold comes back.
GET /availability?city=lisbon&from=2027-03-10&to=2027-03-12
200 hotels and types, with what is free
POST /reservations {"hotel": "h4217", "type": "deluxe",
"from": "2027-03-10", "to": "2027-03-12",
"request_id": "0195e2c4-7a10-7c3e-9d21-5f8a6b2e4c01"}
201 {"id": "h4217-r88321"}, or 409 no room
GET /reservations/h4217-r88321 200 one reservation
DELETE /reservations/h4217-r88321 204
GET /reservations 200 this guest's reservations
There are three entities. A hotel has a city. A room type has its room count. A reservation has its ID, the guest, the hotel, the type, the dates and the request ID. Every booking names exactly one hotel, and the split comes back to that.
- Modelling each physical room per night when guests buy a type: 292 million rows for a distinction nobody asked for, and the interviewer asks what it buys.
- Estimating booking writes at length when the rooms cap them and the searches decide.
- Drawing the flow without asking when the guest pays, so at minute 35 a room has to wait for a card with nothing keeping it.
- Bookings derived from rooms out loud, with the remark that the rooms cap them.
- Type or room asked before a table is drawn, along with what the answer saves.
- Searches multiplied into checks, and that number left to set the read path.
Knowledge Check
Which clarifying question changes the inventory table the most?
- How many searches does a guest run for each booking?
- Does a guest book a room type, or one particular room?
- Can one booking span two hotels in one transaction?
- Does the guest pay up front, or when they check out?
8,000 hotels have 100 rooms each, and a stay averages 2 nights. What do the rooms allow?
- At most 800,000 new stays a day, or 8 a second on average
- At most 200,000 new stays a day, or 2 a second on average
- At most 400,000 new stays a day, or 4 a second on average
- No ceiling at all, since guests can book a year in advance
800 searches a second at peak, 25 hotels a city, 4 types, 2 nights. What load is that on availability?
- 800 checks a second, since one query can cover a whole city
- 20,000 checks a second, since each hotel answers just once
- 80,000 checks a second, one for each hotel and room type
- 160,000 checks a second, one per hotel, type and night
Which estimate can you state in a breath and leave, because no decision hangs on it?
- The bookings at peak, about 8 a second across the chain
- The checks at peak, about 160,000 a second from search
- One hotel's share, one booking every 1,000 seconds or so
- The reservations after 5 years, about 730 GB before replicas
You got correct