Skip to main content

Domain events

The envelope rules, the topic-by-topic list of all 49 types and the delivery guarantees are on the event catalogue. This page adds, per published event, the typed data fields, the producing command and the consumers, and, per consumed event, what the handler does and how it stays idempotent. Source: internal/domain/assignment/events.go, internal/adapters/outbound/kafka/encoder.go (the wire structs), internal/adapters/inbound/kafka/handlers.go.

Envelope​

Every Kafka message is a CloudEvents 1.0 event in structured JSON mode.

AttributeValue for this context
specversion1.0
ida UUID minted once by the encoder and stored in the outbox row, so a redelivery carries the same id
source/retailnetwork/order-sourcing
typecom.retailnetwork.commerce.order-sourcing.assignment.<EventName>
subjectthe assignmentId
timewhen the transition happened, UTC
datacontenttypeapplication/json
dataschemaurn:retailnetwork:order-sourcing:<events|analytics>:<EventName>:v1
Kafka topicretailnetwork.order-sourcing.events, or retailnetwork.order-sourcing.analytics for the analytics-only events (SourcingPolicyPublished has entity policy and subject policy)
Kafka keythe assignmentId, so one assignment's events stay in order on one partition

Every event leaves through the transactional outbox, written in the same transaction as the aggregate.

Published​

EventTopicProducing commandConsumers (read on their origin/develop)
FulfillmentQueuedanalyticsQueueAssignmentnone known
FulfillmentReleasedToNodeeventsReleaseToNode, QueueAssignment for SAME_DAYvendor-connectivity, linehaul-transportation, seller-inbound
FulfillmentSourcingDecidedanalyticsReleaseToNode, QueueAssignment for SAME_DAY (with every FulfillmentReleasedToNode)this context's cmd/os-projector (ADR 0013)
FulfillmentReassignedeventsReoptimiseAssignment, ReleaseToNode, HandleNodeRefusal, ApplyRevisedPromise (node changed)linehaul-transportation
FulfillmentLockedeventsLockAssignmentdelivery-promise, customer-ordering, linehaul-transportation
FulfillmentShippedeventsMarkShippeddelivery-promise, customer-ordering, customer-payments
FulfillmentDeliveredanalyticsMarkDelivered (last package)none known
FulfillmentUnsourceableeventsQueueAssignment, ReoptimiseAssignment, ReleaseToNode, HandleNodeRefusal, ApplyRevisedPromisedelivery-promise, customer-ordering, customer-payments
FulfillmentCancelledeventsCancelAssignmentvendor-connectivity, linehaul-transportation, customer-ordering, seller-inbound, customer-payments
FulfillmentCancelRefusedeventsCancelAssignment (after the lock, or while a merged release is not yet locked, ADR 0015)customer-ordering
FulfillmentConstraintRevisedeventsApplyRevisedPromisenone found
FulfillmentReleaseWithdrawneventsApplyRevisedPromise (a revision breaks a merged window, ADR 0015)vendor-connectivity (cancels the purchase order)
AssignmentsConsolidatedanalyticsReleaseToNode (a merged release, ADR 0015)none
AssignmentsDeconsolidatedanalyticsHandleNodeRefusal, ApplyRevisedPromise (ADR 0015)none

The consumer column is from the handler files of the six consumer repositories named on Integration.

FulfillmentQueued​

FieldTypeMeaning
assignmentIdstringThe new assignment
orderIdstringThe customer order
groupNointegerThe shipment group within the order
promiseIdstringThe promise this assignment must keep
deliverByLatestdate-timeThe binding deadline
linesarraylineNo, catalogItemId, quantity; no listingId yet because no node is chosen

FulfillmentReleasedToNode​

FieldTypeMeaning
assignmentIdstringThe assignment
releaseNointeger1 for the first release, plus 1 for each later one; with assignmentId it is the purchase order's idempotency key
orderId, groupNostring, integerThe group
nodeIdstringThe vendor node released to
pickupDepartureIdstringThe pickup departure the group must make
requiredShipBydate-timeThat departure's cutoff at this node
promisedDeliverByLatestdate-timeThe promise's deliverByLatest
tierstringSAME_DAY, NEXT_DAY, TWO_DAY or STANDARD
linesarrayThe whole group (fill-or-kill): catalogItemId, listingId of this node, quantity

