Part 9 · Blueprint 57
Hotel & Flight Reservation System
11 min reading · Sources · Editorial review pending
Availability on one night does not prove the whole date range is reservable.
Page details
Published date · Last edited:
Draft edition. Editorial review and supplementary reading recommendations are still being completed.
Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Distributed Transactions: 2PC vs. Saga Orchestration, High-Concurrency Ticket Booking System.
Sixty-second mental model
Problem: Availability on one night does not prove the whole date range is reservable.
Use: Protect the requested set of nights as one invariant.
Design boundary: Reserve room capacity over a date interval with explicit local-calendar rules. One counter for the entire hotel cannot represent availability for every night.
Layer 1 · Intuition
Hypothetical scenario: Northwind is designing hotel reservations. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one room night means and which component owns the room-night availability.
Think of a calendar requiring every night in a requested stay. Separate the requester from room-night availability, then identify the retained evidence needed after failure.
- Authority
- The entitled state owner.
- Invariant
- A rule preserved across concurrency and failures.
Architecture and worked reasoning
Design boundary: Reserve room capacity over a date interval with explicit local-calendar rules. One counter for the entire hotel cannot represent availability for every night.
Responsibilities on the request path
Workload and limiting resource
Hypothetical stay from June 10 through checkout June 13 consumes the nights of June 10, 11 and 12: three room-nights. Twenty such bookings consume 60 room-nights. Capacity on June 13 does not repair a shortage on June 11.
Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.
Mutation or publication path
- Expand the requested stay into required nights.
- Atomically hold all needed night capacity under the chosen transaction boundary.
- Confirm or release with durable workflow evidence.
Observation and recovery path
- Query availability for the complete interval.
- Read the caller’s reservation state.
- Reconcile partial or uncertain workflow outcomes.
Failure that changes the decision
Hypothetical scenario: A workflow holds two nights but fails on the third. Either the transaction aborts all holds or a durable compensation path releases the partial allocation.
Attempt this decision before reading the explanation
Can availability be decided by averaging free rooms over the stay?
No. Every requested night must satisfy the required capacity invariant. An average can conceal a completely full night.
Supporting mechanism analysis
Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.
Hypothetical scenario. Northwind reserves a unit inside PostgreSQL, then loses the independent payment provider’s response. Dev proposes rolling back the database transaction. Priya asks whether the provider’s effect belongs to that database boundary.
Distinguish a local commit, coordinated preparation and a compensating workflow. Keep the uncertain provider effect visible while deciding what the reservation permits next. The selected workflow cohort is its own exercise, not an implicit increase in catalogue traffic.
Before you continue: Does a caller’s rollback function undo both services as one atomic operation?
The independent provider may already have acted or remain unresolved. A local transaction cannot silently claim authority over that separate effect.
This lets the team choose a real coordination or compensation contract. Compensation is a later business action with its own outcomes, not an automatic erasure of history.
Hypothetical scenario. A database reservation and an external provider charge do not share a transaction manager. A durable workflow stores the reservation identity, provider operation identity, evidence and next recovery action. Payment uncertainty stays pending until lookup or reconciliation supplies a stronger fact.
In two-phase commit, participants prepare before a coordinator records and communicates a decision. Prepared resources can remain blocked while the decision is unavailable. Use that design only with actual participating resource managers and a recovery protocol; an arbitrary HTTP service is not a participant merely because the caller waits for it.
Hypothetical failure scenario. A workflow decides to refund a payment after a reservation expires. The provider refunds it, but the local process crashes before recording completion. A recovery worker issues another refund because the local state still says pending.
This is the idempotency problem inside compensation. Use the provider's supported identity and reconciliation capabilities, persist the intended corrective action, and distinguish requested, confirmed and unresolved states. Compensation is not exempt from partial failure.
An operational queue should identify unresolved cases and the authorized human decision path where automation cannot establish the outcome. Record the evidence and preserve the original logical operation identity. A manual action without that context can repeat the same mistake as an automated retry.
“A saga is a distributed transaction with automatic rollback.” It permits intermediate commits and uses business-specific corrective actions. Visibility and isolation differ.
Layer 3 · Internals
A hotel stay consumes inventory over a date interval, not one aggregate counter. Represent the requested nights under a consistent calendar and time-zone rule, then require enough capacity on every night. A hypothetical three-night stay with remaining capacities 4, 0 and 7 cannot be accepted merely because the sum is 11. The minimum available capacity across the required nights is zero.
Room-type allocation can be separated from assigning a particular physical room, but both transitions need explicit invariants. Acquire locks or execute a serializable transaction under a consistent ordering to avoid partial allocation and deadlock surprises. Holds need identities, expiry and a payment reconciliation policy. A deliberately chosen overbooking policy is a business assumption with a stated limit, not an accidental consequence of racing updates. Cached availability bitmaps can narrow search candidates, but final reservation must consult the authority. Integration with an external reservation provider also needs an outcome state for requests whose acceptance cannot yet be confirmed.
Trade-offs and limits
| Approach | Provides | Requires |
|---|---|---|
| Room-night inventory | Makes every required night visible to the transaction. | Long stays touch more records and require consistent lock ordering. |
| Precomputed availability bitmap | Quickly removes impossible search candidates. | Final acceptance must recheck authoritative capacity across the entire interval. |
Recovery decision
Hypothetical scenario: A workflow holds two nights but fails on the third. Either the transaction aborts all holds or a durable compensation path releases the partial allocation.
No. Every requested night must satisfy the required capacity invariant. An average can conceal a completely full night.
Write your design before revealing the review
Can availability be decided by averaging free rooms over the stay?
Drafts and self-review are stored only in this browser. They are separate from reading completion.
Compare your decision
No. Every requested night must satisfy the required capacity invariant. An average can conceal a completely full night.
A workflow holds two nights but fails on the third. Either the transaction aborts all holds or a durable compensation path releases the partial allocation.
Check your understanding
Can availability be decided by averaging free rooms over the stay?
No. Every requested night must satisfy the required capacity invariant. An average can conceal a completely full night.
How would you recover from this failure: A workflow holds two nights but fails on the third. Either the transaction aborts all holds or a durable compensation path releases the partial allocation.
Start with the exact boundary that failed. Expand the requested stay into required nights. Atomically hold all needed night capacity under the chosen transaction boundary. Confirm or release with durable workflow evidence. Then recover evidence through the observation path: Query availability for the complete interval. Read the caller’s reservation state. Reconcile partial or uncertain workflow outcomes. Preserve the distinction between a confirmed state change and an unavailable response.
Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?
Hypothetical stay from June 10 through checkout June 13 consumes the nights of June 10, 11 and 12: three room-nights. Twenty such bookings consume 60 room-nights. Capacity on June 13 does not repair a shortage on June 11. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Reserve room capacity over a date interval with explicit local-calendar rules. One counter for the entire hotel cannot represent availability for every night.
Which component in this topology could be removed from a smaller first deployment?
Stay request, Night inventory, Reservation hold, Payment saga name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Expand the requested stay into required nights.
What evidence must a caller have before relying on the observation path?
Query availability for the complete interval. Read the caller’s reservation state. Reconcile partial or uncertain workflow outcomes. No. Every requested night must satisfy the required capacity invariant. An average can conceal a completely full night.
45-minute interview rubric
- 00–05: scope room night and room-night availability.
- 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
- 12–28: draw room-night availability, numbered writes and reads.
- 28–40: challenge recovery: Protect the requested set of nights as one invariant.
- 40–45: defend hotel_id placement, observations and remaining assumptions.
Go deeper
- PostgreSQL: Documentation: 18: 8.17. Range Types · Primary document · www.postgresql.org. Protect the requested set of nights as one invariant. Verified 2026-10-26.
- PostgreSQL: Documentation: 17: PREPARE TRANSACTION · Primary document · www.postgresql.org. Protect the requested set of nights as one invariant. Verified 2026-10-26.
- PostgreSQL: Documentation: 17: 66.4. Two-Phase Transactions · Primary document · www.postgresql.org. Protect the requested set of nights as one invariant. Verified 2026-10-26.
Decision log
Protect the requested set of nights as one invariant.
Preserve room night identity and room-night availability ownership.
Revisit changed workload, observations or recovery objectives.