Skip to main content

Domain Events

This context declares fifteen past-tense domain events in internal/domain/shared/events.go and consumes fourteen CloudEvents types from six sibling contexts. Every Kafka message, in and out, is a CloudEvents 1.0 event in structured content mode (ADR 0030), built and parsed only by internal/adapters/kafka/cloudevents:

  • specversion 1.0; id a UUID minted when the event is encoded (and stored in the outbox row, so a redelivery keeps it); source /warehouse/order-management; type com.warehouse.wes.order-management.order.<EventName>; subject the order id; time the domain occurred-at (UTC); datacontenttype application/json; dataschema urn:warehouse:order-management:<events|analytics>:<EventName>:v1.
  • Kafka header content-type: application/cloudevents+json; charset=UTF-8; W3C trace context in traceparent/tracestate.
  • Kafka key = the order id on both outbound topics, with the Hash balancer, so one order's events stay on one partition (ADR 0027). The one exception is SiteSkuDemandChanged (ADR 0035): its subject and key are the line-scoped <source_order_id>/line/<line_no>, because the LINE is that stream's ordering unit.

How events leave the service​

ports.EventPublisher is selected by EVENT_PUBLISHER in cmd/order:

ConfigurationPublisherDelivery
EVENT_PUBLISHER=log (default)events.LogPublisherJSON log line only
kafka with DATABASE_URLpostgres.OutboxPublisher + postgres.OutboxRelayone outbox_events row per (event x topic) in the same transaction as the Order save, drained to Kafka by the relay (ADR 0022)
kafka without DATABASE_URLkafka.FanOutPublisherwritten directly to both topics

Two encoders decide what goes where: kafka.Publisher (integration topic) accepts only OrderAllocated, OrderPartiallyAllocated, OrderRepromised and SiteSkuDemandChanged; kafka.AnalyticsPublisher (analytics topic) accepts all eleven Order* events (the demand projection is integration-only).

Published events​

EventFull CloudEvents typeTopicsProducing use caseKnown consumers
OrderReceivedcom.warehouse.wes.order-management.order.OrderReceivedanalyticsReceiveOrderorder-projector
OrderLineAllocatedcom.warehouse.wes.order-management.order.OrderLineAllocatedanalyticsallocation passorder-projector
OrderLineBackorderedcom.warehouse.wes.order-management.order.OrderLineBackorderedanalyticsallocation pass, reconfirm before releaseorder-projector
OrderAllocatedcom.warehouse.wes.order-management.order.OrderAllocatedintegration + analyticsallocation pass when the order ends Allocated or Releasedwes-work-planning, order-projector
OrderPartiallyAllocatedcom.warehouse.wes.order-management.order.OrderPartiallyAllocatedintegration + analyticsallocation pass when the order ends PartiallyAllocated or PartiallyReleasedwes-work-planning, order-projector
OrderAllocationPartiallyFailedcom.warehouse.wes.order-management.order.OrderAllocationPartiallyFailedanalyticsallocation pass, hard failure after some lines allocatedorder-projector
OrderCancelledcom.warehouse.wes.order-management.order.OrderCancelledanalyticsCancelOrderorder-projector
OrderRepromisedcom.warehouse.wes.order-management.order.OrderRepromisedintegration + analyticsRepromiseOrderorder-projector, exception-management (auto-resolve correlation)
OrderLineReleasedcom.warehouse.wes.order-management.order.OrderLineReleasedanalyticsallocation pass, once per line released in that passorder-projector
OrderReleasedcom.warehouse.wes.order-management.order.OrderReleasedanalyticsallocation pass, when that pass leaves every line Releasedorder-projector
OrderReleaseUnconfirmedcom.warehouse.wes.order-management.order.OrderReleaseUnconfirmedanalyticsFlagUnconfirmedReleases, the release-confirmation timeout inside the housekeeping sweep, once per line, only while RELEASE_CONFIRMATION_MODE=kafka (ADR 0043)none: the order-projector ignores the type
OrderLineShippedcom.warehouse.wes.order-management.order.OrderLineShippednone: raised through the events port, then skipped by both publishers (outside their contracts)ConfirmShipment, once per line moved Released -> Shipped (ADR 0051), only while OUTBOUND_SHIPPING_CONSUMER_MODE=kafkanone
OrderShippedcom.warehouse.wes.order-management.order.OrderShippednone (as above)ConfirmShipment, when the order ends Shipped; carries the load_idnone
OrderPartiallyShippedcom.warehouse.wes.order-management.order.OrderPartiallyShippednone (as above)ConfirmShipment, when some lines shipped and the order is not Shipped; carries the load_idnone
SiteSkuDemandChangedcom.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChangedintegrationallocation pass (intake/retry), RepromiseOrder's moved group, CancelOrder — for an order carrying a caller-assigned site (ADR 0044) or while DEMAND_PROJECTION_SITE_ID is set (ADR 0035)site-level planning consumers (none in this fleet yet)