No ship-to data: the release carries no PII.

FulfillmentReassigned​

FieldTypeMeaning
assignmentIdstringThe assignment
fromNodeId, toNodeIdstringThe node it leaves and the new candidate
reasonstringREOPTIMISED, RELEASE_RECHECK, PURCHASE_ORDER_REJECTED, PURCHASE_ORDER_EXPIRED or PROMISE_REVISED
assignmentVersionintegerThe version after the change, so consumers can drop stale copies

FulfillmentLocked​

FieldTypeMeaning
assignmentId, orderId, groupNostring, string, integerThe group
promiseIdstringThe promise
nodeIdstringThe node that accepted
pickupDepartureIdstringThe pickup departure the package will make
lockedAtdate-timeThe acceptance time (falls back to the processing time)
lockReasonstringPURCHASE_ORDER_ACCEPTED

FulfillmentShipped​

FieldTypeMeaning
assignmentId, orderId, groupNostring, string, integerThe group
nodeIdstringThe shipping node
trackingNumbersarray of stringOne per package, 1 to 100
shippedAtdate-timeFrom VendorShipmentConfirmed

FulfillmentSourcingDecided​

The analytics-only fact of one release (ADR 0013): written in the same transaction as the FulfillmentReleasedToNode it explains, same aggregate version, its own event id.

FieldTypeMeaning
assignmentId, orderId, groupNostring, string, integer (optional)The group
releaseNo, nodeIdinteger, stringThe release this decision made
nodeRegionId, destinationRegionIdstring (optional)From the NetworkGraphView node and the RegionAndServiceArea of the destination; omitted when unknown
inRegionboolean (optional)Both regions equal; omitted when either is unknown
legsintegerDepartures after the pickup on the chosen route
estimatedCostCents, costCompleteinteger (optional), booleanThe ADR 0011 estimate; omitted and false when any leg lacks a cost
unitsintegerSum of the line quantities
candidateCountintegerCandidates the search evaluated
decidedAtdate-timeThe release instant

FulfillmentDelivered​

FieldTypeMeaning
assignmentId, orderId, groupNostring, string, integerThe group
deliveredAtdate-timeFrom the last PackageDelivered

FulfillmentUnsourceable​

FieldTypeMeaning
assignmentId, orderId, groupNostring, string, integerThe group
promiseIdstringThe promise to revise
excludedNodesarraynodeId, reason of every node that refused, so the re-promise can avoid them
reasonstringNO_CANDIDATE or NODE_REFUSED

FulfillmentCancelled and FulfillmentCancelRefused​

FieldTypeMeaning
assignmentId, orderId, groupNostring, string, integerThe group
reasonstringFrom CustomerOrderCancelled.reason (default UNSPECIFIED); CANCEL_AFTER_LOCK for the refusal after the lock, CANCEL_WHILE_MERGED for the refusal of a member of a live merged release (ADR 0015)

FulfillmentConstraintRevised​

FieldTypeMeaning
assignmentIdstringThe assignment
revisionNointegerThe applied promise revision
deliverByLatestdate-timeThe new binding deadline

Example envelope​

The most important event: the release that becomes a purchase order. The identifiers are illustrative (the same values as the example in apis/asyncapi.yaml).

{
"specversion": "1.0",
"id": "3f6c2a9e-8b1d-4c7a-9e55-0d2f6b7a1c66",
"source": "/retailnetwork/order-sourcing",
"type": "com.retailnetwork.commerce.order-sourcing.assignment.FulfillmentReleasedToNode",
"subject": "asg-7f3c2d10",
"time": "2026-10-22T19:01:00Z",
"datacontenttype": "application/json",
"dataschema": "urn:retailnetwork:order-sourcing:events:FulfillmentReleasedToNode:v1",
"data": {
"assignmentId": "asg-7f3c2d10",
"releaseNo": 1,
"orderId": "ord-51a0c9",
"groupNo": 1,
"nodeId": "node-fc-ws-sor-01",
"pickupDepartureId": "dep-pk-20261022-1800-fc-ws-sor-01",
"requiredShipBy": "2026-10-22T21:00:00Z",
"promisedDeliverByLatest": "2026-10-24T23:00:00Z",
"tier": "TWO_DAY",
"lines": [
{"catalogItemId": "cat-000123", "listingId": "lst-000123-fc-ws-sor-01", "quantity": 2}
]
}
}

