Hotel management

Rooms, bookings and availability: modelling date ranges, preventing double booking and pricing by room type and season.

On the roadmap:Software Design · step 4: Low-level design: start with objects

Lesson 4 of 16 · 11 min read · quiz · exercise

The problem

Guests search for a room type and dates, book, check in, check out and pay. Staff manage rooms. The system must never double-book a room for overlapping dates.

Entities

Figure SDA-LLD-04-1 · Hotel classes · © forcsguy.com

Booking.status moves through reserved, checked in, checked out, cancelled.

Availability is a range problem

A room is free for [in, out) if no active booking overlaps it. Two ranges overlap when startA < endB && startB < endA.

const overlaps = (a: Range, b: Range) => a.start < b.end && b.start < a.end;

function freeRooms(rooms: Room[], bookings: Booking[], want: Range, type: string) {
  return rooms.filter((r) => r.type === type &&
    !bookings.some((b) => b.room === r && b.status !== "CANCELLED" && overlaps(b, want)));
}

Booking safely

Figure SDA-LLD-04-2 · Booking flow · © forcsguy.com

The check and the insert must be one atomic step. In a database that means a transaction with a lock on the room row (or an exclusion constraint on the date range). In memory it means a lock per room.

Pricing

Keep price calculation behind RatePlan: base price per room type, multiplied by season, weekday and demand, with member discounts. A Booking stores the price it was sold at, so later rate changes do not alter old bookings.

Cancellation, check-in and check-out

  • Cancel: apply a cancellation policy (strategy) to compute the refund from how close the stay is.
  • Check-in: assign a specific room if the booking was for a type, mark checked in, create a folio for extra charges.
  • Check-out: add extras, settle the payment, mark the room "needs cleaning" and release it for new bookings after housekeeping.

Extensions

Group bookings, room upgrades, overbooking with a controlled allowance, and housekeeping as a small state machine (dirty, cleaning, ready).

Real-world reading

Check your understanding

Question 1 of 3

0 correct so far

What makes hotel booking harder than selling a single item?

© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.