Bird
Raised Fist0

Hotel Management System

LLDmediumInterview freq: medium
Choose your preparation mode4 modes available
🏗️
Hotel Management System
Design a scalable and concurrent hotel management system handling rooms, housekeeping, and billing
mediumBooking and Reservation SystemsFreq: medium
Prerequisites:Concurrency in JavaObject-Oriented DesignDesign PatternsJava Collections Framework
⚙️
Functional Requirements
  • Allow guests to book available rooms with concurrency control to prevent double booking
  • Track room status: Available, Occupied, UnderCleaning, Maintenance
  • Housekeeping staff can update room cleaning status concurrently
  • Generate accurate bills including room charges and additional services
  • Support dynamic pricing strategies per room type and season
  • Allow cancellation and modification of bookings
  • Maintain audit logs for room status changes
👤
Use Cases
  • Guest books a room
  • Receptionist checks room availability and assigns rooms
  • Housekeeping staff updates room cleaning status
  • Billing department generates bills for guests
  • System administrator manages room inventory and pricing
🧑‍💻
Actors
  • Guest
  • Receptionist
  • Housekeeping Staff
  • Billing Department
  • System Administrator
❓
Clarifying Questions to Ask
  • How many concurrent booking requests can the system expect? (e.g., hundreds per second)
  • Is pricing fixed per room type or dynamic based on demand and season?
  • What happens if housekeeping updates conflict with guest check-in?
  • Are partial cancellations or modifications allowed after booking?
  • Should the system support overbooking or waitlisting?
  • How to handle billing if guest extends stay or uses additional services?
