Skip to main content

Event catalogue

Contract: apis/asyncapi.yaml (AsyncAPI 3.0.0), catalogued in ADR 0004 (published) and ADR 0003 (consumed). TestEventCatalogueMatchesContract and TestConsumedTypesAreDocumented keep the spec, the code and the ADRs aligned. Field-level detail is on Domain events.

Envelope​

Every message is CloudEvents 1.0 in structured content mode with Kafka header content-type: application/cloudevents+json; charset=UTF-8 (internal/adapters/kafka/cloudevents/cloudevents.go):

AttributeValue
specversion1.0
idUUID, minted once when the event is encoded and stored in outbox_events.event_id: a relay retry republishes the same id
source/retailnetwork/shipping-and-tracking
typecom.retailnetwork.logistics.shipping-and-tracking.<entity>.<EventName> with entity label or journey
subjectthe aggregate root id: labelRef for label events, trackingNumber for journey events
timeRFC 3339 UTC
datacontenttypeapplication/json
dataschemaurn:retailnetwork:shipping-and-tracking:events:<EventName>:v1

The Kafka key is the subject, so one aggregate's events stay ordered on one partition. data is camelCase, optional fields are omitted when unset, arrays are always present. A breaking payload change is a new .v2 type, never a mutation. Trace context (traceparent, tracestate) rides as additional Kafka headers.

Published: retailnetwork.shipping-and-tracking.events​

Delivery is at-least-once through the transactional outbox: the aggregate rows and the encoded events are written in one database transaction and the relay (internal/adapters/outbound/outbox/relay.go) drains them. Consumers dedupe on id.

Event (type suffix)Raised byPayload (data)Known consumers (per the AsyncAPI)
label.LabelIssuedIssueLabellabelRef, trackingNumber, poNumber, assignmentId, orderId, packageNo, tier, carrier, stopKey, destinationPostalPrefix, optional destinationStationNodeId (ADR 0019)linehaul-transportation, customer-ordering, last-mile-delivery
label.LabelVoidedVoidLabellabelRef, trackingNumber, reasoncustomer-ordering, linehaul-transportation
journey.PackageScannedevery applied scantrackingNumber, scanId, nodeId, scanType, at, statenone named
journey.PackageHandedOverLABELLED to HANDED_OVERtrackingNumber, poNumber, nodeId, handedOverAtnode-performance
journey.PackageDeliveredOUT_FOR_DELIVERY to DELIVEREDtrackingNumber, assignmentId, orderId, deliveredAtdelivery-promise, order-sourcing, customer-ordering
journey.PackageExceptionRaisedsilence sweep, reason NO_SCANtrackingNumber, assignmentId, orderId, reason, atdelivery-promise, customer-ordering
journey.PackageReturnedAT_STATION to RETURNEDtrackingNumber, orderId, returnedAtdelivery-promise
journey.PackageLostIN_TRANSIT to LOSTtrackingNumber, orderId, declaredAtdelivery-promise
journey.PackageEtaWindowAssignedApplyEtaWindows, one per package of the stoptrackingNumber, assignmentId, orderId, etaStart, etaEnd, assignedAtcustomer-ordering (tracking view)
journey.PackageDeliveryPointFlaggedRelayDeliveryPointFlag, one per package of the stoptrackingNumber, assignmentId, orderId, reason, flaggedAtcustomer-ordering (tracking view advisory)
journey.PackageHandedToCarriera scan taking AT_STATION to WITH_CARRIER (ADR 0015)trackingNumber, assignmentId, orderId, carrierId, handoffNodeId, destinationPostalPrefix, handedAtdelivery-promise
journey.PackageReadyForCollectiona scan taking the journey to READY_FOR_COLLECTION (ADR 0016)trackingNumber, assignmentId, orderId, pickupPointId, readyForCollectionAt, holdUntildelivery-promise
journey.PackageCollecteda scan taking the journey to COLLECTED (ADR 0016)trackingNumber, assignmentId, orderId, pickupPointId, collectedAt, optional proofCodenone named

A handover or delivery raises two events in one transaction: PackageScanned and the milestone event. A scan stored out of order or without an edge raises nothing. PackageEtaWindowAssigned is not a scan: it carries the day-of ETA window of the package's stop and never changes the state (ADR 0013). No event carries a ship-to address; stopKey is the HMAC-SHA-256 (64 lower-case hex characters) of the normalised address and destinationPostalPrefix its first five letters or digits.

Example (LabelIssued, from the AsyncAPI; the values are synthetic):

{
"specversion": "1.0",
"id": "3f6c2a9e-8b1d-4c7a-9e55-0d2f6b7a1c01",
"source": "/retailnetwork/shipping-and-tracking",
"type": "com.retailnetwork.logistics.shipping-and-tracking.label.LabelIssued",
"subject": "lbl-7c1f",
"time": "2026-10-23T12:00:00Z",
"datacontenttype": "application/json",
"dataschema": "urn:retailnetwork:shipping-and-tracking:events:LabelIssued:v1",
"data": {
"labelRef": "lbl-7c1f",
"trackingNumber": "STT00000000000042",
"poNumber": "PO-1001",
"assignmentId": "asg-001",
"orderId": "ord-001",
"packageNo": 1,
"tier": "NEXT_DAY",
"carrier": "RN-EXPRESS",
"stopKey": "9f2a6c0d4b7e11aa5c3d8e90b1f47a62c8d0e3f15a9b7c24d6e8f0a1b3c5d7e9",
"destinationPostalPrefix": "01310"
}
}

