Skip to main content

Domain Events

As built

Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses.

Every event this context publishes and consumes, from contexts[last-mile-delivery].publishes and .consumes and the network-wide conventions.cloudevents (event standard, ADR 0007).

Envelope​

AttributeValue
specversion1.0
ida UUID minted once per event and stored in the outbox row, so a relay retry carries the same id
source/retailnetwork/last-mile-delivery
typecom.retailnetwork.logistics.last-mile-delivery.<entity>.<EventName>; <entity> is wave, route, packageattempthistory or deliverypointprofile
subjectthe aggregate root id: waveId for wave events, routeId for route events, the trackingNumber for packageattempthistory events, the stopKey for deliverypointprofile events
timethe instant the fact happened, UTC
datacontenttypeapplication/json
dataschemaurn:retailnetwork:last-mile-delivery:events:<EventName>:v1
Kafka topicretailnetwork.last-mile-delivery.events
Kafka keythe same aggregate root id as subject, so one wave's (or one route's) events stay ordered on one partition

Every event is written to outbox_events in the same transaction as the aggregate and drained by a relay (model integration_rules).

Published​

EventFull typeSubject / keyProducing command (use case)Consumers
DeliveryWaveScheduledcom.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveScheduledwaveIdScheduleWavedelivery-promise, order-sourcing
WaveCostDeclaredcom.retailnetwork.logistics.last-mile-delivery.wave.WaveCostDeclaredwaveIdDeclareCostorder-sourcing
WaveEmissionDeclaredcom.retailnetwork.logistics.last-mile-delivery.wave.WaveEmissionDeclaredwaveIdDeclareEmissionorder-sourcing
DeliveryWaveCapacityChangedcom.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveCapacityChangedwaveIdInductPackage (policies InductOnArrival, RetryNextWave)delivery-promise, order-sourcing
DeliveryWaveCancelledcom.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveCancelledwaveIdCancelWaveanalytics only
RoutePlannedcom.retailnetwork.logistics.last-mile-delivery.route.RoutePlannedrouteIdPlanRouteanalytics only
PackageOutForDeliverycom.retailnetwork.logistics.last-mile-delivery.route.PackageOutForDeliveryrouteIdStartRoute (one per tracking number)shipping-and-tracking
PackagePickupOutcom.retailnetwork.logistics.last-mile-delivery.route.PackagePickupOutrouteIdStartRoute (one per package inducted as a PICKUP; dormant, service ADR 0017)none
StopEtaWindowAssignedcom.retailnetwork.logistics.last-mile-delivery.route.StopEtaWindowAssignedrouteIdStartRoute (one per stop, after every PackageOutForDelivery)shipping-and-tracking
DeliveryAttemptedcom.retailnetwork.logistics.last-mile-delivery.route.DeliveryAttemptedrouteIdRecordAttemptshipping-and-tracking
PackageInductionDeferredcom.retailnetwork.logistics.last-mile-delivery.packageattempthistory.PackageInductionDeferredtrackingNumberInductPackage (RetryNextWave, no eligible wave)delivery-promise
PackageReturnInitiatedcom.retailnetwork.logistics.last-mile-delivery.packageattempthistory.PackageReturnInitiatedtrackingNumberInductPackage (RetryNextWave, three failures)shipping-and-tracking
DeliveryPointFlaggedcom.retailnetwork.logistics.last-mile-delivery.deliverypointprofile.DeliveryPointFlaggedstopKeyRecordAttempt (the DeliveryPointProfile of the stop, inside the same unit of work)shipping-and-tracking

"Analytics only" is the model's consumer value. No context consumes those two events. The model names an analytics topic convention (retailnetwork.last-mile-delivery.analytics), but it does not say whether these events go there instead of the integration topic, or as well.

DeliveryWaveScheduled​

FieldType (proposed)Meaning
waveIdstringthe wave
stationNodeIdstringthe delivery station (node-topology nodeId)
serviceDatedatethe station's local service date
inductCutoffAtdate-timelast instant a package can join the wave
windowStartdate-timedelivery window start
windowEnddate-timedelivery window end
stopCapacityintegerstops the wave can take

DeliveryWaveCapacityChanged​

FieldType (proposed)Meaning
waveIdstringthe wave
stopCapacityintegerstops the wave can take
assignedStopsintegerstops already assigned
remainingStopsintegerstopCapacity - assignedStops

