Skip to main content

Use Cases

Thirteen use cases, one struct each, in internal/application/usecases. Each depends only on the domain and on application/ports — never on an adapter. Dependencies are plain struct fields, wired in cmd/order (main.go, wiring.go, planned_capacity.go, product_classification.go, release_confirmation.go, outbound_shipping.go) and, for GetOrder over MCP, in cmd/mcp.

Per ADR 0005, allocation and release are not public use cases. They are folded into one shared function, allocateAndRelease (allocation.go), that ReceiveOrder, RetryAllocation and ReleaseHeldOrder all call — a caller expresses one intent ("place an order", "retry a stuck one", "release a held one") and this service attempts allocation and then release as one flow. The usecases_wiring_integration_test.go suite (-tags=integration, Testcontainers Postgres, real OrderRepo/UnitOfWork wired like the composition root) executes these lifecycles end-to-end against real infrastructure.

#Use caseTriggerRaises
1ReceiveOrderPOST /ordersOrderReceived, then (best-effort) the allocation-pass events
2RetryAllocationPOST /orders/{id}/allocation-retriesOrderLineAllocated, OrderLineBackordered, OrderAllocated/OrderPartiallyAllocated, OrderAllocationPartiallyFailed
3ReleaseHeldOrderPOST /orders/{id}/releasesOrderLineBackordered (lost reservation), OrderAllocated/OrderPartiallyAllocated for the released lines
4CancelOrderDELETE /orders/{id}OrderCancelled
5GetOrderGET /orders/{id}, MCP get_order— (query)
6RepromiseOrderKafka TaskCPTMissed/PackageManifested on warehouse.fulfillment.eventsOrderRepromised
7ApplyPlannedCapacityKafka CapacityPlan*/CapacityShortageDetected on warehouse.warehouse-planning.events (opt-in)— (read model write)
8GetPlannedCapacityGET /planned-capacity?site=&from= (registered only when the read model is wired)— (query)
9OrderCapacityConstraintsevery order response, when the read model is wired— (query)
10ApplyProductClassificationKafka ProductClassified on warehouse.product-master.events (opt-in, PRODUCT_CLASSIFICATION_MODE=kafka)— (local copy write)
11ConfirmReleaseKafka WorkUnitCreated on warehouse.work-planning.events (opt-in, RELEASE_CONFIRMATION_MODE=kafka, off by default)— (process-manager write)
12FlagUnconfirmedReleasesthe housekeeping sweeper, every HOUSEKEEPING_INTERVAL (same opt-in)OrderReleaseUnconfirmed (analytics only)
13ConfirmShipmentKafka ShipmentConfirmed on warehouse.outbound-shipping.events (opt-in, OUTBOUND_SHIPPING_CONSUMER_MODE=kafka, off by default)OrderLineShipped, OrderShipped/OrderPartiallyShipped (local, not published)

Step-by-step diagrams for every row are on Sequence Diagrams.

1. ReceiveOrder(lines[], allowPartialShipment, releaseOnAllocation, requiredShipBy)​

Intake. Validates the intake intent (a held order must be ship-complete), then for every requested line looks up the SKU's product classification (fail-open), resolves its process path with PathSelectionPolicy over the active catalogue paths whose intake contains CUSTOMER_ORDER (shortest known CycleTimeP95 among eligible ones, ties to the lower PathId — ADR 0021, ADR 0042; pick when no catalogue is wired or no path declares CUSTOMER_ORDER), and rejects an inactive path (400 unknown-process-path) or a line no active path admits (422 line-ineligible-for-resolved-path) before anything is persisted. It then mints an OrderId, persists the order in Received status, and publishes OrderReceived unconditionally.

With Postgres, the call sits behind the Idempotency-Key middleware (ADR 0023): the header is required (400 idempotency-key-required), a replay returns the stored response, and the same key with a different body is 409 idempotency-key-reused (REST guideline 2.3; it was 422 before ADR 0048).

Request:

{
"allowPartialShipment": false,
"releaseOnAllocation": true,
"lines": [
{"sku": "SKU-1", "quantity": 2},
{"sku": "SKU-2", "quantity": 1, "giftWrap": true}
]
}