When the area covering destinationPostalPrefix has a known delivery station, data also carries "destinationStationNodeId": "node-ds-07" after destinationPostalPrefix (ADR 0019): a node id, never an address. The field is omitted when no station is known (and on a reverse label), and an event without it is byte-identical to the ones published before the field existed.

Consumed​

Each topic has one consumer group (an environment variable, mandatory), a dead-letter topic <topic>.dlq, and an inbox row (consumer, event_id) in processed_events written in the same transaction as the effect. Unknown types and unknown fields are ignored. Handlers: internal/adapters/inbound/kafka/handlers.go, handlers_lastmile.go, handlers_nodetopology.go.

TopicTypeEffect
retailnetwork.vendor-connectivity.eventscom.retailnetwork.partner.vendor-connectivity.purchaseorder.VendorShipmentConfirmedone SHIPMENT_CONFIRMED scan per tracking number (the journey stays LABELLED)
retailnetwork.linehaul-transportation.eventscom.retailnetwork.logistics.linehaul-transportation.load.LoadDeparteddepartureKind PICKUP gives PICKUP_DEPARTURE (handover); other kinds give DEPARTURE; an absent kind promotes a DEPARTURE to PICKUP_DEPARTURE while the journey is still LABELLED
retailnetwork.linehaul-transportation.eventscom.retailnetwork.logistics.linehaul-transportation.load.LoadArrivednode type DELIVERY_STATION gives STATION_ARRIVAL, anything else TRANSIT_ARRIVAL
retailnetwork.last-mile-delivery.eventscom.retailnetwork.logistics.last-mile-delivery.route.PackageOutForDeliveryOUT_FOR_DELIVERY scan at stationNodeId
retailnetwork.last-mile-delivery.eventscom.retailnetwork.logistics.last-mile-delivery.route.DeliveryAttemptedoutcome DELIVERED gives a DELIVERED scan, any other outcome DELIVERY_FAILED (back to AT_STATION)
retailnetwork.last-mile-delivery.eventscom.retailnetwork.logistics.last-mile-delivery.packageattempthistory.PackageReturnInitiated (the route spelling is accepted as an alias)ReturnToSender: AT_STATION to RETURNED, raising PackageReturned
retailnetwork.last-mile-delivery.eventscom.retailnetwork.logistics.last-mile-delivery.route.StopEtaWindowAssignedAssignEta on every tracking number of the stop (the CloudEvents time is the assignedAt); raises PackageEtaWindowAssigned; the stop key is dropped
retailnetwork.last-mile-delivery.eventscom.retailnetwork.logistics.last-mile-delivery.deliverypointprofile.DeliveryPointFlagged (ADR 0014)RelayDeliveryPointFlag on every tracking number of the stop: stores the flag and raises PackageDeliveryPointFlagged per package; stopKey and failures are not used
retailnetwork.offer-availability.eventscom.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemCreatedupsert of the local catalog_dimensions read model
retailnetwork.node-topology.eventscom.retailnetwork.logistics.node-topology.servicearea.ServiceAreaAssigned (ADR 0015)upsert of the local area_modes read model, only when assignmentVersion is newer than the stored row (an equal version also fills a missing deliveryStationNodeId, which is kept, ADR 0019)
retailnetwork.node-topology.eventscom.retailnetwork.logistics.node-topology.node.NodeRegistered (ADR 0016, ADR 0018)a node of any type adds or replaces its row of the local node destination view (node_destinations: the node id and the destination prefix derived from postalCode); a PICKUP_POINT node also adds a row to the local pickup-point view
retailnetwork.node-topology.eventscom.retailnetwork.logistics.node-topology.node.NodeActivated, ...NodeSuspended, ...NodeRetired (ADR 0016)sets the state of the pickup-point row this context holds to ACTIVE, SUSPENDED or RETIRED and nothing else (station and prefix come from NodeRegistered alone); no row is made for a node that is not a held pickup point, and a RETIRED row is kept for good. None of the three reaches the node destination view

Scan ids of consumed events are <CloudEvents id>:<trackingNumber>, so a multi-package load event is idempotent per package. Events for tracking numbers this service did not label are counted as unknown and acknowledged.

Failure behaviour​

  • A transient handler failure retries the same message with capped exponential backoff (initial 200 ms), then the message is dead-lettered to <topic>.dlq (internal/adapters/inbound/kafka/kafka.go, deadletter.go).
  • A message that is not a valid CloudEvent, or a valid event that can never be applied, is skipped with a WARN (or dead-lettered for handled types), never retried.
  • A PackageReturnInitiated for a journey that is not yet AT_STATION fails with an illegal-transition error and is retried, because the failed-attempt scan may still be on its way (ADR 0003).