Consumers apply it as a full snapshot, not a delta, so the latest event by time wins and a duplicate does no harm.

WaveCostDeclared​

FieldType (proposed)Meaning
waveIdstringthe wave
costPerStopCentsintegerthe planner's declared marginal cost of one stop, integer cents (0 to 10000000; 0 is a legal declared zero)
declaredAtdate-timewhen the planner declared it

Raised by DeclareCost while the wave still runs; a later declaration overwrites the earlier one. order-sourcing sums it into its money-denominated cost.

WaveEmissionDeclared​

FieldType (proposed)Meaning
waveIdstringthe wave
gCo2ePerStopintegerthe planner's declared marginal greenhouse emission of one stop, grams of CO2 equivalent (0 to 10000000; 0 is a legal declared zero)
declaredAtdate-timewhen the planner declared it

Raised by DeclareEmission while the wave still runs (OPEN, INDUCTION_CLOSED or DISPATCHED); a later declaration overwrites the earlier one. The emission is per stop, never per package. order-sourcing sums it into its carbon estimate; its ranking does not change (last-mile-delivery ADR 0016).

DeliveryWaveCancelled​

FieldType (proposed)Meaning
waveIdstringthe wave
reasonstringfree text from the canceller

RoutePlanned​

FieldType (proposed)Meaning
routeIdstringthe route
waveIdstringthe wave it serves
dspIdstringthe delivery service partner
stopCountintegernumber of stops, at most the van capacity

PackageOutForDelivery​

FieldType (proposed)Meaning
routeIdstringthe route
trackingNumberstringthe package
stationNodeIdstringthe station it left
atdate-timewhen the route started

PackagePickupOut​

FieldType (proposed)Meaning
routeIdstringthe route
trackingNumberstringthe pickup package
stopKeystringthe stop the package is collected at
stationNodeIdstringthe station the route left
atdate-timewhen the route started

Raised by StartRoute for a package whose induction kind is PICKUP, in place of PackageOutForDelivery. Dormant: every writer of this context inducts with kind DELIVERY, so none is produced today and no context consumes it (service ADR 0017, policy PickupInductionDormant).

StopEtaWindowAssigned​

FieldType (proposed)Meaning
routeIdstringthe route
stopNointeger, minimum 1the 1-based stop number; a route may hold two stops with one stopKey
stopKeystringthe opaque stop key; pkg:<trackingNumber> when the package has no label data
trackingNumbersarray of string, at least 1the packages of the stop, in stop order
etaStartdate-timewindow start
etaEnddate-timewindow end, after etaStart; the window is at most two hours wide

Raised by StartRoute in the same transaction, after every PackageOutForDelivery, one per stop in stop order, under the same Kafka key (the routeId), so the two stay ordered on one partition. The CloudEvents time is the route start instant (the assignment time). The stops are spread linearly over what is left of the wave's delivery window — a deterministic spread, not a prediction (ADR 0013): no event is raised when less than 30 minutes of the wave window is left at the start instant, an ETA is never retracted and never re-raised for the same start, and a re-inducted package gets a new one from its next StartRoute. A window may fall after the promised delivery window; it is published as computed. The analytics read side keeps one row per package (stop_eta_windows) and the GET /reports/eta-window report measures the share of deliveries inside the window.

DeliveryAttempted​

FieldType (proposed)Meaning
routeIdstringthe route
trackingNumberstringthe package
outcomeDELIVERED | FAILEDthe attempt result
outcomeDetailNOT_HOME | ACCESS_PROBLEM | OTHER | SAFE_PLACE_USED, optionalthe driver-reported category (ADR 0014): FAILED carries NOT_HOME, ACCESS_PROBLEM or OTHER, DELIVERED carries SAFE_PLACE_USED; omitted means not reported (a legacy client)
failureReasonstring, null when DELIVEREDwhy it failed; the model gives no vocabulary
atdate-timewhen the attempt happened

PackageInductionDeferred​

FieldType (proposed)Meaning
trackingNumberstringthe package
assignmentIdstring, optionalfrom LabelIssued; omitted only when no label data was received

Raised when no open wave of the station with stop capacity accepts the package; delivery-promise treats it as a risk.

PackageReturnInitiated​

FieldType (proposed)Meaning
trackingNumberstringthe package

Raised by the third failed attempt; the package is not re-inducted.

DeliveryPointFlagged​

