Skip to main content

Domain events

Every event this context publishes and consumes, from internal/adapters/outbound/kafka/encoder.go (payloads), internal/adapters/inbound/kafka/handlers.go (consumed payloads) and the contract apis/asyncapi.yaml. The catalogue with failure behaviour is on Event catalogue; the domain-wide rules are on the central event standard.

Envelope​

Every Kafka message is a CloudEvents 1.0 event in structured JSON mode, built only by internal/adapters/kafka/cloudevents/cloudevents.go.

AttributeValue
specversion1.0
idA UUID minted once when the outbox row is written (outbox_events.event_id): a relay retry re-sends the same id
source/retailnetwork/shipping-and-tracking
typecom.retailnetwork.logistics.shipping-and-tracking.<entity>.<EventName>, entity label or journey
subjectThe aggregate root id: labelRef for label events, trackingNumber for journey events
timeThe instant of the change from the service clock (OccurredAt), UTC
datacontenttypeapplication/json
dataschemaurn:retailnetwork:shipping-and-tracking:events:<EventName>:v1
Kafka topicretailnetwork.shipping-and-tracking.events
Kafka keySame as subject, so one journey's events stay in order on one partition

Every event leaves through the transactional outbox, in the same transaction as the aggregate change. No event carries a ship-to address or any part of it. Payload timestamps are RFC 3339 UTC strings; data is camelCase.

Published​

EventFull typeSubject and keyProducing use caseConsumers (per the AsyncAPI)
LabelIssuedcom.retailnetwork.logistics.shipping-and-tracking.label.LabelIssuedlabelRefIssueLabellinehaul-transportation, customer-ordering, last-mile-delivery
LabelVoided...label.LabelVoidedlabelRefVoidLabelcustomer-ordering, linehaul-transportation
PackageScanned...journey.PackageScannedtrackingNumberRecordScan, ApplyScans (every applied scan)none named
PackageHandedOver...journey.PackageHandedOvertrackingNumbera scan taking LABELLED to HANDED_OVERnode-performance
PackageDelivered...journey.PackageDeliveredtrackingNumbera scan taking OUT_FOR_DELIVERY to DELIVEREDdelivery-promise, order-sourcing, customer-ordering
PackageExceptionRaised...journey.PackageExceptionRaisedtrackingNumberSweepSilence (RaiseException)delivery-promise, customer-ordering
PackageReturned...journey.PackageReturnedtrackingNumberReturnToSenderdelivery-promise
PackageLost...journey.PackageLosttrackingNumberSweepSilence (DeclareLost)delivery-promise
PackageEtaWindowAssigned...journey.PackageEtaWindowAssignedtrackingNumberApplyEtaWindows (AssignEta)customer-ordering (tracking view)
PackageDeliveryPointFlagged...journey.PackageDeliveryPointFlaggedtrackingNumberRelayDeliveryPointFlag, one per package of the stopcustomer-ordering
PackageHandedToCarrier...journey.PackageHandedToCarriertrackingNumbera scan taking AT_STATION to WITH_CARRIERdelivery-promise
PackageReadyForCollection...journey.PackageReadyForCollectiontrackingNumbera scan taking the journey to READY_FOR_COLLECTIONdelivery-promise
PackageCollected...journey.PackageCollectedtrackingNumbera scan taking the journey to COLLECTEDnone named

The consumer column comes from the AsyncAPI descriptions; this repository does not verify that each consumer is deployed. In the table ... abbreviates com.retailnetwork.logistics.shipping-and-tracking.

LabelIssued​

Source: internal/domain/label/events.go, labelIssuedData.

FieldTypeMeaning
labelRefstringIdentity of the label
trackingNumberstringThe package's network-wide unique id
poNumberstringThe purchase order the package belongs to
assignmentIdstringThe fulfillment assignment behind the purchase order
orderIdstringThe customer order (additive field, ADR 0002 A12)
packageNointegerPackage number within the purchase order
tierenum SAME_DAY, NEXT_DAY, TWO_DAY, STANDARDService tier printed on the label
carrierstringRN-EXPRESS or RN-GROUND
stopKeystringOpaque HMAC-SHA-256 of the normalised ship-to address, 64 lower-case hex characters. The address itself never leaves this context
destinationPostalPrefixstringThe first five letters or digits of the normalised postal code
destinationStationNodeIdstring, optionalThe delivery station of the area covering destinationPostalPrefix (ADR 0019): a node id only, omitted when no station is known for the prefix and on a reverse label

LabelVoided​

FieldTypeMeaning
labelRefstringIdentity of the label
trackingNumberstringTracking number of the voided label
reasonstringWhy it was voided, 1 to 500 characters

PackageScanned​

Source: internal/domain/journey/events.go, packageScannedData.