pathId is never part of the request — the path is resolved internally. Optional fields from ADR 0020: releaseOnAllocation (default true; false holds the order after allocation — it must then be ship-complete, else 422 held-order-must-be-ship-complete) and requiredShipBy (the promise is constrained to a CPT window at or before that instant; if none exists the order is still received and allocated, but the response carries no promiseDate).

In the same call, ReceiveOrder runs allocateAndRelease as a best-effort next step. A hard (non-business) failure in that step never fails ReceiveOrder itself — the order really was received. The failure is visible through OrderAllocationPartiallyFailed whenever some line was allocated first.

Response — 201 Created, Location: /orders/{id} — reflects whatever the allocation pass achieved:

{
"id": "ord-a1b2c3d4-0000-0000-0000-000000000001",
"status": "Released",
"allowPartialShipment": false,
"releaseOnAllocation": true,
"promiseDate": "2026-08-27T12:00:00Z",
"lines": [
{"lineNo": 1, "sku": "SKU-1", "quantity": 2, "pathId": "pick", "giftWrap": false, "status": "Released", "reservationId": "res-a1b2c3d4-0000-0000-0000-000000000009"},
{"lineNo": 2, "sku": "SKU-2", "quantity": 1, "pathId": "pick", "giftWrap": true, "status": "Released", "reservationId": "res-a1b2c3d4-0000-0000-0000-000000000010"}
]
}

Fails when: a line's SKU is empty, the order has no lines, the body is malformed or the resolved path is not active (400); a quantity is not greater than zero, a line is ineligible, or a held order allows partial shipment (422); or the order could not be persisted (500) — never because the implicit allocation pass hit a hard failure.

2. allocateAndRelease — the shared allocate-then-release flow​

Not a public use case (internal/application/usecases/allocation.go); it runs inside one UnitOfWork transaction.

  1. Calls inventory-storage's POST /reservations once per line to allocate, with this order's id as demandRef, the line's number as the optional lineNo (decision 18, ADR 0037) and a deterministic Idempotency-Key (ADR 0028). BR2: a 409 is the business fact "not enough usable stock" — that line becomes Backordered and the pass continues. Anything else is ambiguous: the pass hard-fails, keeps what genuinely allocated and raises OrderAllocationPartiallyFailed.
  2. Computes the promise — PromisePolicy.PromiseGroups (capability-derived CPT window per shipment group, lead time as fallback — ADR 0014/0017), or FeasibleBy when requiredShipBy is set (ADR 0020).
  3. If the order is held, saves and publishes the outcome with no released lines. Otherwise it reconfirms every line allocated in an earlier pass (a lapsed reservation now 409s and the line goes back to Backordered via LoseReservation), checks EnsureReleasable (BR3: a ship-complete order releases nothing while any line is unallocated) and releases every Allocated line with the pure domain transition Order.Release.
  4. Saves the order once (version-guarded, ADR 0024) and publishes OrderAllocated or OrderPartiallyAllocated with a lines[] payload of exactly what was released this pass. With RELEASE_CONFIRMATION_MODE=kafka (ADR 0043) it also opens a PENDING release_confirmations row for each line released in this pass, in the same unit of work, so the row commits or rolls back with the release.

A BR3 block is not an error: the order is saved Backordered and the HTTP caller sees a success code.

3. RetryAllocation(orderId)​

Re-attempts allocation for every Backordered line only — the single route from Backordered back to Allocated — then releases in the same call via allocateAndRelease. Unlike ReceiveOrder, this is an explicit recovery action: a hard failure does propagate to the caller.

Fails when: order unknown (404), no backordered line (409 no-backordered-lines), a concurrent writer won (409 concurrent-modification), inventory-storage fails non-409 (503 downstream-unavailable) or is not configured (503 downstream-not-configured).

4. ReleaseHeldOrder(orderId)​

The second half of the ADR 0020 hold. Reuses allocateAndRelease's release leg with no lines to allocate, so reconfirmation, BR3, the promise recompute and the outcome events are those of every other release. Idempotent for a held order whose lines are already released (200, no change, no event); an order that was never held answers 409 order-not-held. The hold flag is never cleared.

Fails when: order unknown (404), not held (409), concurrent writer (409 concurrent-modification), inventory-storage fails during reconfirm (503). A ship-complete held order that lost a reservation is not an error: nothing is released and the call returns 200 with the order Backordered — BR3 is a hold, not a problem type, so there is no ship-complete-blocked response anywhere in the REST contract.