FieldType (proposed)Meaning
stopKeystringthe opaque keyed hash of the address; never an address
reasonNOT_HOME | ACCESS_PROBLEMACCESS_PROBLEM when any open strike has it, else NOT_HOME
failuresinteger, 2 to 5strikes open at that moment
trackingNumbersarray of string, 1 to 5only the packages newly affected by this event
flaggedAtdate-timethe attempt instant that triggered the event

Raised by the DeliveryPointProfile of the stop, inside RecordAttempt's unit of work (ADR 0014), after two counted failed attempts (NOT_HOME or ACCESS_PROBLEM) inside a 60-day window, one strike per route visit. There is no "cleared" event: a delivered attempt ends the episode inside the profile, and consumers end their own view of the flag when the package ends. The feature is dormant until the driver client reports outcomeDetail: until then no strike is counted and no event is raised.

No published event carries an address, a name or any other PII (ADR 0006).

Example envelope​

DeliveryWaveScheduled is the most important event of this context: it is the fact the promise's last leg rests on.

{
"specversion": "1.0",
"id": "5b1f0f8e-4c1e-4b8e-9a51-2f3c0d9e7a14",
"source": "/retailnetwork/last-mile-delivery",
"type": "com.retailnetwork.logistics.last-mile-delivery.wave.DeliveryWaveScheduled",
"subject": "wave-DS-ATL1-2026-10-23-W1",
"time": "2026-10-22T14:05:11Z",
"datacontenttype": "application/json",
"dataschema": "urn:retailnetwork:last-mile-delivery:events:DeliveryWaveScheduled:v1",
"data": {
"waveId": "wave-DS-ATL1-2026-10-23-W1",
"stationNodeId": "node-DS-ATL1",
"serviceDate": "2026-10-23",
"inductCutoffAt": "2026-10-23T09:30:00Z",
"windowStart": "2026-10-23T12:00:00Z",
"windowEnd": "2026-10-23T20:00:00Z",
"stopCapacity": 2400
}
}

The identifiers and numbers are illustrative. They are not taken from any real network.

Consumed​

ProducerFull typeTopicWhat this context does with itIdempotency
linehaul-transportationcom.retailnetwork.logistics.linehaul-transportation.load.LoadArrivedretailnetwork.linehaul-transportation.eventsUses loadId, departureId, destinationNodeId, trackingNumbers, arrivedAt. Also uses nodeType. If nodeType is DELIVERY_STATION (when it is absent, if destinationNodeId is a delivery station in StationView), records the arrivals in InboundPackagesView and runs InductOnArrival: one InductPackage per tracking number into the earliest eligible wave. Loads arriving at any other node are ignored.Inbox on the CloudEvents id (processed_events), in the same transaction as the view write. Each InductPackage is also a no-op for a tracking number already inducted into an open wave.
shipping-and-trackingcom.retailnetwork.logistics.shipping-and-tracking.label.LabelIssuedretailnetwork.shipping-and-tracking.eventsUses trackingNumber, assignmentId, stopKey, destinationPostalPrefix. Keeps them in PackageStopView; InductOnArrival groups packages into stops by stopKey, and wave capacity counts distinct stop keys. A package without a label row is its own stop.Inbox on the CloudEvents id; the first write per trackingNumber is kept (ON CONFLICT DO NOTHING; ADR 0003). A label without stopKey is ignored.
node-topologycom.retailnetwork.logistics.node-topology.node.NodeRegisteredretailnetwork.node-topology.eventsUses nodeId, nodeType, regionId, timezone. Keeps DELIVERY_STATION nodes in StationView; the time zone fixes a station's service date. Other node types are ignored.Inbox on the CloudEvents id; the first write per nodeId is kept (ON CONFLICT DO NOTHING; a node type never changes; ADR 0003).
node-topologycom.retailnetwork.logistics.node-topology.servicearea.ServiceAreaAssignedretailnetwork.node-topology.eventsUses postalPrefix, deliveryStationNodeId, regionId, assignmentVersion. Keeps the prefixes each station serves in StationView. Also uses deliveryMode (omitted means NETWORK_ROUTE): a prefix whose mode is CARRIER_HANDOFF is carrier territory and InductPackage refuses its packages (last-mile-delivery ADR 0015).Inbox on the CloudEvents id; applied only if assignmentVersion is higher than the stored one.

Consumers dispatch on the full type string, never on a suffix (model integration_rules). Any other type on those topics is acknowledged and ignored.