Out of Scope
✗ Online payment gateway integration
✗ Loyalty program management
✗ Detailed guest profile management
✗ Mobile app interfaces
⚡
QPS Calculation
write qps200
read qps1000
🖥️
Server Estimate
app servers5
db servers3
Estimates based on expected concurrent bookings, housekeeping updates, and billing queries.
🔢
Enumerations
enum RoomStatus
AVAILABLE | OCCUPIED | UNDER_CLEANING | MAINTENANCE
Defines finite room states to prevent invalid status assignments and enables exhaustive switch-case handling in Java.
enum BookingStatus
CONFIRMED | CANCELLED | CHECKED_IN | CHECKED_OUT
Encapsulates booking lifecycle states, preventing string typos and enabling compile-time checks.
enum RoomType
SINGLE | DOUBLE | SUITE | DELUXE
Categorizes rooms for pricing and availability logic, ensuring type safety and clarity.
enum HousekeepingStatus
PENDING | IN_PROGRESS | COMPLETED
Tracks housekeeping task progress, enabling concurrency-safe updates and UI status display.
📦
Room
4 fields
private final String roomNumberprivate volatile RoomStatus statusprivate final RoomType typeprivate volatile Booking currentBooking
Represents a hotel room with unique number, type, and current status. Manages booking assignment with concurrency safety.
public String getRoomNumber()Returns the unique room number.
public RoomStatus getStatus()Returns the current status of the room.
public synchronized boolean assignBooking(Booking booking)Atomically assigns a booking if room is AVAILABLE, updates status to OCCUPIED, returns true if successful.
public synchronized void releaseRoom()Marks room as AVAILABLE and clears current booking atomically.
public void setStatus(RoomStatus status)Updates room status with volatile write to ensure visibility.
📦
Booking
7 fields
private final String bookingIdprivate final String guestNameprivate final RoomType roomTypeprivate volatile BookingStatus statusprivate final Date checkInDateprivate final Date checkOutDateprivate volatile Room assignedRoom
Represents a guest's booking request and lifecycle, tracks assigned room and booking status.
public String getBookingId()Returns unique booking identifier.
public synchronized void updateStatus(BookingStatus newStatus)Atomically updates booking status to prevent race conditions.
public void assignRoom(Room room)Associates a room with this booking.
📦
HousekeepingTask
4 fields
private final String taskIdprivate final Room roomprivate volatile HousekeepingStatus statusprivate final String assignedStaff
Tracks housekeeping tasks per room with status updates and staff assignment.
public HousekeepingStatus getStatus()Returns current housekeeping task status.
public synchronized void updateStatus(HousekeepingStatus newStatus)Atomically updates housekeeping status to avoid concurrent update conflicts.
📦
Billing
4 fields
private final String billingIdprivate final Booking bookingprivate volatile double amountprivate volatile boolean isPaid
Calculates and tracks billing amount for a booking, manages payment status.
public synchronized void calculateAmount()Calculates total amount based on room type, duration, and additional services.
public synchronized void markPaid()Marks the bill as paid atomically.
public double getAmount()Returns the current billing amount.
📦
Hotel
4 fields
private final String hotelNameprivate final Map<String, Room> roomsprivate final Map<String, Booking> bookingsprivate final Map<String, HousekeepingTask> housekeepingTasks
Central manager for rooms, bookings, and housekeeping tasks. Coordinates concurrency-safe operations.
public synchronized boolean bookRoom(Booking booking)Atomically checks room availability and assigns booking to a room.
public synchronized void updateHousekeepingStatus(String taskId, HousekeepingStatus status)Updates housekeeping task status safely.
public synchronized void cancelBooking(String bookingId)Cancels a booking and releases the room atomically.
🗄️
Rooms
PK: roomNumber
roomNumber STRINGhotelName STRINGroomType STRINGstatus STRINGcurrentBookingId STRING
Stores room details and current booking reference.
🗄️
Bookings
PK: bookingId
bookingId STRINGguestName STRINGroomType STRINGstatus STRINGcheckInDate DATEcheckOutDate DATEassignedRoomNumber STRING
Stores booking lifecycle and assigned room.
🔌
POST
/bookRoom
Request
{
  "guestName": "string",
  "roomType": "string",
  "checkInDate": "date",
  "checkOutDate": "date"
}
Response
{
  "bookingId": "string",
  "status": "string",
  "assignedRoomNumber": "string"
}
Books a room if available, returns booking confirmation or failure.
🔌
POST
/updateHousekeepingStatus
Request
{
  "taskId": "string",
  "status": "string"
}
Response
{
  "success": "boolean"
}
Updates housekeeping task status safely.
🔌
POST
/cancelBooking
Request
{
  "bookingId": "string"
}
Response
{
  "success": "boolean"
}
Cancels a booking and releases the room.

Practice

(1/5)
1. You want to add a WeekendFeeStrategy to calculate parking fees differently on weekends using the current adapter-based design. What is the minimum change required to comply with SOLID principles?
medium
A. Add a boolean flag to Vehicle to indicate weekend and modify ParkingLot to check it.
B. Create a new WeekendFeeStrategy class implementing FeeStrategy and inject it where needed without modifying existing classes.
C. Modify the existing FeeStrategy class to add weekend logic with if-else checks.
D. Add weekend fee logic inside the adapter class that adapts Vehicle to ParkingLot.

Solution

  1. Step 1: Identify SOLID principle involved

    Open-Closed Principle (OCP) requires extending behavior without modifying existing code.
  2. Step 2: Evaluate options

    Create a new WeekendFeeStrategy class implementing FeeStrategy and inject it where needed without modifying existing classes. respects OCP by adding a new class implementing FeeStrategy. Add a boolean flag to Vehicle to indicate weekend and modify ParkingLot to check it. modifies Vehicle and ParkingLot, violating OCP. Options A and D modify existing classes.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    New strategy class extends behavior without modifying existing code [check]
