Hotel Management System
Reservations, Billing & Operations
Design a hotel system that books room types for date ranges without overbooking any night, assigns a clean room at check-in, prices each night through stacked rules, and tracks rooms through cleaning.
Overview
A hotel sells nights, not rooms. A guest books a room type (standard, deluxe, suite) for a range of dates, and only when they arrive does the front desk give them a particular room. In between, the system must make sure that on every night of every stay it has not promised more rooms of a type than the hotel owns. When the guest leaves, the room needs cleaning before anyone else can use it, and the bill adds up each night's price plus anything charged to the room.
The problem tests four things. First, separating the reservation (a type and dates) from the room assignment (a room number at check-in), which is the move that makes the rest simple. Second, date ranges: a stay from Thursday to Sunday uses the nights of Thursday, Friday and Saturday, and two stays that touch on one day do not overlap. Third, a room status state machine so that nobody checks into a dirty room. Fourth, pricing as a chain of small rules, because rates change more often than anything else.
A strong answer states the half-open date rule early, counts bookings per type per night, draws the room states, and demos an overlap refusal, an upgrade and a bill.
Scoping the problem
The scope comes down to seven questions. For each, here is why it matters and the usual answer.
- Does a guest book a room type or a specific room? This decides the inventory model. A guest books a type, and the room is given at check-in.
- Is the check-out day a night of the stay? This is the off-by-one that breaks overlap checks. It is not: stays are half-open, with the check-in day included and the check-out day excluded.
- What if no clean room of the type is free at check-in? The choices are to upgrade, to wait, or to move the guest to another hotel. The usual answer is an upgrade to the next type at no extra charge.
- How are prices set? Rates can be seasonal, weekend, long-stay or corporate. Model them as stacked rules applied to each night.
- Are extras charged to the room? Yes, and they add line items to the bill.
- Overbooking on purpose? It changes the capacity check, so leave it out of the core and treat it as a follow-up.
- Several front desks and websites at once? Yes, and that decides the locking: a night must never be oversold.
Functional requirements
- available(type, check_in, check_out) returns how many rooms of a type are free on every night of the stay
- book(guest, type, check_in, check_out) reserves a room type for the stay or refuses if any night is full
- cancel(id) returns every night of a booked reservation to inventory
- check_in(id) assigns an AVAILABLE room of the booked type, or of the next type up as a free upgrade when that type has a spare room every night
- add_extra(id, description, cents) charges services to an in-house guest
- check_out(id) returns the total (room charge plus extras) and sends the room to housekeeping
- cleaned(number) and set_maintenance(number, on) move rooms through their states
Non-functional requirements
- No night is sold beyond the rooms of its type, even with many desks booking at once
- Stays are half-open date ranges; back-to-back stays never conflict
- Room status changes follow one transition table
- A new pricing rule is a new class added to the list; the Hotel class does not change
- Money in integer cents; percentages round down and in a fixed order
Interview questions
- How would you make sure the database never oversells a night?
- An upgrade gives a standard guest a deluxe room. What can go wrong?
- How would you add overbooking on purpose?
- How does housekeeping decide which room to clean first?
Sign up free to read the full topic
More Low-Level Design topics
Start free on Cariara · Coding problems · System design studio