Skip to main content

Domain events

Every event this context raises, publishes and consumes, with the field detail the Event catalogue summarises. Sources: internal/domain/customerorder/events.go, internal/adapters/outbound/kafka/encoder.go, internal/adapters/kafka/cloudevents/cloudevents.go, apis/asyncapi.yaml.

Envelope​

Every message is a CloudEvents 1.0 event in structured JSON mode with the Kafka header content-type: application/cloudevents+json; charset=UTF-8.

AttributeValue
specversion1.0
ida UUID v4 minted once by the encoder when the event is written to outbox_events; every relay retry repeats it
source/retailnetwork/customer-ordering
typecom.retailnetwork.commerce.customer-ordering.customerorder.<EventName> (tier commerce, entity customerorder)
subjectthe orderId
timethe instant the fact happened, UTC
datacontenttypeapplication/json
dataschemaurn:retailnetwork:customer-ordering:events:<EventName>:v1
Kafka topic / keyretailnetwork.customer-ordering.events / the orderId

data is camelCase, instants are RFC 3339 UTC, optional fields are omitted when absent and arrays are always present. A breaking change would be a new .v2 type, never a mutation of v1.

Raised by the domain​

EventRaised byCondition
CustomerOrderPlacedcustomerorder.Placethe order was built with every line in one group and every group promised
CustomerOrderCancelledCustomerOrder.CancelOrder and CancelUnkeepableGroupat least one unlocked group became CANCELLATION_REQUESTED, or an unkeepable group became CANCELLED

Shoppers raise no events. The consumed events change state but raise nothing except the cancellation of an unkeepable group.

Published​

CustomerOrderPlaced​

FieldTypeMeaning
orderIdstringthe customer order
shopperIdstringthe shopper (an id, not PII)
destinationPostalPrefixstringfirst 3 letters or digits of the normalised ship-to postal code; never the address
placedAttimestampwhen the order was placed
consolidationKeystring, optional64 lower-case hex: keyed hash of shopper and normalised ship-to (ADR 0012); omitted when no secret is configured, which means the order never merges
groups[].groupNointegergroup number inside the order
groups[].promiseIdstringthe delivery-promise promise of the group
groups[].tierenumSAME_DAY, NEXT_DAY, TWO_DAY, STANDARD, CONSOLIDATED (the real tier, never mapped; ADR 0013)
groups[].witnessNodeIdstringthe node of the promise's witness path; order-sourcing may choose another node
groups[].shipBy, deliverByEarliest, deliverByLatesttimestampthe promise terms
groups[].timeZonestring, optionalIANA zone of the destination the window is read in (ADR 0009)
groups[].chosenDeliveryDayYYYY-MM-DD, optionalCONSOLIDATED groups only: the local date of deliverByLatest in timeZone the shopper chose at placement; omitted when unknown (ADR 0013)
groups[].consolidationEligibleboolean, optionalCONSOLIDATED groups only: delivery-promise's answer whether the option leaves the network time to merge; an absent value is unknown, never false (ADR 0013)
groups[].lines[]{lineNo, catalogItemId, quantity}the lines of the group

Consumers: order-sourcing (queues one assignment per group) and delivery-promise (reconciling confirm). The per-group promise snapshot lets order-sourcing build its constraint from this one event.

CustomerOrderCancelled​

FieldTypeMeaning
orderIdstringthe customer order
reasonstringfree text: the shopper's reason (1 to 200 characters) or PROMISE_UNKEEPABLE: <reason> from the policy
cancelledAttimestampwhen the cancellation was recorded
groupNosinteger[]the groups whose cancellation is requested, a subset of the order's groups when others are locked

Consumers: order-sourcing (cancel request per listed group; it answers FulfillmentCancelled or FulfillmentCancelRefused) and delivery-promise (cancels the promises of the listed groups).

Example envelope (from apis/asyncapi.yaml, synthetic ids):

{
"specversion": "1.0",
"id": "3f6c2a9e-8b1d-4c7a-9e55-0d2f6b7a1c40",
"source": "/retailnetwork/customer-ordering",
"type": "com.retailnetwork.commerce.customer-ordering.customerorder.CustomerOrderPlaced",
"subject": "7a1e6c52-0d2b-4f0e-9d6a-5c6f1b8e2a10",
"time": "2026-10-23T10:15:30Z",
"datacontenttype": "application/json",
"dataschema": "urn:retailnetwork:customer-ordering:events:CustomerOrderPlaced:v1",
"data": {
"orderId": "7a1e6c52-0d2b-4f0e-9d6a-5c6f1b8e2a10",
"shopperId": "3b0c1f0e-6f0a-4a39-8a55-2b7f0d8c9e11",
"destinationPostalPrefix": "787",
"placedAt": "2026-10-23T10:15:30Z",
"consolidationKey": "9f2c6d0b1a7e4c3d8b5a0e6f1d2c3b4a5968778695a4b3c2d1e0f9a8b7c6d5e4",
"groups": [
{
"groupNo": 1,
"promiseId": "p-1001",
"tier": "NEXT_DAY",
"witnessNodeId": "fc-aus-1",
"shipBy": "2026-10-23T22:00:00Z",
"deliverByEarliest": "2026-10-24T13:00:00Z",
"deliverByLatest": "2026-10-24T22:00:00Z",
"timeZone": "America/Chicago",
"lines": [{"lineNo": 1, "catalogItemId": "sku-100", "quantity": 2}]
}
]
}
}

