ADR 0004: CloudEvents envelope and type catalogue
Status
Accepted (2026-10-23).
Context
Every Kafka message in the retail network is a CloudEvents 1.0 event in structured
mode (retail-network-docs model/model.yaml conventions.cloudevents; the repo
rule .claude/rules/fleet/cloudevents.md). This ADR is the catalogue of every
type last-mile-delivery publishes. TestEventCatalogueMatchesContract checks it
against apis/asyncapi.yaml. The consumed types are listed in ADR 0003.
Decision
Envelope
specversion1.0;ida UUID persisted with the outbox row (stable across relay retries; consumers dedupe on it);source/retailnetwork/last-mile-delivery;subjectthe aggregate root id (waveId,routeIdor, for the per-package history, thetrackingNumber);timethe instant of the change, in UTC;datacontenttypeapplication/json;dataschemaurn:retailnetwork:last-mile-delivery:<stream>:<EventName>:v1with streameventsoranalytics.- Kafka value = the JSON event format; header
content-type: application/cloudevents+json; charset=UTF-8; Kafka key = the subject, so all events of one aggregate stay ordered on one partition. datais camelCase; optional fields are omitted when unset; timestamps are RFC 3339 UTC; the service date isYYYY-MM-DD.- Built and decoded only through
internal/adapters/kafka/cloudevents. <entity>is the raising aggregate, lowercase, no separators:wave,route,packageattempthistory,deliverypointprofile. Tier islogistics.
Published types
Eleven types go ONLY to the integration topic retailnetwork.last-mile-delivery.events
(stream: events); RoutePlanned is analytics-only and goes ONLY to
retailnetwork.last-mile-delivery.analytics (stream: analytics).
DeliveryWaveCancelled is an integration event (Gap Register G5, contracts-delta
E5), no longer analytics-only. PackageInductionDeferred and
PackageReturnInitiated are the Gap Register G16 additions (contracts-delta E15).
WaveCostDeclared is the roadmap F7 provider-B addition (ADR 0011).
WaveEmissionDeclared is the roadmap C9 provider addition (ADR 0016).
StopEtaWindowAssigned is the roadmap E3 addition (ADR 0013).
DeliveryPointFlagged is the roadmap C5 addition (ADR 0014); its entity is
deliverypointprofile and its subject and key are the opaque stopKey.
PackagePickupOut is the roadmap C8-LM addition (ADR 0017); its entity is
route and it shares topic, subject and key with PackageOutForDelivery.
type: com.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveScheduled stream: events
type: com.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveCapacityChanged stream: events
type: com.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveCancelled stream: events
type: com.retailnetwork.logistics.last-mile-delivery.wave.WaveCostDeclared stream: events
type: com.retailnetwork.logistics.last-mile-delivery.wave.WaveEmissionDeclared stream: events
type: com.retailnetwork.logistics.last-mile-delivery.route.RoutePlanned stream: analytics
type: com.retailnetwork.logistics.last-mile-delivery.route.PackageOutForDelivery stream: events
type: com.retailnetwork.logistics.last-mile-delivery.route.PackagePickupOut stream: events
type: com.retailnetwork.logistics.last-mile-delivery.route.DeliveryAttempted stream: events
type: com.retailnetwork.logistics.last-mile-delivery.route.StopEtaWindowAssigned stream: events
type: com.retailnetwork.logistics.last-mile-delivery.packageattempthistory.PackageInductionDeferred stream: events
type: com.retailnetwork.logistics.last-mile-delivery.packageattempthistory.PackageReturnInitiated stream: events
type: com.retailnetwork.logistics.last-mile-delivery.deliverypointprofile.DeliveryPointFlagged stream: events
| Event | Subject / key | Raised when | data |
|---|---|---|---|
DeliveryWaveScheduled | waveId | ScheduleWave is saved (state OPEN) | {waveId, stationNodeId, serviceDate, inductCutoffAt, windowStart, windowEnd, stopCapacity} |
DeliveryWaveCapacityChanged | waveId | an induction adds a new stop to a wave | {waveId, stopCapacity, assignedStops, remainingStops} |
DeliveryWaveCancelled | waveId | CancelWave is saved | {waveId, reason} |
WaveCostDeclared | waveId | DeclareCost is saved (planner's stop-cost declaration, ADR 0011) | {waveId, costPerStopCents, declaredAt} |
WaveEmissionDeclared | waveId | DeclareEmission is saved (planner's stop-emission declaration, ADR 0016) | {waveId, gCo2ePerStop, declaredAt} |
RoutePlanned | routeId | PlanRoute is saved | {routeId, waveId, dspId, stopCount} |
PackageOutForDelivery | routeId | StartRoute is saved, one per tracking number | {routeId, trackingNumber, stationNodeId, at} |
PackagePickupOut | routeId | StartRoute is saved, one per PICKUP tracking number (ADR 0017, activation-gated) | {routeId, trackingNumber, stopKey, stationNodeId, at} |
DeliveryAttempted | routeId | RecordAttempt is saved, one per package | {routeId, trackingNumber, outcome, outcomeDetail?, failureReason?, at} |
StopEtaWindowAssigned | routeId | StartRoute is saved, one per stop, after every PackageOutForDelivery (ADR 0013) | {routeId, stopNo, stopKey, trackingNumbers, etaStart, etaEnd} |
PackageInductionDeferred | trackingNumber | no wave accepts a package that is at the station | {trackingNumber, assignmentId?} |
PackageReturnInitiated | trackingNumber | the third failed attempt of a package | {trackingNumber} |
DeliveryPointFlagged | stopKey | RecordAttempt leaves a delivery point with two open counted failures and packages not told yet (ADR 0014) | {stopKey, reason, failures, trackingNumbers, flaggedAt} |
Payload rules:
- The
datafield lists are exactly the model'spublishes[].datalists plus the two Gap Register G16 events. Wire types are recorded inapis/asyncapi.yaml(ADR 0002, assumption A24). outcomeDetailis optional and present only when the driver client reported one (ADR 0014);failureReasonis present only whenoutcomeisFAILED;assignmentIdis omitted only when noLabelIssuedwas received for the package.CloseInduction,DispatchWave,CompleteWave,StartRoute(other than its per-package events),CompleteRoute,ContractPartnerandDeactivatePartnerraise no wave, route or partner event.- A breaking payload change is a new
.v2type and dataschema, never a mutation of v1.
Consequences
- Consumers need nothing but this catalogue and
apis/asyncapi.yaml; there is no shared Go code. - Adding a published type requires a line here in the same commit as its asyncapi message, or the architecture fitness test fails.
Addendum 2026-11-13: current state
The count in "Published types" is stale. The catalogue above lists eleven types: ten go to retailnetwork.last-mile-delivery.events (stream: events) and RoutePlanned goes to retailnetwork.last-mile-delivery.analytics (stream: analytics). apis/asyncapi.yaml declares the same eleven messages, and TestEventCatalogueMatchesContract checks that every declared type is listed in this ADR.