ArchitectAI resilience reviews are here. See what's new
Back to all articles
Low Level Design Sep 04, 2026 14 min read

Low Level Design: Hotel Room Booking System with Optimistic Locking

Solving the hotel booking machine coding problem. Date interval overlap checks, optimistic locking for double-booking prevention, and transient reservation holds.

LLDHotel BookingConcurrencyOptimistic LockingOOP
HFHLDForge Architecture TeamLead Machine Coding Specialist

1. Domain Model: Hotels, Rooms & Reservations

A hotel has multiple rooms of different types (Standard, Deluxe, Suite). A reservation spans a date range `[checkInDate, checkOutDate)`. Two reservations for the same physical room conflict if their date ranges overlap: `startA < endB && endA > startB`.

2. Preventing Double-Booking: Concurrency Models

Pessimistic Locking: Acquiring a database `SELECT FOR UPDATE` on the room row serializes checkouts but degrades throughput.

Optimistic Locking (Recommended): Each room inventory record has an integer `version` field. When committing a reservation, the update verifies the version hasn't changed. If another thread reserved the room first, the transaction fails gracefully and retries.

3. Code Implementation

Here is the room reservation manager implementation:

typescript
class Booking {
  constructor(public roomId: string, public checkIn: Date, public checkOut: Date) {}
  overlaps(start: Date, end: Date): boolean {
    return this.checkIn < end && this.checkOut > start;
  }
}

class HotelManager {
  private bookings: Booking[] = [];
  public bookRoom(roomId: string, checkIn: Date, checkOut: Date): boolean {
    const hasConflict = this.bookings.some(b => b.roomId === roomId && b.overlaps(checkIn, checkOut));
    if (hasConflict) return false;
    this.bookings.push(new Booking(roomId, checkIn, checkOut));
    return true;
  }
}
Interactive Modeling ArchitectAI

Model this architecture on the HLDForge Canvas

Turn static box diagrams into living, collaborative systems. Drag and drop microservices, Kafka clusters, and cache tiers. Run automated SPOF detection and STRIDE threat modeling in real time.

HF

Written by HLDForge Architecture Team

Lead Machine Coding Specialist

The HLDForge Architecture Team publishes practical engineering guides, real-world case studies, and high-concurrency blueprints to help engineers build scalable and fault-tolerant software.

Free forever plan

Ready to master distributed system design?

HLDForge gives you the tools, templates, and AI reviews to design systems like a Staff Engineer. Get started free.

SOC 2 Type II · ISO 27001 aligned · SSO on every paid plan