← Case study

01 · DOMAIN MODEL

Model the promises

Separate capacity, commitment, custody, and billing before choosing tables.

Learning objective

Model a partial receipt without counting the same position twice.

The engineering problem

An empty position can already be promised. A cancelled booking can still have goods in custody. A single status field cannot represent both facts.

STEP 1

Name four concepts

Capacity describes compatible physical positions. Commitment is a hold or unreceived reservation over an interval. Custody starts at actual acceptance and ends at recorded departure. Billing derives money from custody and completed operations.

STEP 2

Define the transitions

Quote → hold → confirmation changes promises. Receiving converts an unfulfilled allocation into custody. Closing receiving releases the unused balance. Cancellation releases unfulfilled promises while preserving goods already present.

STEP 3

State the invariant

A position has at most one pallet in current custody. A received pallet replaces its matching unreceived allocation. A forecast departure becomes a fact only when an operator records release.

YOUR TURN

Make the behavior visible.

  1. Reserve six positions and receive five pallets.
  2. Inspect five occupied positions and one unreceived commitment.
  3. Close receiving and verify the unused sixth position becomes available.
Open the sandbox ↗

Acceptance evidence

Five occupied + zero unreceived = five positions consumed. Cancelling the booking preserves those five pallets until release.

Read the working source.

These files belong to the downloadable PostgreSQL reference. The hosted companion has its own bounded state machine and persistence adapter.

Design review

Which record would be lost if reservation cancellation also deleted custody?

Review the tradeoff

Lifecycle promises and physical custody advance independently. Keeping them distinct preserves an overdue pallet and its charges when the original commercial promise changes.