0033. Consume NIP WorkDemandReleased into transfer-referenced work units
Status
Accepted.
Context
network-inventory-planning (NIP) plans and approves inter-site inventory
transfers. Executing a transfer needs real warehouse work — picking at the
origin site, dispatching/loading, receiving at the destination — and that
work is exactly what this bounded context exists to plan, pool and release.
NIP therefore publishes WorkDemandReleased
(com.warehouse.wes.network-inventory-planning.workdemand.WorkDemandReleased,
dataschema urn:warehouse:network-inventory-planning:events:WorkDemandReleased:v1)
on warehouse.network-inventory-planning.events, carrying
{demand_id, work_kind, transfer_ref, path_id, site_id, cpt, sku, quantity},
where work_kind is one of TRANSFER_PICK | TRANSFER_DISPATCH | TRANSFER_ARRIVAL.
This is the same integration shape as order-management's
ADR-0031: an upstream context
releases work by event, and this service enqueues it through the existing
EnqueueWorkUnit path rather than gaining a second admission path.
Decision
-
A fifth consumed topic. The inbound
Consumeralso readswarehouse.network-inventory-planning.events(cloudevents.TopicNetworkDemandEvents), with its own<topic>.dlqwriter, its ownhandleNetworkDemandEvent, and unknowntypes ignored as usual. -
ApplyWorkDemandReleased, besideApplyOrderAllocated. The handler dispatches to a new use case with the same skeleton:onceAtomicallybrackets the processed-event mark and the enqueue in ONE atomic scope (ADR-0028), thepath_idis validated against the process-path catalogue (ADR-0012) and thework_kindagainst the declared enum BEFORE anything is enqueued, and the reuse target is the existingEnqueueWorkUnit— no new admission path, no new aggregate. -
Deterministic id:
work_unit_id = demand_id, withreference = demand_idas the generic operator ref (so the existingGET /work-units?reference=lookup serves transfer demands unchanged). Idempotency at two levels, exactly like ADR-0031: the CloudEventsidmark catches redelivery, andrelease.ErrDuplicateEntryfor the deterministic id (a DIFFERENT event carrying the same demand) is a benign no-op, never a stall. -
Transfer metadata is additive on
WorkUnit, not a new invariant.transfer_ref,work_kind,site_id,quantityfollow theSetSKU/SetGiftWrapdiscipline: optional fields with zero-value defaults, threaded throughEnqueueWorkUnitRequest, persisted by migration0011(allNOT NULL DEFAULT— every existing row and writer keeps working), rehydrated by the Postgres and memory repos (work_kindvalidated on read likestate), and never part of the aggregate's own lifecycle rules.skualready existed. -
WorkReleasedstays v1 — additive optional fields only.workReleasedDatagainswork_kind,transfer_ref,site_id,quantity, present ONLY on a transfer-referenced unit (work_kind != ""is the discriminator). Thetype,dataschema urn:warehouse:wes-work-planning:events:WorkReleased:v1and required{path_id, work_unit_id, cpt, ref}are unchanged, so the payload of every order-driven unit is byte-identical to before this feature existed (pinned by a golden byte-compat test), and consumers that ignore unknown fields see no difference at all. -
Fail-loud contract. An unknown
path_idorwork_kindis deterministic poison: the handler returns an error, the message is retried and then dead-lettered — never silently enqueued into a pool nothing downstream services (the ADR-0017 rationale, applied to a new inbound stream). -
Fire-and-forget, like ADR-0031: no reply event to NIP. The published
WorkReleased(now carrying the transfer context) is the only observable signal, and it is the same signal every otherEnqueueWorkUnitcaller relies on.
Consequences
- fulfillment-execution (the
WorkReleasedconsumer) can recognize transfer tasks bywork_kindwithout any lookup, or ignore the fields entirely — both are safe. - The AsyncAPI contract documents the consumed message and the optional fields; the catalogue fitness rule is unaffected (the NIP type is consumed, not declared by this service).
- A future NIP-side payload change rides the same additive discipline: optional fields on the same v1 dataschema, byte-compat preserved for every pre-existing unit.
Alternatives considered
- A dedicated
TransferWorkUnitaggregate — rejected: transfers are the same releasable unit of work with extra descriptive context; a second aggregate would duplicate the pool, release policy and completion loop wholesale. - Replying to NIP on enqueue — rejected for the same fire-and-forget
reasons as ADR-0031; the outboxed
WorkReleasedis the signal. - Bumping WorkReleased to v2 — rejected: additive optional fields on v1 are backward compatible by construction; a v2 would force every consumer to migrate for nothing.