5. CancelOrder(orderId)​

Checks EnsureCancellable first (BR6: 409 order-already-released if any line is Released or Shipped, before anything is revoked), then revokes every allocated line's reservation via DELETE /reservations/{id}, cancels every line and saves.

Response: 204 No Content.

Fails when: order unknown (404), any line released (409), a concurrent writer (409 concurrent-modification), a revoke fails (503) — earlier revocations stay in place and the caller retries.

6. GetOrder(orderId)​

Read-only. Returns the current Order, with the order-level status derived from line statuses at read time (Order.Status(), an if-chain written deliberately so the mutation gate can attribute its mutants). Also backs the MCP tool get_order (cmd/mcp, ADR 0010), whose wire contract is pinned end-to-end over the real Streamable HTTP transport by streamable_http_integration_test.go (-tags=integration).

Fails when: order unknown (404).

7. RepromiseOrder (Kafka-driven)​

Not reachable over HTTP. RepromiseConsumer (internal/adapters/inbound/kafka, group order-management-repromise) decodes TaskCPTMissed / PackageManifested from warehouse.fulfillment.events, maps the work-unit id back to an order line (ParseWorkUnitID), and RepromiseOrder recomputes that line's shipment-group promise, publishing OrderRepromised only if it moved (ADR 0018). Each inbound CloudEvents id is processed at most once (ports.RepromiseProcessedEvents); after 3 failed attempts the message is dead-lettered to warehouse.fulfillment.events.dlq.

8. ApplyPlannedCapacity (Kafka-driven, opt-in)​

Runs only when PLANNED_CAPACITY_CONSUMER_GROUP is set (ADR 0031). PlannedCapacityConsumer maps CapacityPlanCreated to a DRAFT window, CapacityPlanPublished/CapacityShortageDetected to a PUBLISHED one and CapacityPlanSuperseded to a terminal SUPERSEDED one that never constrains an order (ADR 0052); the use case validates the window, claims the event id (ports.PlannedCapacityProcessedEvents) and upserts it into planned_capacity_windows (last writer wins, a DRAFT never overwrites a PUBLISHED plan). No order changes and no event is raised.

9. GetPlannedCapacity and OrderCapacityConstraints (queries)​

GetPlannedCapacity serves GET /planned-capacity?site=&from= — the windows for one site that end after from (default now). OrderCapacityConstraints is called while building every order response: an order with a promise gets a capacityConstraint annotation listing the published shortage windows its promise overlaps, at the order's own fulfillmentSiteId or, for an order without one, the configured site (PLANNED_CAPACITY_SITE_ID, defaulting to DEFAULT_SITE_ID; ADR 0047). Neither changes a promise.

10. ApplyProductClassification (Kafka-driven, opt-in)​

Runs only when PRODUCT_CLASSIFICATION_MODE=kafka, which also requires PRODUCT_CLASSIFICATION_CONSUMER_GROUP and KAFKA_BROKERS (ADR 0036). ProductClassificationConsumer applies only com.warehouse.wms.product-master.product.ProductClassified from product-master's warehouse.product-master.events; every other type is committed past. The use case rejects an empty event id, an empty sku or a version below 1 (ErrInvalidProductClassification, logged and skipped), then, in one UnitOfWork, claims the CloudEvents id (ports.ProductClassificationProcessedEvents) and upserts the row into product_classification_copy only when the incoming version is greater than the stored one (ports.ProductClassificationCopy). No order changes and no event is raised. ReceiveOrder reads the copy through ports.ProductClassificationLookup; an unknown SKU fails open.

Fails when: a transient error (database down, deadlock) — the same message is retried with backoff and the offset is committed only after success.

11. ConfirmRelease (Kafka-driven, opt-in, off by default)​