There is no address, name or phone anywhere in the envelope.

Consumed​

Fields the handlers rely on (the producers' own AsyncAPI files are authoritative; unknown fields are ignored).

EventProducer type segmentFields usedEffect
PromiseAtRiskcommerce.delivery-promise.promisepromiseId, orderId, reason, detectedAtat-risk reason on the group's signal row
PromiseRevisedsamepromiseId, orderId, revisionNo, deliverByEarliest, deliverByLatest, timeZone?, shipBy, nodeId, reasonUpdateGroupPromise; a revisionNo not above the stored one is ignored
PromiseKeptsamepromiseId, orderId, nodeId, deliveredAt, deliverByLatestverdict KEPT in the tracking view
PromiseBrokensameas above plus lateByMinutes, causeverdict BROKEN with minutes late
PromiseUnkeepablesamepromiseId, orderId, groupNo, reasonCancelUnkeepableGroup (policy CancelOnUnfulfillable)
FulfillmentLockedcommerce.order-sourcing.assignmentassignmentId, orderId, groupNo, nodeId, lockedAt, promiseIdMarkInFulfillment; stores the assignment link
FulfillmentShippedsameassignmentId, orderId, groupNo, nodeId, trackingNumbers, shippedAtMarkGroupShipped; replays early package events
FulfillmentUnsourceablesameorderId, groupNo, promiseId, excludedNodes, reasonreason in the tracking view only
FulfillmentCancelledsameorderId, groupNo, reasonConfirmGroupCancelled
FulfillmentCancelRefusedsameorderId, groupNo, reasonRefuseGroupCancellation: back to LOCKED
LabelIssuedlogistics.shipping-and-tracking.labeltrackingNumber, assignmentId, packageNo, tier, carrierpackage row created or completed
LabelVoidedsametrackingNumber, reasonpackage marked voided
PackageScannedlogistics.shipping-and-tracking.journeytrackingNumber, scanId, nodeId, scanType, at, statenewest scan on the package
PackageExceptionRaisedsametrackingNumber, assignmentId, orderId, reason, atexception reason
PackageDeliveredsametrackingNumber, assignmentId, orderId, deliveredAtMarkGroupDelivered for every group of the tracking number, once every package of the group is delivered (ADR 0012)
PackageLostsametrackingNumber, orderId, declaredAt (falls back to the event time)MarkGroupLost: terminal
PackageReturnedsametrackingNumber, orderId, returnedAt (falls back to the event time)MarkGroupReturned: terminal
PackageEtaWindowAssignedsametrackingNumber, assignmentId, orderId, etaStart, etaEnd, assignedAt (falls back to the event time)tracking package window only (latest assignedAt wins); no aggregate command, the promise is untouched (ADR 0014)
PackageDeliveryPointFlaggedsametrackingNumber, assignmentId, orderId, reason (NOT_HOME or ACCESS_PROBLEM, anything else is a bad payload), flaggedAt (falls back to the event time)delivery-point advisory on the tracking package row (newest flaggedAt wins); read model only, no order, group, promise or ETA window is read or written (ADR 0015)
PackageReadyForCollectionsametrackingNumber, assignmentId, orderId, pickupPointId, readyForCollectionAt, holdUntil (pickupPointId, readyForCollectionAt and holdUntil are required, else a bad payload)records the deposit at the pickup point on the tracking package row; no aggregate changes (ADR 0016)
PackageCollectedsametrackingNumber, assignmentId, orderId, pickupPointId, collectedAt, proofCode? (pickupPointId and collectedAt are required, else a bad payload)records the collection on the tracking package row; no aggregate changes (ADR 0016)

Ordering. Producers key by their own root ids, so there is no order guarantee across groups or topics. An event for an unknown order, an unknown group, a regression or an illegal transition is logged as consumed event skipped and acknowledged (ADR 0002, A7); a delivery or package outcome that arrives before the shipment is known is stored and replayed when FulfillmentShipped arrives. Dedupe is on the CloudEvents id (processed_events).