Consumed​

Every consumer is idempotent on the CloudEvents id through the inbox table processed_events, written in the same transaction as the change it causes, and dispatches on the full type string, never on a suffix. Domain-level idempotency comes on top, per row below.

Events that drive the aggregate​

ProducerEventFields usedWhat this context doesDomain idempotency
customer-orderingCustomerOrderPlacedorderId, destinationPostalPrefix, groups[]QueueAssignment per group; SAME_DAY groups are released at onceone assignment per (orderId, groupNo); a repeat finds it and does nothing
customer-orderingCustomerOrderCancelledorderId, groupNos, reasonCancelAssignment for each listed groupan already CANCELLED assignment is left as is; a group never queued here is skipped
delivery-promisePromiseRevisedpromiseId, revisionNo, deliverByLatest, nodeIdApplyRevisedPromise on the assignment of that promisea revisionNo not above the applied one is ignored
vendor-connectivityPurchaseOrderAcceptedassignmentId, releaseNo, acceptedAtLockAssignmentonly the pending releaseNo locks; a repeat for the locking release is a no-op
vendor-connectivityPurchaseOrderRejectedassignmentId, releaseNo, reasonCodeHandleNodeRefusal with outcome REJECTEDonly for the pending release; an older releaseNo is ignored
vendor-connectivityPurchaseOrderExpiredassignmentId, releaseNoHandleNodeRefusal with outcome EXPIREDas above
vendor-connectivityVendorShipmentConfirmedassignmentId, trackingNumbers, shippedAtMarkShippeda repeat on SHIPPED or DELIVERED is a no-op
shipping-and-trackingPackageDeliveredassignmentId, trackingNumber, deliveredAtMarkDelivereda repeat of a recorded package is a no-op; the last package delivers
linehaul-transportationBookingMovedassignmentId, fromDepartureId, toDepartureIdRecordPickupMoved on a LOCKED assignmenta move to the current departure, or from another one, changes nothing
linehaul-transportationBookingFailedassignmentIdrecorded as processed only; the departure's own events drive re-optimisationinbox

Events that feed read models​

ProducerEventsRead modelIdempotency
delivery-promisePromiseBookExhaustedPromiseBookPressureView (rm_book_pressure)upsert by bookId
node-topologyNodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetiredNodeProfileView (rm_nodes)upsert by nodeId; a lower profileRevision is ignored; a status with an older instant is ignored
node-topologyLaneOpened, LaneClosed, LaneCostDeclared, ServiceAreaAssigned, RegionDefinedNetworkGraphViewupsert by laneId, postalPrefix (newer assignmentVersion wins), regionId; a lane cost with a newer declaredAt wins and is kept even if LaneOpened arrives later
linehaul-transportationDepartureScheduled, DepartureCapacityChanged, DepartureCancelledNetworkGraphView (rm_departures)upsert by departureId; any arrival order converges
last-mile-deliveryDeliveryWaveScheduled, DeliveryWaveCapacityChanged, DeliveryWaveCancelled, WaveCostDeclaredNetworkGraphView (rm_waves)upsert by waveId; a wave cost with a newer declaredAt wins and is kept even if DeliveryWaveScheduled arrives later
offer-availabilityListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored, CatalogItemDiscontinuedAvailabilityViewupsert by listingId / catalogItemId; an older asOf is ignored
node-performanceNodeScorecardUpdatedScorecardView (rm_scorecards)upsert by (nodeId, window); an older computedAt is ignored

A read-model change does not itself move an assignment. Queued assignments pick it up at the next re-optimisation sweep, and a release re-checks the candidate against fresh read models.

Full types for every row are on the event catalogue.