2Brute2Best
🔥0
P15

Design a Hotel Room Booking System

Medium Pro OnlyBuilderStateStrategy
⚡ 30-Second Interview Cheat SheetP15 · 45-Min Design Plan
3 Patterns Combined
1. Scope Boundaries

In a 45-minute LLD interview, the interviewer tests fluent validated object creation, lifecycle state enforcement, and dynamic pricing strategies. Scope the solution to: inventory management across room types (Standard, Deluxe, Suite), date-range non-overlap availability checking over half-open intervals [checkIn, checkOut), fluent construction via ReservationRequest::Builder, state transitions (Tentative → Confirmed → CheckedIn → Cancelled), and surge/seasonal pricing models. Cleaning schedules and multi-property chains can be deferred to follow-ups.

2. Core Noun Entities
ReservationRequeststateful-class
ReservationRequest::Builderstateful-class
ReservationStateinterface
Reservationstateful-class
3. Hotspot → Pattern
Complex multi-parameter reservation construction and validation → Builder Pattern (ReservationRequest::Builder)
Reservation lifecycle transition rules (Tentative to Confirmed to CheckedIn to Cancelled) → State Pattern (ReservationState: Tentative, Confirmed, CheckedIn, Cancelled)
Dynamic seasonal and surge rate calculations → Strategy Pattern (PricingStrategy)
01

Problem statement & clarifying requirements

Design a hotel room booking system that manages room inventory across diverse room types (Standard, Deluxe, Suite). The system must validate reservation parameters fluently using the Builder Pattern, govern reservation lifecycles (Tentative → Confirmed → CheckedIn → Cancelled) using the State Pattern, and dynamically compute room charges with seasonal, holiday, and weekend multipliers via the Strategy Pattern.

Questions you should ask the interviewer first
“How are room reservations constructed and validated?”

Through ReservationRequest::Builder, enforcing cross-field invariants (e.g. check-out strictly after check-in, valid guest count, non-empty guest name) before creating an immutable ReservationRequest.

“What lifecycle states does a reservation transition through?”

Four explicit states: Tentative (on hold before payment), Confirmed (payment received), CheckedIn (guest on-premise), and Cancelled. Transitions like checking in without confirmation or cancelling after check-in are strictly forbidden.

“How is room availability determined for a date range?”

A room is available for interval [checkIn, checkOut) if no active (!= Cancelled) reservation for that room overlaps the interval: max(start1, start2) < min(end1, end2).

“How is dynamic pricing calculated?”

A PricingStrategy interface computes total cost combining room base rate, night count, add-on services (breakfast, airport shuttle, late check-out), and surge multipliers (weekend, holiday peak).

02

First, sketch the design yourself

Spend 5 minutes listing the classes, who owns whom, and which interface hides the part that changes.

  1. 1.

    Builder Pattern (b1) prevents constructor telescoping: A reservation involves multiple optional attributes (shuttle, breakfast, late check-out, special requests). The Builder pattern allows fluent construction and guarantees the final product is valid and immutable.

  2. 2.

    State Pattern (a4) enforces valid business lifecycles: Putting state transitions in Reservation with flags leads to scattered if (status == ...) checks. Polymorphic state objects cleanly reject invalid operations (e.g. refunding after checkout).

  3. 3.

    Date range overlap mathematics: Standard half-open intervals [checkIn, checkOut) permit back-to-back stays where one guest checks out on the same day another guest checks in.

03

How to think through this problem (5-step walkthrough)

Step 1 · Scope the 45-minute target & core boundary

In a 45-minute LLD interview, the interviewer tests fluent validated object creation, lifecycle state enforcement, and dynamic pricing strategies. Scope the solution to: inventory management across room types (Standard, Deluxe, Suite), date-range non-overlap availability checking over half-open intervals [checkIn, checkOut), fluent construction via ReservationRequest::Builder, state transitions (Tentative → Confirmed → CheckedIn → Cancelled), and surge/seasonal pricing models. Cleaning schedules and multi-property chains can be deferred to follow-ups.

Step 2 · Extract candidate nouns (and reject false classes)