Runs only when RELEASE_CONFIRMATION_MODE=kafka, which also requires RELEASE_CONFIRMATION_CONSUMER_GROUP, KAFKA_BROKERS, DATABASE_URL and EVENT_PUBLISHER=kafka (ADR 0043). ReleaseConfirmationConsumer acts only on wes-work-planning's com.warehouse.wes.work-planning.workunit.WorkUnitCreated and reads its two optional fields, reference (the order id) and line_no. The use case rejects an empty event id (ErrInvalidReleaseConfirmation, dead-lettered). An event without reference or a positive line_no is ignored and counted ignored_no_reference; one for a line this service never opened a row for (transfer, RELOCATE or legacy work, or an order released before the loop was on) is ignored_unknown_line. Otherwise, in one UnitOfWork, it reads the release_confirmations row, claims the CloudEvents id (ports.ReleaseConfirmationProcessedEvents) and sets the row CONFIRMED (confirmed), or clears an UNCONFIRMED one (late_confirmed, logged at WARN). A redelivered id or a second event for a CONFIRMED line is a duplicate no-op. The order is never loaded or changed and no event is raised.

Fails when: a transient error — retried in process up to 3 attempts, then the message goes to warehouse.work-planning.events.dlq; a shutdown never dead-letters it.

12. FlagUnconfirmedReleases (housekeeping, opt-in, off by default)​

Not reachable over HTTP or Kafka. The housekeeping sweeper (ADR 0032) calls it once per pass, after its deletes, only when RELEASE_CONFIRMATION_MODE=kafka and RELEASE_CONFIRMATION_TIMEOUT (default 15m) is above 0. In batches of 100, each in one UnitOfWork, it claims PENDING rows released longer ago than the timeout (FOR UPDATE SKIP LOCKED, so several replicas flag a line exactly once), moves each to UNCONFIRMED and raises one analytics-only OrderReleaseUnconfirmed through the outbox in the same transaction. After the commit it logs release unconfirmed at ERROR and increments order.release_confirmation.unconfirmed. It is a fact, never an action: nothing is cancelled, re-released or retried, and the order is not touched. With the default 1h HOUSEKEEPING_INTERVAL a line is flagged up to 1h15m after release; use about 5m when the loop is on.

13. ConfirmShipment (Kafka-driven, opt-in, off by default)​

Runs only when OUTBOUND_SHIPPING_CONSUMER_MODE=kafka, which also requires OUTBOUND_SHIPPING_CONSUMER_GROUP, KAFKA_BROKERS and DATABASE_URL (ADR 0051). OutboundShippingConsumer acts only on outbound-shipping's com.warehouse.wms.outbound-shipping.outboundload.ShipmentConfirmed and reads load_id and orders[].order_id. In one UnitOfWork the use case claims the raw CloudEvents id in shipment_processed_events (ports.ShipmentProcessedEvents; one claim covers every order the event names), then for each named order moves its Released lines to Shipped (Order.ShipAll), saves it and raises OrderLineShipped per moved line plus one OrderShipped (every line shipped) or OrderPartiallyShipped, each carrying the load_id. Outcomes per order, also the structured-log values: shipped, no_change (first-seen event, order already fully shipped), duplicate (id already claimed; the whole event is a no-op), ignored_no_orders (empty orders[]), ignored_unknown_order and ignored_not_shippable (no Released or Shipped line, or cancelled). The skip outcomes are logged at WARN and committed past; the other orders in the event still ship. None of the three events is published.

The same consumer routes PackageMissedLoad (source_order_id, a bare order id) to RepromiseOrder.ExecuteForMissedLoad, the order-wide variant of use case 6: every promise group of the order is recomputed, and each group whose promise moved publishes one OrderRepromised with reason PackageMissedLoad.

Fails when: a transient error — retried in process, then the message goes to warehouse.outbound-shipping.events.dlq; a shutdown never dead-letters it.

REST endpoint summary​

MethodPathUse case
POST/ordersReceiveOrder (allocates + releases automatically)
GET/orders/{id}GetOrder
POST/orders/{id}/allocation-retriesRetryAllocation
POST/orders/{id}/releasesReleaseHeldOrder (held orders only, ADR 0020)
DELETE/orders/{id}CancelOrder
GET/planned-capacityGetPlannedCapacity (ADR 0031)
GET/healthzLiveness probe
GET/readyzReadiness probe (200 ready, 503 not_ready once shutdown starts)

POST /orders/{id}/allocate no longer exists, and the pre-ADR-0005 general-purpose release endpoint is gone. The current /release path is ADR 0020's held-order release only. The full contract, generated from apis/openapi.yaml, is on the API Reference pages.