Skip to main content

Domain events

Synced from network-inventory-planning

This page is a copy of docs/docs/ddd/domain-events.md on develop, derived from that repository's code. Edit it there, then re-sync.

Every event this context publishes or consumes. All are CloudEvents 1.0 in structured content mode (content-type: application/cloudevents+json; charset=UTF-8) with source=/warehouse/network-inventory-planning on what it publishes. The published catalogue is pinned by ADR 0004 and an architecture fitness test (internal/architecture/catalogue_fitness_test.go): adding, renaming or versioning a published type is one change across apis/asyncapi.yaml, the emitting code and that ADR.

Published on warehouse.network-inventory-planning.events​

All through the transactional outbox, in the same transaction as the state change that justifies them.

TypeKafka keyRaised whenConsumer
com.warehouse.wes.network-inventory-planning.transfer.TransferPlanApprovedtransfer_idan operator approved a proposal (APPROVED)none in the fleet today
com.warehouse.wes.network-inventory-planning.transfer.TransferAllocationRequestedtransfer_line_id (<transfer_id>:1)the saga asks for origin stock (ALLOCATING, same transaction)inventory-storage
com.warehouse.wes.network-inventory-planning.workdemand.WorkDemandReleaseddemand_id (<transfer_id>:pick / :dispatch)pick leg with ALLOCATED, dispatch leg with PICKEDwes-work-planning

dataschema is urn:warehouse:network-inventory-planning:events:<EventName>:v1. The workdemand entity segment is the one WES's consumed contract names.

Payloads (apis/asyncapi.yaml, internal/adapters/outbound/kafka/publisher.go):

  • TransferPlanApproved: transfer_id, origin_site_id, destination_site_id, sku, quantity, policy_version, operator_reason (may be empty), proposal_as_of.
  • TransferAllocationRequested: exactly inventory-storage's five fields, transfer_id, transfer_line_id, origin_site_id, sku, quantity.
  • WorkDemandReleased: exactly WES's eight fields, demand_id, work_kind (TRANSFER_PICK or TRANSFER_DISPATCH), transfer_ref, path_id, site_id (the origin), cpt (triggering fact time + the leg's offset), sku, quantity (allocated for pick, picked for dispatch).

Published on warehouse.network-inventory-planning.analytics (ADR 0007)​

Saga-health occurrences for this context's own projector, not an integration contract. dataschema is urn:warehouse:network-inventory-planning:analytics:<EventName>:v1.

TypeKeyDataRaised when
...saga.TransferStateAdvancedtransfer_idtransfer_id, from (empty for the creation entry), to, age_seconds (since creation)each transition recorded by ApproveTransfer (→DRAFT, →PROPOSED, →APPROVED, →ALLOCATING), ApplyTransferAllocation (→ALLOCATED) and ApplyTransferPick (→PICKED)
...saga.TransferStuckDetectedtransfer_idtransfer_id, state, age_seconds (since updated_at), threshold_secondseach health tick, for each non-terminal transfer past its threshold
...saga.RebalanceRunCompletedrun_idrun_id, proposal_count, rejected_count, stale_factsa scheduled rebalance completed (a FAILED run publishes nothing)

IN_TRANSIT, ARRIVED, RECEIVED and UNFULFILLABLE produce no TransferStateAdvanced: those use cases are wired without a publisher in cmd/network-inventory-planning/main.go, so the analytics funnel stops at PICKED.

Not published​

TransferProposed, OriginReservationRequested and any transfer-completed or transfer-cancelled integration event are not in the AsyncAPI document. A proposal is advisory and never published.

Consumed​

Decoded as CloudEvents structured mode only, dispatched on the full type, deduplicated on the CloudEvents id in processed_events in the same unit of work, and committed only after that transaction settles.

TypeTopicProducerEffect
com.warehouse.wms.facility-layout.site.SiteCapabilityChangedwarehouse.facility.eventsfacility-layoutupsert site_capability; a greater capability_revision wins
com.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChangedwarehouse.order-management.eventsorder-managementupsert site_sku_demand per (source_order_id, line_no), newest CloudEvents time wins (an older event is a no-op, ADR 0014); REMOVED contributes no units
com.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanPublishedwarehouse.warehouse-planning.eventswarehouse-planningupsert published_capacity_plan per plan_id, newer published_at wins; no site_id → excluded
com.warehouse.wms.inventory-storage.reservation.TransferStockAllocatedwarehouse.inventory.eventsinventory-storageALLOCATING → ALLOCATED; reservation, allocations, expiry; releases the pick demand
com.warehouse.wms.inventory-storage.reservation.TransferStockAllocationRejectedwarehouse.inventory.eventsinventory-storageALLOCATING → UNFULFILLABLE with a closed reason; an unknown reason is logged and skipped
com.warehouse.wes.fulfillment-execution.transfer.TransferPickedwarehouse.fulfillment.eventsfulfillment-executionALLOCATED → PICKED; picked quantity (short allowed); releases the dispatch demand
com.warehouse.wes.fulfillment-execution.transfer.TransferDispatchedwarehouse.fulfillment.eventsfulfillment-executionPICKED → IN_TRANSIT
com.warehouse.wes.fulfillment-execution.transfer.TransferArrivedwarehouse.fulfillment.eventsfulfillment-executionIN_TRANSIT → ARRIVED; reserved, may never fire
com.warehouse.wms.inventory-storage.stock.TransferReceiptStagedwarehouse.inventory.eventsinventory-storageIN_TRANSIT → ARRIVED
com.warehouse.wms.inventory-storage.stock.TransferStockStowedwarehouse.inventory.eventsinventory-storageARRIVED → RECEIVED; stow allocations persisted

Whichever of TransferArrived and TransferReceiptStaged arrives first drives the arrival; the other is skipped as out of order. nip-projector consumes the three saga.* types from the analytics topic. Failure handling per consumer is in Ecosystem integration.