Not every noun in the prompt deserves its own class. Separate dumb data structs from stateful managers, and turn trivial nouns into fields or enums.

ReservationRequest
Stateful Class / Manager

Immutable value object encapsulating validated booking specifications (dates, guest details, room type, add-ons), constructed exclusively via its nested Builder.

ReservationRequest::Builder
Stateful Class / Manager

Fluent builder validating cross-field invariants (e.g. check-out strictly after check-in, positive guest count, non-empty guest name) before assembling the immutable request.

ReservationState
Abstract Interface

Polymorphic State contract (TentativeState, ConfirmedState, CheckedInState, CancelledState) governing permitted lifecycle transitions and rejecting illegal operations.

Reservation
Stateful Class / Manager

Context entity holding reservation ID, validated request, calculated total price, and the current std::unique_ptr<ReservationState>.

PricingStrategy
Abstract Interface

Strategy contract calculating nightly stay totals, surge multipliers (weekend, peak holiday), and optional add-on fees (breakfast, airport shuttle, late checkout).

HotelBookingSystem
Stateful Class / Manager

Central facade managing room inventory, checking date range availability across active bookings, and coordinating reservations.

NightCount / GuestName
Reject as Class → Field / Method

Trap noun — NightCount is a derived scalar value (checkOut - checkIn) calculated by a helper method, and GuestName is a validated std::string, not heavy domain classes.

Step 3 · Draft the naive design & spot what breaks

A beginner writes a massive Reservation constructor with 8 parameters (guestName, checkIn, checkOut, roomType, breakfast, shuttle, lateCheckout, guests). Optional parameters lead to constructor telescoping, invalid date ranges pass silently into the system, and reservation lifecycles are checked via error-prone status strings (status == "TENTATIVE"). Guests can mistakenly cancel already completed stays or check into unconfirmed bookings without compiler or runtime guards.

Step 4 · Map change hotspots to design patterns
Complex multi-parameter reservation construction and validation→ Builder Pattern (ReservationRequest::Builder)

Telescoping constructors make code unreadable and permit invalid combinations (such as check-out preceding check-in or zero guests).

Reservation lifecycle transition rules (Tentative to Confirmed to CheckedIn to Cancelled)→ State Pattern (ReservationState: Tentative, Confirmed, CheckedIn, Cancelled)

Scattered if (status == ...) checks allow illegal transitions, like checking in without payment confirmation or refunding completed bookings.

Dynamic seasonal and surge rate calculations→ Strategy Pattern (PricingStrategy)

Hardcoded pricing algorithms inside the booking system prevent dynamic adjustments for peak tourist seasons, weekends, or promotional corporate discounts.

Step 5 · Lock down C++23 ownership, invariants & concurrency
  • ✓

    Half-open date interval non-overlap: Two reservations for the same room overlap if and only if $\max(start_1, start_2) < \min(end_1, end_2). Reservations ending on day D do not collide with new reservations beginning on day D$.

  • ✓

    Strict lifecycle directionality: A reservation can only transition along valid directed edges: Tentative → Confirmed → CheckedIn; cancellation is permitted from Tentative or Confirmed, but strictly forbidden once CheckedIn.

  • ✓

    Immutable request safety: Once built by ReservationRequest::Builder, a ReservationRequest is completely immutable, preventing post-validation tampering with dates, guest counts, or room categories.

04

Entities & design patterns used

Brute2Best Pro Content

Unlock Full UML Diagram & C++23 Solution

The complete UML diagram, production-ready C++23 code, follow-up extensions, and design pitfall analysis are part of Brute2Best Pro. All 7 foundation chapters are 100% free.

All 440 visual dry runs & algorithms
Interactive step-by-step playback with pointer & array state transitions
52 comprehensive LLD chapters
Interactive UML diagrams, real-world stories (Food Delivery, Trading, RPG), and practice solutions
40 C++ basics labs & hardware memory models
Vtables, byte layouts, assembly insights, and multi-threading race conditions
Production-ready C++23 source code
Modern idioms, clean contracts, time/space complexity derivations, and interview takeaways

First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.

Systems Integration

Related C++ Systems & Algorithmic Foundations

Deep dive into underlying layers