FieldTypeMeaning
trackingNumberstringThe package
scanIdstringIdentity of the applied scan
nodeIdstringWhere the package was observed
scanTypeenum, the eight scan typesKind of observation
attimestampWhen it was observed (the scan's own time)
stateenum, the nine journey statesJourney state after the scan

PackageHandedOver​

FieldTypeMeaning
trackingNumberstringThe package
poNumberstringThe purchase order, so node-performance can compare with its required ship-by
nodeIdstringThe vendor node it left (origin of the pickup departure)
handedOverAttimestampThe handover instant

PackageDelivered​

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment, for order-sourcing
orderIdstringThe customer order
deliveredAttimestampTime of the successful attempt

PackageExceptionRaised​

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment
orderIdstringThe customer order
reasonstringNO_SCAN, the only reason
attimestampWhen the exception was raised (the sweep's clock)

PackageReturned​

FieldTypeMeaning
trackingNumberstringThe package
orderIdstringThe customer order
returnedAttimestampThe at of the consumed PackageReturnInitiated

PackageLost​

FieldTypeMeaning
trackingNumberstringThe package
orderIdstringThe customer order
declaredAttimestampWhen the sweep declared the package lost

PackageEtaWindowAssigned​

Source: internal/domain/journey/journey_eta.go, packageEtaWindowAssignedData (ADR 0013). Not a scan: the state does not change.

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment
orderIdstringThe customer order
etaStarttimestampStart of the day-of ETA window, as last-mile-delivery stated it
etaEndtimestampEnd of the window, after etaStart
assignedAttimestampThe route start instant: the CloudEvents time of the consumed StopEtaWindowAssigned. A window is current only while the journey is OUT_FOR_DELIVERY and assignedAt is not before the last applied scan

PackageDeliveryPointFlagged​

Source: internal/adapters/outbound/kafka/encoder_point_flag.go, packageDeliveryPointFlaggedData (ADR 0014). Not a scan: the state does not change. A newer flag replaces an older one.

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment
orderIdstringThe customer order, so customer-ordering can warn the shopper
reasonenum NOT_HOME, ACCESS_PROBLEMWhy last-mile-delivery flagged the delivery point
flaggedAttimestampWhen the flag was raised, from the consumed DeliveryPointFlagged

PackageHandedToCarrier​

Source: internal/adapters/outbound/kafka/encoder_carrier.go, packageHandedToCarrierData (ADR 0015). Raised once per journey.

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment
orderIdstringThe customer order
carrierIdstringThe carrier chosen at the station (ADR 0015)
handoffNodeIdstringThe handoff node of the chosen carrier option
destinationPostalPrefixstringThe label's postal prefix
handedAttimestampThe time of the handoff scan

PackageReadyForCollection​

Source: internal/adapters/outbound/kafka/encoder_pickup.go, readyForCollectionData (ADR 0016).

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment
orderIdstringThe customer order
pickupPointIdstringThe pickup point the package was deposited at
readyForCollectionAttimestampThe time of the deposit scan
holdUntiltimestampThe retention deadline the uncollected sweep returns the package after

PackageCollected​

Source: internal/adapters/outbound/kafka/encoder_pickup.go, collectedData (ADR 0016). COLLECTED is terminal.

FieldTypeMeaning
trackingNumberstringThe package
assignmentIdstringThe assignment
orderIdstringThe customer order
pickupPointIdstringThe pickup point
collectedAttimestampThe time of the collection scan
proofCodestringOptional; omitted when no proof was taken

Example envelope: PackageDelivered​

PackageDelivered closes the journey and is what delivery-promise and order-sourcing react to. The values are synthetic.

{
"specversion": "1.0",
"id": "5b6f2a0e-8d1c-4f7a-9c3e-2a41d7e9b0c4",
"source": "/retailnetwork/shipping-and-tracking",
"type": "com.retailnetwork.logistics.shipping-and-tracking.journey.PackageDelivered",
"subject": "RN7K3Q2M4B6D5F2XAB",
"time": "2026-10-22T17:42:12Z",
"datacontenttype": "application/json",
"dataschema": "urn:retailnetwork:shipping-and-tracking:events:PackageDelivered:v1",
"data": {
"trackingNumber": "RN7K3Q2M4B6D5F2XAB",
"assignmentId": "asg-7f3c21",
"orderId": "ord-20261021-0091",
"deliveredAt": "2026-10-22T17:42:10Z"
}
}

Consumed​

Source: internal/adapters/inbound/kafka/handlers.go, handlers_lastmile.go and handlers_nodetopology.go. Consumers dispatch on the full type string, never on a suffix; unknown types and unknown fields are ignored.

ProducerFull typeTopicFields usedWhat this context does
vendor-connectivitycom.retailnetwork.partner.vendor-connectivity.purchaseorder.VendorShipmentConfirmedretailnetwork.vendor-connectivity.eventspoNumber, nodeId, trackingNumbers, shippedAtOne SHIPMENT_CONFIRMED scan per tracking number at nodeId. It is applied and raises PackageScanned, but a LABELLED journey stays LABELLED (handover comes from the pickup scan)
linehaul-transportationcom.retailnetwork.logistics.linehaul-transportation.load.LoadDepartedretailnetwork.linehaul-transportation.eventsoriginNodeId, trackingNumbers, departedAt, departureKindOne scan per tracking number at originNodeId. Kind PICKUP (or no kind on a LABELLED journey) is PICKUP_DEPARTURE, the handover. Any other kind is DEPARTURE
linehaul-transportation...load.LoadArrivedsame topicdestinationNodeId, trackingNumbers, arrivedAt, nodeType (or destinationNodeType)STATION_ARRIVAL when the node type is DELIVERY_STATION, otherwise TRANSIT_ARRIVAL
last-mile-deliverycom.retailnetwork.logistics.last-mile-delivery.route.PackageOutForDeliveryretailnetwork.last-mile-delivery.eventstrackingNumber, stationNodeId, atOUT_FOR_DELIVERY scan at stationNodeId
last-mile-delivery...route.DeliveryAttemptedsame topictrackingNumber, outcome, atOutcome DELIVERED gives a DELIVERED scan, any other outcome DELIVERY_FAILED. The event has no node id: the scan takes the node of the journey's last applied scan
last-mile-delivery...packageattempthistory.PackageReturnInitiated (the route spelling is accepted)same topictrackingNumber, atReturnToSender: AT_STATION to RETURNED, raising PackageReturned
last-mile-delivery...route.StopEtaWindowAssignedsame topictrackingNumbers, etaStart, etaEnd; the CloudEvents time is the assignedAtApplyEtaWindows: AssignEta on every package of the stop, raising PackageEtaWindowAssigned. A stale window, a closed journey and an unknown tracking number are counted and acknowledged; stopNo, stopKey and routeId are not kept
last-mile-delivery...deliverypointprofile.DeliveryPointFlagged (ADR 0014)same topictrackingNumbers, reason (NOT_HOME or ACCESS_PROBLEM), flaggedAt; stopKey and failures are not usedRelayDeliveryPointFlag: stores the flag on every journey of the stop and raises PackageDeliveryPointFlagged per package. A stale flag, a closed journey and an unknown tracking number are counted and acknowledged
offer-availabilitycom.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemCreatedretailnetwork.offer-availability.eventscatalogItemId, title, lengthMm, widthMm, heightMm, weightG, hazmat, fragileUpsert of catalog_dimensions
node-topologycom.retailnetwork.logistics.node-topology.servicearea.ServiceAreaAssigned (ADR 0015)retailnetwork.node-topology.eventspostalPrefix, assignmentVersion, deliveryMode, carriers, deliveryStationNodeId (kept, ADR 0019); regionId is read and droppedUpsert of area_modes, only when assignmentVersion is newer than the stored row; an equal version also fills a station the stored row lacks (ADR 0019). An absent deliveryMode and carriers mean NETWORK_ROUTE with no options
node-topology...node.NodeRegistered (ADR 0016, ADR 0018)same topicevery node type: nodeId, postalCode; a pickup point also: nodeType, servingStationNodeIdNoteNodeDestination: upserts the node's row of node_destinations with the prefix derived from postalCode (shipto.NodePrefix: the first five characters from A-Z 0-9; an unusable code keeps the node with an empty prefix). Then, for a PICKUP_POINT node only, NotePickupPoint adds a pickup-point row in state PROPOSED. A registration without a nodeId is dead-lettered
node-topology...node.NodeActivated, ...node.NodeSuspended, ...node.NodeRetired (ADR 0016)same topicnodeIdSets the state of the pickup-point row the view holds to ACTIVE, SUSPENDED or RETIRED and changes nothing else: station and prefix come from NodeRegistered alone. A node with no pickup-point row (every node of another type) is acknowledged without an effect and no row is made; a RETIRED row is kept and never revived (usecases/points.go, NotePickupPoint.ExecuteStatus; ADR 0016 addendum 2026-11-18). They never reach node_destinations: a status fact can neither demote nor erase a node's prefix

Idempotency​

  • Inbox. ApplyScans and ReturnToSender claim (consumer, CloudEvents id) in processed_events first, in the same transaction as every journey change of the event. A message whose id is already claimed is acknowledged and skipped. RecordCatalogItem claims the same way.
  • Per-scan dedupe. One load event names many tracking numbers. The scan id is <CloudEvents id>:<trackingNumber>, so a scan is applied once per package even if the claim were lost. A duplicate scan is counted and acknowledged, never retried.
  • Out of order and no edge. Stored with applied=false, counted, acknowledged.
  • Closed journeys. Counted and acknowledged; a scan after delivery is a producer-side anomaly, not a retry case.
  • Unknown tracking number. One this context never issued is counted and acknowledged. There is no dead-letter for it.
  • Read model. catalog_dimensions is an upsert on catalogItemId and is naturally idempotent.
  • One inbox identity per fold of NodeRegistered. The pickup-point fold claims the event id as consumer node-topology, the node destination fold as node-topology.node-destinations (internal/adapters/inbound/kafka/handlers.go), each in its own transaction. A redelivered id is skipped by whichever fold already claimed it; an id the older fold claimed before ADR 0018 is still new to the node destination fold, which is what lets a replay of the topic fill node_destinations (see the runbook).
  • Dead letters. A transient failure retries with capped backoff and is then written to <topic>.dlq; a handled type whose payload can never be applied is dead-lettered at once.