ADR 0013: the day-of stop ETA window (StopEtaWindowAssigned at StartRoute; roadmap E3 provider)
Status
Accepted (2026-11-11).
Context
A shopper whose parcel is out for delivery sees only the promised delivery window, which can be a whole day. The network's plan for E3 is a day-of ETA window of two hours, relayed by shipping-and-tracking and shown by customer-ordering on the tracking view. This context is the provider: it owns the route, its stop order and the wave whose delivery window bounds the day.
What the code gives it, and what it does not:
- There is no stop sequencer. The station planner sends the numbered stops
(
PlanRoute);route.Planonly validates them. The sequence is the planner's. StartRoutealready loads the wave (DISPATCHEDis required) and the wave carrieswindowStart,windowEndand every induction with itsstopKey.- The context holds no geography, no travel time and no service time. A routing-based ETA is therefore not possible here without a new data source.
Alternatives weighed:
- Derive the ETA from coordinates and travel time. Rejected: nothing in
the context or in its consumed contracts carries a coordinate (PII
confinement keeps the address in customer-ordering and
shipping-and-tracking, and the stop is the opaque
stopKey). - Persist the ETA on the route and serve it on
GET /routes/{routeId}. Rejected:Startis a single transition that commits with its outbox rows (a secondStartRouteis409 illegal-transition), so there is nothing to replay or recompute and no new aggregate field is needed. - Re-raise or retract the ETA as the day goes on. Rejected for this slice: without a position signal nothing would change the answer.
- Publish one event per package. Rejected: the stop is the unit the driver visits and the unit of the computation; the event carries the packages of the stop and consumers fan out by tracking number.
Decision
-
Event
StopEtaWindowAssigned(integration, events topic).- Type
com.retailnetwork.logistics.last-mile-delivery.route.StopEtaWindowAssigned; source/retailnetwork/last-mile-delivery; dataschemaurn:retailnetwork:last-mile-delivery:events:StopEtaWindowAssigned:v1; topicretailnetwork.last-mile-delivery.events; entityroute; subject and Kafka key =routeId(the same key asPackageOutForDelivery, so the two stay ordered on one partition). - data:
routeId(string),stopNo(integer >= 1),stopKey(string, opaque;pkg:<trackingNumber>when the package has no label data),trackingNumbers(string[], at least 1, the packages of the stop in stop order),etaStartandetaEnd(RFC 3339 UTC). CloudEventstime= the route start instant =assignedAt; shipping-and-tracking relies on this. - Raised by
StartRoute, in the same transaction and AFTER everyPackageOutForDelivery, one per stop in stop order. An ETA is never retracted and is never re-raised for the same start; when the wave's window leaves less thanMinEtaSpanat the start instant NO event is raised (no ETA). A package that fails and is re-inducted gets a new ETA from its nextStartRoute. - The plan's field list is extended by
stopNo, because a route may hold two stops with the samestopKey(only the packages within ONE stop must share one), so the plan's fields alone do not identify a stop.
- Type
-
The computation is a pure function in
internal/domain/route/route_eta.gowith named constants and integer duration arithmetic only (no float):constant value EtaWindowWidth2 hours MinEtaSpan30 minutes EtaGrain1 minute EtaWindows(in EtaInput{Now, WindowStart, WindowEnd, Stops []StopRef{No, StopKey, TrackingNumbers}}) []StopEta:from = max(Now, WindowStart),to = WindowEnd,span = to - from. Ifspan < MinEtaSpanreturn nothing.width = min(EtaWindowWidth, span), truncated toEtaGrain.- For stop
kofn:centre = from + (span / (2n)) * (2k - 1)(no overflow: the product is at mostspan).start = centre - width/2; ifstart < fromthenstart = from; ifstart + width > tothenstart = to - width; truncatestarttoEtaGrain;end = start + width.
The stops are spread linearly over the wave's delivery window: this is a deterministic spread, not a prediction. Its quality is unproven; the KPI of point 5 decides whether it is good enough.
-
Route.Start(now, wv)replacesStart(now). It builds theStopRefs from the route's stops and the wave induction'sstopKeyof the stop's first package (a package without an induction isshared.Corrupt, impossible afterPlan) and appends the ETA events after thePackageOutForDeliveryones.StartRoute.Executepasses the wave it already loaded. No aggregate field is added and nothing about the ETA is persisted on the route. -
Observability. Counters
last_mile_delivery.stop_eta.assigned(one per event) andlast_mile_delivery.stop_eta.skipped(attributereason=window_elapsed), through a new small portports.EtaMetricswith the nil-safe pattern ofDeps.metrics(). -
The KPI: share of deliveries inside the ETA window (analytical side, ADR 0012).
- Analytical migration
analytics/migrations/0002_stop_eta_windows:stop_eta_windows(route_id, tracking_number, stop_no, eta_start, eta_end, assigned_at, event_id, PRIMARY KEY (route_id, tracking_number)), one row per package, exploded at projection by one idempotent statement (INSERT ... SELECT unnest(...) ... ON CONFLICT DO NOTHING), plus an index on(tracking_number). - The projector maps the full type to
report.KindStopEtaWindowAssigned;Event.ValidaterequiresstopNo >= 1, at least one tracking number andetaStart < etaEnd. The type leaves the acknowledged-only list. - Report
GET /reports/eta-window(operationIdgetEtaWindowReport, samefrom/toparameters,x-pagination-exempt: report, served bycmd/lm-reports): per UTC day of the DELIVERED attempt and per station (UNKNOWNif not projected):deliveriesWithEta,deliveriesInsideEta,deliveriesBeforeEta,deliveriesAfterEtaandetaHitRate = inside / withEta(null when no delivery had an ETA). Inside meanseta_start <= attempted_at <= eta_end. Only the attempt that DELIVERED counts; a delivered package whose ETA row was never projected is not in the denominator.
- Analytical migration
-
Contract registration.
apis/asyncapi.yaml(message, publish operation, description counts), the type catalogue ADR 0004 (table row and thetype:line),docs/docs/api-reference/events.md, the domain pages and the ADR index move with the code. The encoder payload lives in a new fileencoder_eta.go. -
What this does not do. It does not change any promise, group or judgement; the ETA never reaches delivery-promise. A window that falls after
deliverByLatestis published as computed (no clipping). Nothing carries an address, a name, a phone or free text;stopKeyis the opaque HMAC.
Consequences
- No OLTP migration and no aggregate field.
GET /routes/{routeId}and the MCP and A2Aget_routedo NOT show the ETA: the event and the E3 report are the record. - The integration topic gains one type (nine on the events topic, ten in all); the catalogue and the contract moved in one commit.
- A route start late in the wave window, or a window of less than 30 minutes,
yields no ETA at all (counted as
skipped); the route starts normally. - The first month of
etaHitRateis a baseline, not a verdict: if the linear spread proves poor, a routing signal has to come from outside this context (a new event from the planner), as a new dataschema or an additive field. - Deploy: no env var, topic, consumer group, chart value or secret. The
analytical migration 0002 runs when
cmd/lm-projectorboots. Deploy order across the chain is customer-ordering, shipping-and-tracking, then this service: this service's deploy is the activation of the ETA events, because a consumer ignores a type it has no handler for and commits past it. - Rollback: LM rollback stops the events; consumers see only silence.