0
0
LLDsystem_design~25 mins

Hotel, Room, Booking classes in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Hotel Booking System
Design focuses on core classes and their relationships for hotel, room, and booking management. Payment processing, user authentication, and UI are out of scope.
Functional Requirements
FR1: Allow creation and management of hotels with multiple rooms
FR2: Support room types and availability tracking
FR3: Enable customers to book rooms for specific dates
FR4: Prevent double booking of the same room for overlapping dates
FR5: Allow cancellation and modification of bookings
Non-Functional Requirements
NFR1: Support up to 10,000 hotels and 100,000 rooms
NFR2: Booking operations should respond within 200ms
NFR3: System availability target is 99.9%
NFR4: Data consistency is important for booking operations
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Hotel class to represent hotel details
Room class to represent individual rooms and their types
Booking class to represent reservations with date ranges
Availability checking logic
Booking management service
Design Patterns
Aggregation between Hotel and Room classes
Composition of Booking with Room and Customer
Use of date range overlap checks
Factory pattern for creating bookings
Observer pattern for availability updates
Reference Architecture
HotelBookingSystem
  |
  +-- Hotel
  |     +-- Room
  |
  +-- Booking
  
Classes:
Hotel -- owns --> Rooms
Booking -- references --> Room
Booking -- has --> date range
Components
Hotel
Class
Represents a hotel with attributes like name, location, and a list of rooms
Room
Class
Represents a room with attributes like room number, type, and status
Booking
Class
Represents a reservation with customer info, room reference, and booking dates
Request Flow
1. User requests to book a room for specific dates
2. System checks the requested hotel's rooms for availability
3. For each room, system checks existing bookings for date overlaps
4. If an available room is found, system creates a Booking instance
5. Booking is saved and room availability is updated
6. Confirmation is sent to the user
Database Schema
Entities: - Hotel(id, name, location) - Room(id, hotel_id, room_number, type, status) - Booking(id, room_id, customer_id, start_date, end_date, status) Relationships: - Hotel 1:N Room - Room 1:N Booking Constraints: - Booking dates must not overlap for the same room
Scaling Discussion
Bottlenecks
Checking room availability for many rooms and bookings can be slow
Booking conflicts due to concurrent requests
Database write contention on booking records
Solutions
Use caching for room availability data with short TTL
Implement optimistic locking or transactions to prevent double booking
Partition booking data by hotel or room to reduce contention
Use asynchronous processing for non-critical updates
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying assumptions, 20 minutes designing classes and relationships, 10 minutes discussing scaling and trade-offs, 5 minutes summarizing
Explain class responsibilities and relationships clearly
Discuss how to handle booking conflicts and availability checks
Mention data consistency and concurrency control
Highlight scalability considerations and possible optimizations
Show awareness of real-world constraints and trade-offs