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
The offer freezes the price; the category-night inventory lists the quantity available each night.
Domain entities and relationships
| Entity | Authoritative attributes | Relationship |
|---|---|---|
| Room category and night | K-27 + date of the night; inventory and active occupancy | For each stay, all affected night rows are locked in date order. |
| Price offer | A-27; two nights, 24000 cents, expiration time | Designates price and stay; does not reserve capacity itself. |
| Reservation | R-27; Guest reference, offer reference and status | A confirmed reservation occupies inventory for each night. |
| Inventory movement | Reservation, night, debit or one-off release | Cancellation 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 point | Target | Precondition |
|---|---|---|
| Offered | bestätigt | The offer is still valid and all nights are atomically available. |
| Offered | Decayed | The time limit for the offer has been reached. |
| bestätigt | storniert | The reservation team confirms cancellation before arrival and releases all nights once. |
| bestätigt | angereist | Reception confirms the arrival. |
| angereist | abgeschlossen | Reception confirms completion of the stay. |
| expired, cancelled or completed | terminal | New 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.
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?