Topics: integration = warehouse.order-management.events, analytics = warehouse.order-management.analytics. "Allocation pass" is the shared allocateAndRelease flow run by ReceiveOrder, RetryAllocation and ReleaseHeldOrder. Release is announced to wes-work-planning only through OrderAllocated/OrderPartiallyAllocated and their lines[]. OrderLineReleased/OrderReleased are analytics-only facts raised at the same release transition (publishReleaseFacts, in the same unit of work as the aggregate save, so they go through the outbox, ADR 0034); they feed the funnel's linesReleased/ordersReleased. Nothing is raised when the release leg releases nothing (BR3-blocked ship-complete order, held order, a reservation lost at reconfirm), and a line is announced only in the pass that releases it.

OrderLineShipped, OrderShipped and OrderPartiallyShipped are local domain facts: ADR 0051 adds them to the events port but changes neither the integration contract nor the analytics contract, so both publishers skip them and the funnel still ends at Released. The aggregate gains the matching line status Shipped and the derived order statuses Shipped and PartiallyShipped, reachable only through the outbound-shipping consumer.

OrderReleaseUnconfirmed is the one event not raised by an allocation pass. It is an analytics-only fact that a released line was never confirmed by wes-work-planning's WorkUnitCreated within RELEASE_CONFIRMATION_TIMEOUT (default 15m); the housekeeping sweep (ADR 0032) raises it exactly once per line, in the same transaction that flips the line's release_confirmations row to UNCONFIRMED. Nothing is cancelled, re-released or retried because of it, it is not retracted if a late WorkUnitCreated arrives, and the integration topic keeps its contract. It exists only while RELEASE_CONFIRMATION_MODE=kafka; the consumer ships off by default.

Integration payloads (warehouse.order-management.events)​

OrderAllocated and OrderPartiallyAllocated share one data shape (allocationData in internal/adapters/outbound/kafka/publisher.go):

FieldTypeNotes
order_idstring
promise_dateRFC 3339latest cutoff across promise groups
promise_cpt_idstring, omitted when emptyabsent for a LeadTime promise
promise_basisCapability, LeadTime or Network, omitted when empty
lines[]arraylines released in this pass (empty for a held order)
lines[].line_no, sku, path_id, gift_wrapthe original four frozen fields wes-work-planning decodes
lines[].fulfillment_classSINGLE, SAME_SKU_MULTI, MULTI_LINE_MULTIadditive, ADR 0008
lines[].promise_cpt_id, promise_basis, promise_cutoff_atomitted when emptyper-line group attribution, ADR 0017

OrderPartiallyAllocated's allocated_lines/backordered_lines counts travel only on the analytics topic; on the integration topic both events have exactly the fields above.

{
"order_id": "ord-a1b2c3d4-0000-0000-0000-000000000001",
"promise_date": "2026-08-27T12:00:00Z",
"promise_cpt_id": "sp1-1200",
"promise_basis": "Capability",
"lines": [
{"line_no": 1, "sku": "SKU-1", "path_id": "pick", "gift_wrap": false,
"fulfillment_class": "SINGLE", "promise_cpt_id": "sp1-1200",
"promise_basis": "Capability", "promise_cutoff_at": "2026-08-27T12:00:00Z"}
]
}

OrderRepromised (repromisedData): order_id, cpt_id_old and cpt_id_new (each omitted when that side is a LeadTime promise), and reason (TaskCPTMissed or PackageManifested).

SiteSkuDemandChanged (ADR 0035, siteSkuDemandData): source_order_id, line_no, site_id, sku, demanded_units, due_at (RFC 3339 — the line's own promise-group cutoff where one is recorded, else the order-level promise date), state (ACTIVE or REMOVED), and assignment_version (order-site-v1 when the order carries a caller-assigned fulfillment site, ADR 0044; else static-site-v1). PII-free by construction; subject/Kafka key = <source_order_id>/line/<line_no>. Emitted in the same order-save/outbox transaction as the allocation, re-promise, or cancellation that produced the line state, and only for an order that carries a fulfillment site or while DEMAND_PROJECTION_SITE_ID is configured.

wes-work-planning never receives a work-unit id: it rebuilds {order_id}-line-{line_no} itself, and this repo's usecases.WorkUnitID must produce the byte-identical string. usecases.ParseWorkUnitID reverses it for the re-promise consumer.

Analytics payloads (warehouse.order-management.analytics)​

Built by AnalyticsPublisher.marshalData, enriched with a path_id looked up through OrderRepo:

Eventdata fields
OrderReceivedorder_id, path_id (first line), line_count
OrderAllocatedorder_id, path_id (first released line, else first line), promise_basis, promise_cutoff_at (Capability basis only), split_shipment
OrderPartiallyAllocatedas OrderAllocated plus allocated_lines, backordered_lines
OrderAllocationPartiallyFailedorder_id, path_id, allocated_lines, remaining_lines
OrderCancelledorder_id, path_id, revoked_reservations
OrderLineAllocatedorder_id, line_no, path_id (that line), sku
OrderLineBackorderedorder_id, line_no, path_id (that line), sku
OrderRepromisedorder_id, cpt_id_old, cpt_id_new, reason
OrderLineReleasedorder_id, line_no, path_id, work_unit_id
OrderReleasedorder_id, path_id
OrderReleaseUnconfirmedorder_id, line_no, path_id, work_unit_id ({order_id}-line-{line_no}), released_at (when the line was released; the CloudEvents time is when it was flagged). subject and Kafka key = the order id; dataschema urn:warehouse:order-management:analytics:OrderReleaseUnconfirmed:v1

The sole consumer is cmd/order-projector (inbound/kafka.AnalyticsConsumer, group order-management-analytics, from the first offset), which de-duplicates on the CloudEvents id; see Order Funnel report. It ignores OrderReleaseUnconfirmed: no funnel column reads it.

Consumed events​

ProducerFull CloudEvents typeTopicPayload fields readAdapter, groupEffect
fulfillment-executioncom.warehouse.wes.fulfillment-execution.task.TaskCPTMissedwarehouse.fulfillment.eventstask_id, order_ref, task_type, cptinbound/kafka.RepromiseConsumer, stable group order-management-repromiseRepromiseOrder
fulfillment-executioncom.warehouse.wes.fulfillment-execution.package.PackageManifestedwarehouse.fulfillment.eventspackage_id, order_refsameRepromiseOrder
process-path-managementcom.warehouse.wes.process-path-management.processpath.ProcessPathCreatedwarehouse.process-path-management.eventspath_id, match_prefix, cycle_time_p95, eligibility (max_units_per_line, required_product_attributes, excluded_product_attributes, non_sortable), destination_location_roleoutbound/kafkacatalog, per-process group order-management-process-path-catalogue-*upsert catalogue cache
process-path-managementcom.warehouse.wes.process-path-management.processpath.ProcessPathUpdatedsamesamesameupsert catalogue cache
process-path-managementcom.warehouse.wes.process-path-management.processpath.ProcessPathDeactivatedsamepath_idsameremove from catalogue cache
process-path-managementcom.warehouse.wes.process-path-management.cptschedule.CPTScheduleChangedsamesite_id, timezone, cutoffs[] (cpt_id, local_time, days_of_week, ship_method, eligible_path_ids)outbound/kafkacptschedule, per-process group order-management-cpt-schedule-*replace site CPT schedule
wes-work-planningcom.warehouse.wes.work-planning.workpool.PathCapacityChangedwarehouse.work-planning.eventspath_id, cutoff_at, remaining_units, knownoutbound/kafkapathcapacity, per-process group order-management-path-capacity-*remaining capacity keyed by path and cutoff
wes-work-planningcom.warehouse.wes.work-planning.workunit.WorkUnitCreatedwarehouse.work-planning.eventsthe optional reference (the order id) and line_no; path_id and work_unit_id are not readinbound/kafka.ReleaseConfirmationConsumer, stable group from RELEASE_CONFIRMATION_CONSUMER_GROUP (only with RELEASE_CONFIRMATION_MODE=kafka; off by default)ConfirmRelease: the matching PENDING or UNCONFIRMED release_confirmations row becomes CONFIRMED (ADR 0043)
outbound-shippingcom.warehouse.wms.outbound-shipping.outboundload.ShipmentConfirmedwarehouse.outbound-shipping.eventsload_id and orders[].order_id (the distinct source order ids); site_id, cpt_id, carrier, trailer_id, seal_number, departed_at and version are not readinbound/kafka.OutboundShippingConsumer, stable group from OUTBOUND_SHIPPING_CONSUMER_GROUP (no default)ConfirmShipment: ship every named order's Released lines in one unit of work
outbound-shippingcom.warehouse.wms.outbound-shipping.shippingpackage.PackageMissedLoadsamesource_order_id (a bare order id) and cutoff (logged, not used as the new promise); package_id, load_id, site_id, detected_at and version are not readsameRepromiseOrder.ExecuteForMissedLoad: re-promise every group of that order
warehouse-planningcom.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanCreatedwarehouse.warehouse-planning.eventsplan_id, warehouse_id, location, path_id, window_start, window_end, assigned_demand, capacity_over_window, shortage, bottleneck_stepinbound/kafka.PlannedCapacityConsumer, group from PLANNED_CAPACITY_CONSUMER_GROUPupsert window as DRAFT
warehouse-planningcom.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanPublishedsamesamesameupsert window as PUBLISHED
warehouse-planningcom.warehouse.wes.warehouse-planning.capacityplan.CapacityShortageDetectedsamesamesameupsert window as PUBLISHED
warehouse-planningcom.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanSupersededsamesamesamemove the plan's row to terminal SUPERSEDED (tombstone if unseen; ADR 0052)
product-mastercom.warehouse.wms.product-master.product.ProductClassifiedwarehouse.product-master.eventssku, handling_tags, temperature_class, dot_hazard_class, version (classification_source decoded, not stored)inbound/kafka.ProductClassificationConsumer, group from PRODUCT_CLASSIFICATION_CONSUMER_GROUP (only with PRODUCT_CLASSIFICATION_MODE=kafka)ApplyProductClassification: version-guarded upsert into product_classification_copy (ADR 0036)

com.warehouse.wes.warehouse-planning.capacityplan.BottleneckDetected is recognised and ignored, and so are product-master's other types on its topic (ProductRegistered, ProductDescriptionChanged, ProductDimensionsDeclared, ProductMeasured). Unknown types are ignored on every consumer.

Delivery guarantees by consumer:

  • RepromiseConsumer and PlannedCapacityConsumer — stable shared groups, idempotent on the CloudEvents id (repromise_processed_events, planned_capacity_processed_events), up to 3 attempts, then the raw message goes to the .dlq topic (warehouse.fulfillment.events.dlq, warehouse.warehouse-planning.events.dlq) with x-dlq-* headers and the offset is committed (ADR 0025). A non-CloudEvents message is dead-lettered immediately.
  • ProductClassificationConsumer — stable shared group from PRODUCT_CLASSIFICATION_CONSUMER_GROUP (no default), idempotent on the CloudEvents id (product_classification_processed_events) in the same transaction as the upsert. A transient failure retries the same message until it succeeds; a non-CloudEvents message or an invalid payload is logged at WARN and committed past. No dead-letter topic: the next ProductClassified for the SKU repairs the copy (ADR 0036).
  • Catalogue, CPT-schedule and path-capacity caches — run only with PATH_CATALOGUE_SOURCE=kafka, each under a fresh per-process group that replays from the first offset; cmd/order waits up to 60s for each to catch up before serving. Undecodable messages are logged and skipped.
  • OutboundShippingConsumer (ADR 0051; runs only with OUTBOUND_SHIPPING_CONSUMER_MODE=kafka, off by default) — stable shared group from OUTBOUND_SHIPPING_CONSUMER_GROUP (no default). ShipmentConfirmed is idempotent on the raw CloudEvents id in shipment_processed_events, claimed once for every order the event names, in the same transaction as the state changes; a re-delivery under a new id for an already shipped order is a no_change outcome. PackageMissedLoad goes through the existing repromise_processed_events gate. It dispatches on the two full types only; every other type on the topic is committed past. A ShipmentConfirmed naming an unknown order or an order with no Released line is logged at WARN and skipped (the other orders in the event still ship), never dead-lettered. A non-CloudEvents message or an undecodable data goes to warehouse.outbound-shipping.events.dlq; a transient failure retries in process and is then dead-lettered. Shutdown never dead-letters a message.
  • ReleaseConfirmationConsumer (ADR 0043; runs only with RELEASE_CONFIRMATION_MODE=kafka, off by default) — stable shared group from RELEASE_CONFIRMATION_CONSUMER_GROUP (no default), idempotent on the CloudEvents id (release_confirmation_processed_events) in the same transaction as the state change, so a rollback un-claims the id. It acts on the full type …workunit.WorkUnitCreated only; every other type on the topic is committed past. A WorkUnitCreated without reference or a positive line_no, or for a line this service never opened a confirmation for (transfer, RELOCATE and legacy work, orders released before the loop was on), is ignored and counted, never dead-lettered. A non-CloudEvents message or an undecodable data goes to warehouse.work-planning.events.dlq with x-dlq-* headers; a transient failure retries in process (3 attempts) and is then dead-lettered. Shutdown never dead-letters a message.

order_ref on the fulfillment events is a work-unit id ({orderId}-line-{lineNo}), not a bare order id; a value that does not parse is logged and skipped.

Which use case emits what​

Source: internal/application/usecases/*.go, internal/adapters/outbound/kafka/publisher.go, analytics_publisher.go. Omits: the outbox hop (diagram 9 on Sequence Diagrams). The SiteSkuDemandChanged emissions are conditional on DEMAND_PROJECTION_SITE_ID (ADR 0035), and OrderReleaseUnconfirmed on RELEASE_CONFIRMATION_MODE=kafka (ADR 0043), and the three shipped facts on OUTBOUND_SHIPPING_CONSUMER_MODE=kafka (ADR 0051).

Naming and payload shape​

Every event embeds an occurredAt from the injected Clock port, so ordering is a domain fact, not an infrastructure artefact. Payloads carry the minimum needed to make the event self-describing — OrderLineAllocated carries OrderID, LineNo, SKU, Quantity and the Supplier's ReservationID, never an Order snapshot. OrderAllocated/ OrderPartiallyAllocated carry Lines []ReleasedLine because that is the integration payload wes-work-planning needs.

Why choreography, not a synchronous call​

Before ADR 0005 release was a synchronous POST /paths/{pathId}/work-units call to wes-work-planning, which made release depend on that Supplier's availability at the exact moment of release. Release is now a published fact that wes-work-planning consumes on its own schedule. It is fire-and-forget by default: there is no reply event back. With RELEASE_CONFIRMATION_MODE=kafka (ADR 0043, available, off by default) this service instead watches for wes-work-planning's own WorkUnitCreated and flags a line that never shows up as OrderReleaseUnconfirmed; that is a fact for analytics, never a trigger to cancel, re-release or retry.