Chapter Twenty-Three · Problem Seventeen

Hotel Reservation

A small table that everyone fights over: inventory kept as counts, a room held across a card payment, and a search path that may lag while the booking path stays exact.

4 lessons · 45 minutes
The Question

"Design booking for a hotel chain: guests search availability and reserve rooms, and no room is ever sold twice for the same night."

Size will not make this hard. A chain sells a known number of rooms, and the table all of its guests fight over is about a gigabyte. The hard moment is one row near the end of a sale: the last room on a night, and two guests pressing Book at once. Then a stay of several nights has to take all of them or none, and the money turns up later than the room.

Three earlier chapters carry the weight. Chapter 5's Leases, Locks and Fencing and Transactions Across Partitions give you the hold and the saga. Chapter 3's When One Machine Is Not Enough, Hot Partitions and Picking the Partition Key, whose hotel section this chapter computes, settle the split and what a sale does to it. Chapter 4's CAP and PACELC, Precisely says what booking does when the store cannot be sure: it refuses. Backend Deep Dive's lesson on the oversell fixed one seat in one service, and it is named here and not taught again. This problem is a run of nights across many hotels, split and still correct.

The round suits mid to senior. A mid-level candidate has to reach the race on the last room. A senior one raises it unprompted, and says that the bytes do not force the split. The difficulty has three parts. The first is inventory as counts per room type per night, and the control that protects them. The second is a booking of several nights held across a payment. The third is search on a stale copy of availability, against a booking path that stays exact. The fight is contention on rows that share one partition. Atomicity across two partitions belongs to Chapter 25's wallet, and nothing here needs it.

Put 45 minutes on a timer and sketch yours before the first lesson. Then ask your sketch one thing: what does the second guest's transaction see on the last room? Scope stops at minute 10. First Design stops at 20, Scaling It at 30, and the interviewer picks what fills the last fifteen.

The 45 minutes of this problem, lesson by lesson
Scopeminutes 0-10
→
First Designminutes 10-20
→
Scaling Itminutes 20-30
→
Deep Divesminutes 30-45

Lessons in This Chapter