skip to content

In a hotel booking system, why store pooled per-night counts per room type rather than rows per room, and how does a multi-night stay book?

level: middleimportance: should knowfreq 50%

answer

  1. guests buy a type, not a number
  2. assign the room at check-in
  3. one record per type per night
  4. every night or none
  5. a sell limit above capacity

basics

~20 s

Guests book a room type, not a room number, so one count per room type per night suffices and rooms are assigned at check-in. A multi-night stay takes every night or none; an overbooking cap lifts each night's sell limit.

solid answer

~50 s

Assigned concert seats are distinct items a buyer picks, so each needs its own record. Hotel rooms of one type are interchangeable, so the system keeps one record per hotel, room type and night with `capacity`, `held`, `sold` and a `sellLimit`. A booking takes from the counts and the room is assigned at check-in; as long as no night exceeds the rooms available, an assignment with no mid-stay room change exists. A three-night stay must take all three nights together: inside one transaction, each night is incremented only if it is under its limit, and if any night is full the whole stay rolls back. Keying the records by hotel and room type keeps a stay's nights in one partition, so that transaction stays local. Overbooking is just a `sellLimit` above capacity, roughly capacity times one plus the expected no-show rate, enforced by the same check; it works only because pooled rooms are interchangeable.

code

pseudocode · 16 lines
pseudocode
// Illustrative; field and function names are invented.
// Nights are [checkIn, checkOut): the checkout date itself is not booked.
function holdStay(hotelId, roomType, checkIn, checkOut, holdId, expiresAt):
    begin transaction
    for night in datesFrom(checkIn, until = checkOut):      // ascending order
        changed = incrementIf(
            record    = nightInventory(hotelId, roomType, night),
            field     = held,
            by        = 1,
            condition = sold + held + 1 <= sellLimit)
        if not changed:
            rollback                     // undoes every night taken so far
            return NoAvailability(night)
    insert stayHold(holdId, hotelId, roomType, checkIn, checkOut, expiresAt)
    commit
    return Held(holdId)

go deeper

for a junior

Recall that hotel guests book a room type, so the system can count rooms per type per night instead of picking a room number at booking time.

for a middle

Explain the per-night record, the all-or-none transaction over a stay's nights, and why keying records by hotel and room type keeps that transaction on one partition.

for a senior

Show the judgment: no-show risk is correlated, the cap is enforced in the same condition as normal sales, fragmentation from early room assignment, and cross-partition stays released by retry and expiry.

for a principal

Treat the overbooking allowance as a revenue policy the system must make adjustable per night and measurable, with someone owning the cost of guests who cannot be housed.

## Two shapes of inventory A booking system's first modelling decision is whether the thing sold is a **specific item** or a **quantity of interchangeable items**. | | Per-item rows | Pooled counts | |---|---|---| | Typical use | assigned concert seats, a named table in a restaurant | hotel room types, general-admission tickets | | What the buyer chooses | an exact item (row 12, seat 7) | a kind of item (a double room) | | Record | one per item per event | one per type per night (or per event) | | A hold changes | that item's state | the type's `held` count | | Can be overbooked | no, a second sale is a double sale | yes, up to a cap | A concert seat must be a row, because the buyer chose it and nobody else may have it. A hotel guest booking "a double room for three nights" does not care which double room; forcing the system to pick room 412 at booking time creates work and wastes capacity. ## Why pooled counts suit rooms The hotel keeps one record per **hotel, room type and night**: `capacity` (rooms of that type in service), `held`, `sold` and a `sellLimit`. Picking a specific room per booking causes problems the counts avoid: - **Fragmentation.** If every booking is pinned to a room, a guest asking for three nights can be refused even though every night has a free room of that type, because no *single* room is free on all three. - **Volume.** Counts need one small record per type per night, rather than one per room per night. - **Late assignment works.** Stays are runs of consecutive nights. If no night has more stays than rooms, assigning rooms in arrival order, giving each arriving guest any room free that night, always finds one, and nobody has to move mid-stay. Real hotels still face limits the counts ignore, such as accessible or connecting rooms, which are usually modelled as their own room type. ## A multi-night stay takes every night or none A stay from the 10th to the 13th needs the nights of the 10th, 11th and 12th. Taking two of three is worthless to the guest and wastes two nights of inventory. The booking is **all-or-none**: 1. Open one transaction. 2. For each night in ascending date order, increment `held` only if `sold + held` is below that night's `sellLimit`. 3. If any night fails the condition, roll back, which undoes the nights already taken, and report which night is full. 4. Otherwise record the stay hold with its expiry and commit. Two details make this cheap. **Keying the per-night records by hotel and room type** puts a stay's nights in the same partition, so the transaction never spans servers. **Taking nights in date order** means two overlapping stays always contend in the same order rather than each grabbing a night the other needs. When the hold expires, the same nights give back one `held` each; when it confirms, each moves from `held` to `sold`. ## Folding in the overbooking cap Some guests never arrive. Overbooking sells slightly more than capacity so those empty rooms still earn. In the pooled model it is one field: `sellLimit` on each night's record, set above `capacity`, and enforced by the very condition the booking already checks. Holding `capacity` and the allowance separately lets revenue staff change the policy per night without touching inventory. The common rule of thumb is **sell limit = capacity × (1 + expected no-show rate)**. Worked through for one illustrative room type: - 200 rooms, 5% expected no-shows: 200 × 1.05 = **210** sellable. - If all 210 are sold, expected arrivals are 210 × 0.95 = 199.5, almost exactly full; the exact expected-fill figure is 200 / 0.95 ≈ 210.5. - Because the rule aims at the average, many nights will be over. Treating no-shows as independent, at least one guest arrives to no room on roughly 39% of fully sold nights; a limit of 205 brings that to roughly 2%. Group cancellations and weather make real no-shows correlated, so true risk is higher. That is why the formula is a ceiling to reason from, not a setting to copy. **When everyone shows up**, check-in assignment simply runs out of rooms for the last arrivals; the system's job is to detect it early (arrivals forecast above capacity) and flag it. How the hotel compensates a guest it cannot house is a business policy, not an inventory mechanism. Seats a buyer picked by number cannot carry an overbooking cap: a seat number cannot be shared, so selling it twice is not a bet on no-shows but a double sale. ## Pitfalls - Booking each night of a stay as a separate request, so a failure halfway leaves orphaned nights. - Storing only `available` and losing the split between held and sold, which makes expiry and reporting guesswork. - Applying the overbooking allowance to rooms the guest picked by number. - Hard-coding the no-show rate instead of measuring it per hotel, season and channel.

  • What if a stay's nights live on different partitions, so one local transaction cannot cover them?
    First try to avoid it by keying nights by hotel and room type. If it is unavoidable, take each night as a separate hold with its own expiry, in date order, and release the ones already taken when a later night fails. The release must be retried until it succeeds, and the holds' expiry is the backstop if the releasing process dies, so a failed stay never pins inventory for longer than the hold's time limit.
  • Why does the per-night record keep held and sold separately instead of one available number?
    Holds expire and sales do not. With separate fields, an expiry gives back exactly one held night, a confirmation moves one from held to sold, and reports can show how much inventory is merely pending. A single available number hides that difference, so a lost expiry or a double release cannot be detected by comparing against the stay holds.

  • Every hotel room needs its own booked row so the guest knows the room number.
  • A multi-night stay can book the free nights and waitlist the full one.
  • Overbooking works the same way for assigned concert seats.
  • Capacity times one plus the no-show rate guarantees nobody is turned away.
  • Pooled counts need no condition on the decrement because the numbers are small.