System Design Atlas

Hotel inventory and room pricing

05 / 10Worked example

Data and states

Which reservation changes must take effect together, and what remains protected after completion?

The contracts require an authoritative data store for reservation R-27. A stay includes the half-open date interval from arrival inclusive to departure exclusive. Two nights of 12000 cents each make 24000 cents. The offer version freezes this price; later room rates do not change existing confirmations. The state is stored together with its command result; this keeps the same change task visible after restart.

Starting point Confirmation binds the price offer version.

Assumptions for the example case

Own fictitious example design. One hotel, one room category, full nights and a fixed offer in EUR without prepayment. A price offer is valid for 300 seconds; at exactly 300 seconds, a new confirmation is rejected. All figures and test goals are illustrative assumptions.

Authoritative data and permitted state transitions

Nights, offer and reservation

Category K-27Category with date-related quotas
Price Offer A-27Offer version · 2 × 12,000 = 24,000 cents
Reservation R-27occupies November 14 and 15 together
Kategorie K-27 → Preisangebot A-27Provides inventory for 1..n nights
Preisangebot A-27 → Reservierung R-27Confirmed not more than once
Reservierung R-27 → Kategorie K-27occupies every bound night
1offered → confirmed or expired at 300 s
2confirmed → cancelled or arrived
3arrived → completed
4expired, cancelled and completed block a new confirmation

The offer freezes the price; the category-night inventory lists the quantity available each night.

A stay includes the half-open date interval from arrival inclusive to departure exclusive. Two nights of 12000 cents each make 24000 cents. The offer version freezes this price; later room rates do not change existing confirmations.

Domain entities and relationships

EntityAuthoritative attributesRelationship
Room category and nightK-27 + date of the night; inventory and active occupancyFor each stay, all affected night rows are locked in date order.
Price offerA-27; two nights, 24000 cents, expiration timeDesignates price and stay; does not reserve capacity itself.
ReservationR-27; Guest reference, offer reference and statusA confirmed reservation occupies inventory for each night.
Inventory movementReservation, night, debit or one-off releaseCancellation only returns the previously occupied nights.

Room category and night

Authoritative attributes
K-27 + date of the night; inventory and active occupancy
Relationship
For each stay, all affected night rows are locked in date order.

Price offer

Authoritative attributes
A-27; two nights, 24000 cents, expiration time
Relationship
Designates price and stay; does not reserve capacity itself.

Reservation

Authoritative attributes
R-27; Guest reference, offer reference and status
Relationship
A confirmed reservation occupies inventory for each night.

Inventory movement

Authoritative attributes
Reservation, night, debit or one-off release
Relationship
Cancellation only returns the previously occupied nights.

Permitted state transitions

Starting pointTargetPrecondition
OfferedbestätigtThe offer is still valid and all nights are atomically available.
OfferedDecayedThe time limit for the offer has been reached.
bestätigtstorniertThe reservation team confirms cancellation before arrival and releases all nights once.
bestätigtangereistReception confirms the arrival.
angereistabgeschlossenReception confirms completion of the stay.
expired, cancelled or completedterminalNew confirmation remains blocked.

Offered

Target
bestätigt
Precondition
The offer is still valid and all nights are atomically available.

Offered

Target
Decayed
Precondition
The time limit for the offer has been reached.

bestätigt

Target
storniert
Precondition
The reservation team confirms cancellation before arrival and releases all nights once.

bestätigt

Target
angereist
Precondition
Reception confirms the arrival.

angereist

Target
abgeschlossen
Precondition
Reception confirms completion of the stay.

expired, cancelled or completed

Target
terminal
Precondition
New confirmation remains blocked.

Atomic changes and versions

Content reference
A stay includes the half-open date interval from arrival inclusive to departure exclusive. Two nights of 12000 cents each make 24000 cents. The offer version freezes this price; later room rates do not change existing confirmations.
Shared commit
Reservation API checks category, arrival, departure, price offer version and total price in cents and writes domain change, command result and, if applicable, pending work in a transaction. Commit means that these changes will be permanently visible together. Before commit, a rollback ends the attempt without partial effect.
Concurrency
Two confirmations claim the last night. In either order of competing requests, exactly one reservation receives every night; the other receives a conflict and no partial allocation.
Terminal completion
Double cancellation releases the quota once. A completed reservation can neither be confirmed again nor released again.

Cover the full scope of the case

Concrete rule
An expired offer cannot generate a new reservation. A reservation already confirmed within the deadline does not expire when the offer subsequently expires. The two nights are either promised together or rejected together.

Derive storage needs from access patterns

Authoritative relational datastore
For each stay, all affected night rows are locked in date order. The offer specifies the price and stay without reserving capacity. The design therefore uses a relational metadata store with uniqueness constraints and short transactions. Historical versions remain referenceable; a rebuildable read model must not overwrite the authoritative state.
Large content and measurement series
Derived views and extensive measurement or event histories are read separately according to their access patterns. Binding state decisions remain in the authoritative datastore.

Cancellation releases the same nights exactly once

Cancellation releases the same nights exactly once

Cancellation releases the same nights exactly once.

Two confirmations claim the last night. In either order of competing requests, exactly one reservation receives every night; the other receives a conflict and no partial allocation.

Double cancellation releases the quota once. A completed reservation can neither be confirmed again nor released again. The exercise specifies the input and expected result.

Alternative considered
Separate unversioned changes allow an older state to overwrite the newer one.
Trade-off
Changes to reservation R-27 will be serialized briefly.
Reassess
Measurable waiting times for 50 requests for the last available night justify a check of the transaction duration.

Try it yourself

Explain the two possible winner orders in the case contract. Also determine the behaviour after terminal completion.

A hint for your attempt

Content revision and aggregate version have different tasks.

Compare with a possible solution
Concurrency
Two confirmations claim the last night. In either order of competing requests, exactly one reservation receives every night; the other receives a conflict and no partial allocation.
Completion
Double cancellation releases the quota once. A completed reservation can neither be confirmed again nor released again.

Apply to your project

Which states must remain protected in your model against late replay?

Next: Room-night inventory stays at the reservation core.