Hint: OCP: extend with new class, don't modify existing ones [check]
Common Mistakes:
2. The Wallet System currently calculates fees with a FeeStrategy interface. To add a WeekendFeeStrategy without modifying existing classes, which SOLID principle is being applied and what is the minimum required change?
medium
A. Open/Closed Principle: create WeekendFeeStrategy implementing FeeStrategy; no existing class changes.
B. Dependency Inversion Principle: inject WeekendFeeStrategy into Account class by modifying Account.
C. Single Responsibility Principle: modify FeeStrategy to handle weekends explicitly.
D. Liskov Substitution Principle: override FeeStrategy methods in WeekendFeeStrategy and modify Transaction.

Solution

  1. Step 1: Identify the SOLID principle for extensibility

    Open/Closed Principle (OCP) states software entities should be open for extension but closed for modification.
  2. Step 2: Apply OCP to fee calculation

    Adding WeekendFeeStrategy as a new class implementing FeeStrategy extends behavior without modifying existing classes, preserving OCP.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    New FeeStrategy implementation -> no existing class changes -> OCP [check]
Hint: Add new strategy class, no existing code change -> OCP [check]
Common Mistakes:
3. In a parking system, the parkVehicle() method checks if a spot is available and then marks it occupied. Without synchronization, which exact thread interleaving causes double-booking of the same spot?
medium
A. Thread 1 reads spot as occupied; Thread 2 waits until spot is free.
B. Thread 1 checks spot availability -> true, context switch before marking occupied; Thread 2 checks availability -> true, both mark spot occupied.
C. Thread 1 marks spot occupied; Thread 2 reads spot as occupied and aborts parking.
D. Thread 1 and Thread 2 both wait on a lock, preventing double-booking.

Solution

  1. Step 1: Trace parkVehicle() check-then-act sequence

    Thread 1 reads spot as available (true), then context switch occurs before marking occupied.
  2. Step 2: Thread 2 also reads spot as available (true) and proceeds to mark it occupied, causing double-booking.

  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Check-then-act race without synchronization -> double-booking [check]
Hint: Check-then-act gap causes double-booking without synchronized [check]
Common Mistakes:
4. In a parking lot system, if parkVehicle() is not synchronized, which exact thread interleaving causes double-booking of the same spot?
medium
A. Thread 1 parks vehicle, Thread 2 parks vehicle simultaneously without checking availability.
B. Thread 1 updates spot status after parking, Thread 2 reads stale status and parks again.
C. Thread 1 releases spot, Thread 2 immediately parks without synchronization.
D. Thread 1 checks spot availability -> true, context switch; Thread 2 checks availability -> true; both park concurrently.

Solution

  1. Step 1: Identify the check-then-act race condition

    Without synchronization, Thread 1 reads spot as available and is preempted before marking it occupied. Thread 2 also reads available and proceeds to park.
  2. Step 2: Confirm both threads park concurrently causing double-booking

    Both threads believe the spot is free and park, leading to inconsistent state and double-booking.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Unsynchronized check-then-act -> double-booking race [check]
Hint: Check-then-act without sync -> double-booking race condition [check]
Common Mistakes:
5. The Restaurant Management System needs to support ElectricCar vehicles that require ChargingSpots. What is the minimum change to the current Java design to add this feature without modifying existing classes?
hard
A. Add ELECTRIC_CAR to VehicleType enum, CHARGING to SpotType enum, create ElectricCar subclass, and update SpotCompatibility map externally.
B. Modify Vehicle class to include a boolean isElectric field and add charging logic inside existing methods.
C. Create a new ChargingSpot class extending Spot and modify TableManager to handle charging spots explicitly.
D. Add charging logic inside the existing Spot class and modify all subclasses to support electric vehicles.

Solution

  1. Step 1: Identify extensibility without modifying existing classes

    Adding new enum values and subclasses without changing existing classes respects OCP and avoids class explosion.
  2. Step 2: Update compatibility externally

    Updating SpotCompatibility map outside existing classes allows new vehicle and spot types to integrate without modifying existing code.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    New enums + subclass + external compatibility update -> minimal change [check]
Hint: Add enums + subclass + external map update -> minimal change [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard