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:
specversion1.0;ida UUID minted when the event is encoded (and stored in the outbox row, so a redelivery keeps it);source/warehouse/order-management;typecom.warehouse.wes.order-management.order.<EventName>;subjectthe order id;timethe domain occurred-at (UTC);datacontenttypeapplication/json;dataschemaurn:warehouse:order-management:<events|analytics>:<EventName>:v1.- Kafka header
content-type: application/cloudevents+json; charset=UTF-8; W3C trace context intraceparent/tracestate. - Kafka key = the order id on both outbound topics, with the
Hashbalancer, so one order's events stay on one partition (ADR 0027). The one exception isSiteSkuDemandChanged(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:
| Configuration | Publisher | Delivery |
|---|---|---|
EVENT_PUBLISHER=log (default) | events.LogPublisher | JSON log line only |
kafka with DATABASE_URL | postgres.OutboxPublisher + postgres.OutboxRelay | one 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_URL | kafka.FanOutPublisher | written 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
| Event | Full CloudEvents type | Topics | Producing use case | Known consumers |
|---|---|---|---|---|
| OrderReceived | com.warehouse.wes.order-management.order.OrderReceived | analytics | ReceiveOrder | order-projector |
| OrderLineAllocated | com.warehouse.wes.order-management.order.OrderLineAllocated | analytics | allocation pass | order-projector |
| OrderLineBackordered | com.warehouse.wes.order-management.order.OrderLineBackordered | analytics | allocation pass, reconfirm before release | order-projector |
| OrderAllocated | com.warehouse.wes.order-management.order.OrderAllocated | integration + analytics | allocation pass when the order ends Allocated or Released | wes-work-planning, order-projector |
| OrderPartiallyAllocated | com.warehouse.wes.order-management.order.OrderPartiallyAllocated | integration + analytics | allocation pass when the order ends PartiallyAllocated or PartiallyReleased | wes-work-planning, order-projector |
| OrderAllocationPartiallyFailed | com.warehouse.wes.order-management.order.OrderAllocationPartiallyFailed | analytics | allocation pass, hard failure after some lines allocated | order-projector |
| OrderCancelled | com.warehouse.wes.order-management.order.OrderCancelled | analytics | CancelOrder | order-projector |
| OrderRepromised | com.warehouse.wes.order-management.order.OrderRepromised | integration + analytics | RepromiseOrder | order-projector, exception-management (auto-resolve correlation) |
| OrderLineReleased | com.warehouse.wes.order-management.order.OrderLineReleased | analytics | allocation pass, once per line released in that pass | order-projector |
| OrderReleased | com.warehouse.wes.order-management.order.OrderReleased | analytics | allocation pass, when that pass leaves every line Released | order-projector |
| OrderReleaseUnconfirmed | com.warehouse.wes.order-management.order.OrderReleaseUnconfirmed | analytics | FlagUnconfirmedReleases, 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 |
| OrderLineShipped | com.warehouse.wes.order-management.order.OrderLineShipped | none: 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=kafka | none |
| OrderShipped | com.warehouse.wes.order-management.order.OrderShipped | none (as above) | ConfirmShipment, when the order ends Shipped; carries the load_id | none |
| OrderPartiallyShipped | com.warehouse.wes.order-management.order.OrderPartiallyShipped | none (as above) | ConfirmShipment, when some lines shipped and the order is not Shipped; carries the load_id | none |
| SiteSkuDemandChanged | com.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChanged | integration | allocation 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):
| Field | Type | Notes |
|---|---|---|
order_id | string | |
promise_date | RFC 3339 | latest cutoff across promise groups |
promise_cpt_id | string, omitted when empty | absent for a LeadTime promise |
promise_basis | Capability, LeadTime or Network, omitted when empty | |
lines[] | array | lines released in this pass (empty for a held order) |
lines[].line_no, sku, path_id, gift_wrap | the original four frozen fields wes-work-planning decodes | |
lines[].fulfillment_class | SINGLE, SAME_SKU_MULTI, MULTI_LINE_MULTI | additive, ADR 0008 |
lines[].promise_cpt_id, promise_basis, promise_cutoff_at | omitted when empty | per-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:
| Event | data fields |
|---|---|
| OrderReceived | order_id, path_id (first line), line_count |
| OrderAllocated | order_id, path_id (first released line, else first line), promise_basis, promise_cutoff_at (Capability basis only), split_shipment |
| OrderPartiallyAllocated | as OrderAllocated plus allocated_lines, backordered_lines |
| OrderAllocationPartiallyFailed | order_id, path_id, allocated_lines, remaining_lines |
| OrderCancelled | order_id, path_id, revoked_reservations |
| OrderLineAllocated | order_id, line_no, path_id (that line), sku |
| OrderLineBackordered | order_id, line_no, path_id (that line), sku |
| OrderRepromised | order_id, cpt_id_old, cpt_id_new, reason |
| OrderLineReleased | order_id, line_no, path_id, work_unit_id |
| OrderReleased | order_id, path_id |
| OrderReleaseUnconfirmed | order_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
| Producer | Full CloudEvents type | Topic | Payload fields read | Adapter, group | Effect |
|---|---|---|---|---|---|
| fulfillment-execution | com.warehouse.wes.fulfillment-execution.task.TaskCPTMissed | warehouse.fulfillment.events | task_id, order_ref, task_type, cpt | inbound/kafka.RepromiseConsumer, stable group order-management-repromise | RepromiseOrder |
| fulfillment-execution | com.warehouse.wes.fulfillment-execution.package.PackageManifested | warehouse.fulfillment.events | package_id, order_ref | same | RepromiseOrder |
| process-path-management | com.warehouse.wes.process-path-management.processpath.ProcessPathCreated | warehouse.process-path-management.events | path_id, match_prefix, cycle_time_p95, eligibility (max_units_per_line, required_product_attributes, excluded_product_attributes, non_sortable), destination_location_role | outbound/kafkacatalog, per-process group order-management-process-path-catalogue-* | upsert catalogue cache |
| process-path-management | com.warehouse.wes.process-path-management.processpath.ProcessPathUpdated | same | same | same | upsert catalogue cache |
| process-path-management | com.warehouse.wes.process-path-management.processpath.ProcessPathDeactivated | same | path_id | same | remove from catalogue cache |
| process-path-management | com.warehouse.wes.process-path-management.cptschedule.CPTScheduleChanged | same | site_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-planning | com.warehouse.wes.work-planning.workpool.PathCapacityChanged | warehouse.work-planning.events | path_id, cutoff_at, remaining_units, known | outbound/kafkapathcapacity, per-process group order-management-path-capacity-* | remaining capacity keyed by path and cutoff |
| wes-work-planning | com.warehouse.wes.work-planning.workunit.WorkUnitCreated | warehouse.work-planning.events | the optional reference (the order id) and line_no; path_id and work_unit_id are not read | inbound/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-shipping | com.warehouse.wms.outbound-shipping.outboundload.ShipmentConfirmed | warehouse.outbound-shipping.events | load_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 read | inbound/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-shipping | com.warehouse.wms.outbound-shipping.shippingpackage.PackageMissedLoad | same | source_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 read | same | RepromiseOrder.ExecuteForMissedLoad: re-promise every group of that order |
| warehouse-planning | com.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanCreated | warehouse.warehouse-planning.events | plan_id, warehouse_id, location, path_id, window_start, window_end, assigned_demand, capacity_over_window, shortage, bottleneck_step | inbound/kafka.PlannedCapacityConsumer, group from PLANNED_CAPACITY_CONSUMER_GROUP | upsert window as DRAFT |
| warehouse-planning | com.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanPublished | same | same | same | upsert window as PUBLISHED |
| warehouse-planning | com.warehouse.wes.warehouse-planning.capacityplan.CapacityShortageDetected | same | same | same | upsert window as PUBLISHED |
| warehouse-planning | com.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanSuperseded | same | same | same | move the plan's row to terminal SUPERSEDED (tombstone if unseen; ADR 0052) |
| product-master | com.warehouse.wms.product-master.product.ProductClassified | warehouse.product-master.events | sku, 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.dlqtopic (warehouse.fulfillment.events.dlq,warehouse.warehouse-planning.events.dlq) withx-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 CloudEventsid(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 nextProductClassifiedfor 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/orderwaits 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 fromOUTBOUND_SHIPPING_CONSUMER_GROUP(no default).ShipmentConfirmedis idempotent on the raw CloudEventsidinshipment_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 ano_changeoutcome.PackageMissedLoadgoes through the existingrepromise_processed_eventsgate. It dispatches on the two full types only; every other type on the topic is committed past. AShipmentConfirmednaming an unknown order or an order with noReleasedline is logged at WARN and skipped (the other orders in the event still ship), never dead-lettered. A non-CloudEvents message or an undecodabledatagoes towarehouse.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 fromRELEASE_CONFIRMATION_CONSUMER_GROUP(no default), idempotent on the CloudEventsid(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.WorkUnitCreatedonly; every other type on the topic is committed past. AWorkUnitCreatedwithoutreferenceor a positiveline_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 undecodabledatagoes towarehouse.work-planning.events.dlqwithx-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.