Home/Low-level design/Meeting Room Booking System

Meeting Room Booking System

Interval conflicts and atomic room allocation

Ownership and transitions

Half-open intervals overlap exactly when a.start < b.end and b.start < a.end; equality at an endpoint permits adjacency. Plan all requested rooms before committing any reservation. A successful booking ID remains reserved after cancellation, while a failed ID can be retried. Sorting feasible rooms by capacity/ID gives deterministic allocation. A scan-based catalog uses O(rooms * bookings) checks plus candidate sorting.

Java boundaries

Use the supplied nested records as immutable value carriers. A record is only shallowly immutable: copy every retained mutable input and every outward list/map, including lists inside records. Absence is null; validation failures use IllegalArgumentException, missing-key purchase errors use NoSuchElementException, and invalid transaction boundaries use IllegalStateException. Java primitive types already exclude booleans from numeric inputs. Numeric values use long where signatures say long and all computations must fit signed 64-bit values. Calls in these service exercises are serialized.

Half-open reservations permit endpoint adjacency but reject any shared interior time. The predicate works for containment and partial overlap alike:

java
import java.util.*;

class Example {
    public static void main(String[] args) {
        long leftStart = 0, leftEnd = 2;
        long rightStart = 2, rightEnd = 4;
        boolean overlap = leftStart < rightEnd && rightStart < leftEnd;
        assert !overlap;
        assert leftEnd == rightStart;
    }
}

Using <= in either comparison would reject touching bookings incorrectly. For multiple rooms, compute the entire feasible allocation before adding any room reservation; one missing room must not leave a partial booking.

Design boundary

A successful booking ID remains reserved after cancellation, while a capacity failure leaves the ID reusable. Each room independently must satisfy seats; capacities are not summed across rooms. This abstract-time model intentionally has no wall-clock cleanup or recurrence policy.

Put it into practice

Implement the exercise in a full-screen workspace, then run its tests.

Open practice
Next lessonExpense Sharing System