Skip to main content

Domain events

Synced from exception-management

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 Kafka message is a CloudEvents 1.0 event in structured mode: the Kafka value is the whole JSON envelope, header content-type: application/cloudevents+json; charset=UTF-8. Envelopes are built and decoded only in internal/adapters/kafka/cloudevents (ADR 0004). The contract is apis/asyncapi.yaml; the summary table is the event catalogue.

Published​

Integration topic warehouse.exception-management.events, source /warehouse/exception-management, subject and Kafka key = the case id (the source type for the policy event), dataschema urn:warehouse:exception-management:events:<EventName>:v1. A warehouse.exception-management.analytics mirror of every type is declared in ADR 0004 but not built yet (roadmap: the projector).

EventRaised when
ExceptionOpeneda source fact opens a case (first occurrence of the dedup key)
ExceptionTriagedseverity/queue set by an operator or system
ExceptionAssignedan owner takes the case
ExceptionEscalatedthe SLA sweeper sets the breach flag
ExceptionResolvedan operator records resolution code + root cause (terminal)
ExceptionAutoResolveda policy auto-resolve rule fires on a correlated fact
ExceptionPolicyDeclareda policy version is declared (subject and key = the source type)

Touch raises nothing: the occurrence count and the audit trail are the record.

Payloads (data, snake_case, optional fields omitted when unset)​

ExceptionOpened {case_id, source_type, source_subject, site_id (nullable), severity, queue, opened_at, sla_due_at, source_event_id, source_payload (object, frozen)}

ExceptionTriaged {case_id, severity, queue, actor, at}

ExceptionAssigned {case_id, assignee, actor, at}

ExceptionEscalated {case_id, sla_due_at, at}

ExceptionResolved {case_id, resolution_code, root_cause, note (nullable), actor, at}

ExceptionAutoResolved {case_id, rule_id, correlated_type, correlated_event_id, at}

ExceptionPolicyDeclared {source_type, version, severity, queue, sla_minutes, auto_resolve (nullable: {on_type, within_minutes})}

severity is LOW, MEDIUM, HIGH or CRITICAL. The CloudEvents id is a UUID minted once at enqueue and persisted with the outbox row — a relay retry republishes byte-identically, consumers dedupe on it. A breaking payload change is a new .v2 type and dataschema, never a mutation of v1.

Consumed​

Nine case sources plus one correlation fact, each under its pinned consumer group. Dispatch is on the FULL type; every other type on those topics is ignored; anything that is not a valid CloudEvent is logged and skipped (WARN, commit past).

Type (prefix com.warehouse.)TopicDedup subjectNotes
wes.fulfillment-execution.task.TaskCPTMissedwarehouse.fulfillment.eventstask idRe-fires every sweep tick by design; order_ref = work unit {order_id}-line-{line_no} feeds the correlation
wes.fulfillment-execution.package.PackageDivertedwarehouse.fulfillment.eventspackage idPromoted to the integration topic by the producer (PR #234, merged 2026-10-21)
wes.fulfillment-execution.package.WeightDiscrepancyDetectedwarehouse.fulfillment.eventspackage idSame promotion
wes.work-planning.workpool.BacklogThresholdBreachedwarehouse.work-planning.eventspath iddata carries only path_id (the producer's contract)
wes.network-fulfillment.networkorder.AcknowledgementDeadlineAtRiskwarehouse.network-fulfillment.eventsnetworkRefRe-fires while the condition holds; siteId feeds the dedup key
wes.network-fulfillment.networkorder.OrphanedHoldCancelledwarehouse.network-fulfillment.eventsnetworkRefSame
wms.returns-processing.returnreceipt.UnexpectedReturnReceivedwarehouse.returns-processing.eventsreceipt idOne case per receipt (line_no is not part of the key); site_id feeds the dedup key
wms.inbound-receiving.receipt.CartonDiscrepancyRaisedwarehouse.inbound-receiving.eventsreceipt id + sscc or - + kindOne case per (receipt, sscc, kind); UnlabelledCarton/CartonOverLimit route to receiving-lead, every other kind to problem-solve (ADR 0006)
wms.inventory-storage.bin.DiscrepancyDetectedwarehouse.inventory.eventsbin idPromoted by the producer (PR #239, merged 2026-10-21)
wms.inventory-storage.stock.ItemUnlocatedwarehouse.inventory.eventsstock unit idSame promotion
wms.yard-management.yardvisit.VisitRejectedwarehouse.yard-management.eventsvisit idOne case per rejected visit; default queue yard-supervisor (ADR 0010)
wms.yard-management.trailer.SealExceptionRaisedwarehouse.yard-management.eventstrailer id + raised_atA later raise for the same trailer is its own case; the same raise re-published touches (ADR 0010)
wms.yard-management.trailer.TrailerDwellExceededwarehouse.yard-management.eventstrailer id + CloudEvents timeThe payload carries no instant of its own (ADR 0010)
wms.yard-management.yardcheck.YardCheckClosedwarehouse.yard-management.eventsyard check id + kind + location + trailer id, unit number or -One case per discrepancy, one claimed event id for the whole check (ADR 0010)
wms.dock-scheduling.dockappointment.DockAppointmentNoShowwarehouse.dock-scheduling.eventsappointment idOne case per appointment; default queue dock-planner (ADR 0010)
wms.outbound-shipping.shippingpackage.PackageMissedLoadwarehouse.outbound-shipping.eventspackage idOne problem-solve case per missed package (site_id feeds the dedup key); the load/order/cutoff stay in the frozen payload (ADR 0011)
wes.order-management.order.OrderRepromisedwarehouse.order-management.events—Correlation only, never a case source: the correlated fact of the auto-resolve rule

Not consumed (roadmap): workforce-management PathUnderstaffed, network-inventory-planning TransferStuckDetected — analytics-topic-only today, promotion pending on the producers.

None of the consumed types carries a version field: the dedup key alone decides open-vs-touch and the CloudEvents id ledger alone decides process-once (ADR 0003).

Example: ExceptionOpened​

{
"specversion": "1.0",
"id": "0f4a2a2e-1f6b-4a1e-9d0c-6f2f2c9b7a11",
"source": "/warehouse/exception-management",
"type": "com.warehouse.wes.exception-management.exceptioncase.ExceptionOpened",
"subject": "case-1b4e28ba-2b11-53ba-bc5f-4a5d7e8f9a01",
"time": "2026-10-21T09:15:04.122Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:exception-management:events:ExceptionOpened:v1",
"data": {
"case_id": "case-1b4e28ba-2b11-53ba-bc5f-4a5d7e8f9a01",
"source_type": "com.warehouse.wes.fulfillment-execution.task.TaskCPTMissed",
"source_subject": "task-8a1f",
"site_id": null,
"severity": "HIGH",
"queue": "cpt-missed",
"opened_at": "2026-10-21T09:15:04.122Z",
"sla_due_at": "2026-10-21T09:45:04.122Z",
"source_event_id": "6c1f0e8a-0a3d-4bfa-9b6e-7d2c1f5a3e22",
"source_payload": {
"task_id": "task-8a1f",
"order_ref": "wu-8a1f",
"task_type": "PICK",
"cpt": "2026-09-30T14:55:00Z"
}
}
}

(The envelope shape and every field name are pinned by apis/asyncapi.yaml and checked by the golden exact-JSON tests per type; the values above are an illustration of the shape, not a captured message.)