Design an In-Memory Hotel Reservation System
Model room availability, confirmed stays, and cancellation using only in-memory data structures.
Design a hotel reservation system using only in-memory data structures, with no database.
For this exercise, assume one hotel has a fixed catalog of individually identified rooms. A guest can search for rooms available for a stay, book one chosen room, inspect a reservation by its ID, and cancel it. Guests and rooms have stable opaque identifiers.
A stay uses local calendar dates and a half-open interval [check-in, check-out): check-in must precede check-out, and another stay may begin on the checkout date.
For this exercise, assume a booking is confirmed immediately and receives a unique reservation ID. The same room must never have overlapping confirmed reservations.
Cancellation changes a confirmed reservation to cancelled and releases its interval; repeating cancellation returns the existing cancelled result without another change. An availability result is a snapshot, so a later booking can fail if another booking intervenes.
Invalid intervals, unknown rooms, unavailable rooms, and unknown reservation IDs return explicit errors without partial mutation.
For this exercise, assume the foundation runs in one process with sequential operations; its state is lost on process restart. Payments, temporary holds, room-type inventory, room administration, authentication, persistence, networking, and pricing are outside scope.
A follow-up introduces concurrent threads in the same process while keeping the no-database constraint.
Design responsibilities, data structures, focused operation contracts, and interactions. No implementation is required. The original report supplies the hotel domain and the in-memory/no-database restriction; the journey and detailed rules above are practice assumptions.