System Design Atlas

Hotel inventory and room pricing

04 / 10Worked example

Interfaces

How does the “confirm stay” contract distinguish a repetition from a new intention?

The load profile meets the specific change order “confirm stay”. Its content consists of category, arrival, departure, price offer version and total price in cents. An idempotency key detects the same intention after a loss of response; an aggregate version protects the changed business state.

Starting point The last available night determines the concurrency test.

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.

Commands, retries and current state

Command and historical result

CommandCategory K-27 · Price Offer A-27 · Reservation R-27
Command → Reservierungs-APICheck content and expected version
Reservation APIAccept the command or recognise a replay
Reservierungs-API → ErgebnisjournalCommit the result before responding
Result journalFingerprint + stored record
identicalHistorical result
ModifiedConflict without effect
Response lossReplay after commit

The key binds the full content; identical repetition provides the stored receipt.

Confirm stay binds category, arrival, departure, price offer version and total price in cents. Same key points back to saved result; altered content branches to conflict.

Proposed API for this example

  1. POST/hotelinventar/{id}/commands

    Confirm stay

    Input
    Category, arrival, departure, price offer version and total price in cents; expected aggregate version, authorized role and stable command key.
    Result
    Durably stored business result and new version; version or content conflicts produce no partial effects. An accepted external request receives an open status.
    Retry behaviour
    The key is scoped to the actor, operation and business object. After authentication, first compare the existing result and canonical content: identical content returns the stored evidence; changed content produces a conflict. Only new keys trigger validation of the current version.
  2. GET/hotelinventar/{id}

    Read the current business state and reason for investigation.

    Input
    Authorised identity and business object.
    Result
    Reservation with current version, proofs and open processing reason.
    Retry behaviour
    Repeating a read creates no business change; access is checked again.

Additional state changes

OperationInputResult and protection
Create an offerCategory, arrival and departureStore price and fixed expiration time; no capacity commitment.
Cancel reservationReservation team, confirmed reservation, expected versionRelease the inventory allocated to every night exactly once, before arrival.
Confirm arrivalReception, confirmed reservation and versionConfirmed → arrived; cancellation is permitted only before arrival.
Complete the stayReception and documented departure completionArrived → completed; historical room-night occupancy is retained.

Create an offer

Input
Category, arrival and departure
Result and protection
Store price and fixed expiration time; no capacity commitment.

Cancel reservation

Input
Reservation team, confirmed reservation, expected version
Result and protection
Release the inventory allocated to every night exactly once, before arrival.

Confirm arrival

Input
Reception, confirmed reservation and version
Result and protection
Confirmed → arrived; cancellation is permitted only before arrival.

Complete the stay

Input
Reception and documented departure completion
Result and protection
Arrived → completed; historical room-night occupancy is retained.

Messages across the external boundary

Source contract
OpenTravel treats room stays, rates and date-specific availability as distinct domain elements. The local inventory contract belongs to this example design.
System responsibility
Reservation API locks category nights in date order, checks the remaining inventory for both nights and commits the reservation together with the channel request. After a lost response, the same key will deliver the same reservation. External channel success is reconciled separately.

Confirmation binds the price offer version

Confirmation binds the price offer version

Confirmation binds the price offer version.

Confirm stay can re-arrive after a lost response.

Category, arrival, departure, price offer version and total price in cents must remain identical on replay. The exercise specifies the input and expected result.

Alternative considered
A key stored only in volatile memory loses its evidence on restart.
Trade-off
The journal for Confirm stay requires permanent storage and access controls.
Reassess
The documented retry window and journal volume determine the future archiving strategy.

Try it yourself

Predict the results of an identical retry of “Confirm stay”, the same key with a different departure date, and a new key with an old version.

A hint for your attempt

Retry identity and current state require separate checks.

Compare with a possible solution
Identical
The saved result for reservation R-27 is returned; the effect is not repeated.
Changed
The same key with altered canonical content results in conflict.
New intent with a stale version
A new key with a stale version is rejected before any business change. The interface reloads the current state and asks the user to confirm the decision again.

Apply to your project

Which input fields make two change intentions different in your project?

Next: Cancellation releases the same nights once.