Problem statement
Design the object model and public APIs for the booking core behind a boutique gym's class schedule, where members reserve spots in instructor-led sessions that each carry a fixed capacity.
Operating context. A studio publishes a weekly schedule of classes (spin, yoga, HIIT); each session has a start time, duration, instructor, room, and a hard capacity. A member books a spot, may cancel up to a cutoff before start, and rolls onto a waitlist when the session is full. When a confirmed member cancels, the earliest eligible waitlisted member is promoted automatically. A member may hold at most one active booking across any overlapping time window. Single studio, in-process service, one wall clock.
Out of scope. Payment capture and membership billing, the mobile / REST surface, calendar-sync exports (iCal), instructor payroll, and the persistence engine (assume in-memory for v1).
What to produce. The class hierarchy (entities, value objects, services), the public API each class exposes, and the state transitions for a booking (requested → confirmed / waitlisted → attended / cancelled / no-show). Be explicit about: how a full session waitlists rather than overbooks under concurrent booking attempts, how the promotion rule is pluggable (FIFO today, priority-tier tomorrow), and how the cancellation-cutoff policy is injected so it can be tested without waiting on a real clock.
Functional requirements
- Book a spot in a scheduled session: confirm it if capacity remains, otherwise add the member to that session's waitlist.
- Cancel a booking before the session's cutoff and release the seat for promotion.
- Promote the next eligible waitlisted member automatically when a confirmed spot is released.
- Reject a booking that overlaps in time with the member's existing active booking.
- Let staff query a session's confirmed roster, waitlist depth, and remaining capacity.
Non-functional requirements
- Concurrent booking attempts on the last remaining seat must confirm exactly one member and waitlist the rest.
- Booking, cancelling, and promoting are O(log N) or better in the waitlist size N.
- The waitlist promotion order is a pluggable policy swapped without touching the booking or cancel paths.
- The cancellation-cutoff clock is injected so lifecycle rules are unit-testable with no real time.
- Adding a new session type or a new promotion tier is a localized change, not an edit to the allocator core.
- The booking state machine rejects illegal transitions, such as cancelling an already-attended booking.
Topics
- System Design LLD
- Oop Solid
- Patterns Strategy
- Patterns State-Machine
- Concurrency Locks