ADR 0003: consumed contracts, local read models and relationships
Status
Accepted (2026-10-23).
Context
last-mile-delivery consumes four events and makes no synchronous call into a
sibling context (model sync_calls: [], common rule 4). What it needs from a
neighbour is a local, event-fed read model.
Decision
Consumed events
| Event (full type) | Producer | Topic | Read model | Used by |
|---|---|---|---|---|
com.retailnetwork.logistics.linehaul-transportation.load.LoadArrived | linehaul-transportation | retailnetwork.linehaul-transportation.events | rm_inbound_packages (InboundPackagesView) | policy InductOnArrival |
com.retailnetwork.logistics.node-topology.node.NodeRegistered | node-topology | retailnetwork.node-topology.events | rm_stations (StationView) | ScheduleWave, ContractPartner, LoadArrived (A8) |
com.retailnetwork.logistics.node-topology.servicearea.ServiceAreaAssigned | node-topology | retailnetwork.node-topology.events | rm_station_service_areas (StationView) | none yet (A28) |
com.retailnetwork.logistics.shipping-and-tracking.label.LabelIssued | shipping-and-tracking | retailnetwork.shipping-and-tracking.events | rm_package_stops (PackageStopView) | stop grouping (G11), assignmentId (A20) |
LabelIssued is the addition of contracts-delta E10 (stopKey and
destinationPostalPrefix on the label event); LoadArrived carries nodeType
since E3. The producers' AsyncAPI files are the authority: node-topology's was
read from origin/feature/service; linehaul-transportation's and
shipping-and-tracking's were not pushed when this was written, so their inbound
contracts were built from the model fields, contracts-delta and the wire
conventions, and are vendored here (apis/asyncapi.yaml, receive operations)
as tolerant copies of the fields used. They are to be re-checked against the
producers' files once pushed.
Consumption rules
- One consumer per topic, one consumer group per consumer, each a mandatory
environment variable (
LINEHAUL_CONSUMER_GROUP,NODE_TOPOLOGY_CONSUMER_GROUP,SHIPPING_CONSUMER_GROUP); a missing one is a boot error naming it. - The CloudEvents
idis claimed inprocessed_events(the inbox) in the SAME transaction as the effect; a redelivered event is applied once. - Dispatch is on the full
typestring; an unknown type and unknown fields are ignored; a message that is not a CloudEvents 1.0 event, or whosedatacannot be decoded, goes to the dead-letter topic (<topic>.dlq) at once and the offset is committed; a transient failure is retried five times before the same fate. - A deterministic skip (a
LoadArrivedwhosenodeTypeis notDELIVERY_STATION, or a decodable event with no usable key) is not retried: the event is applied as "ignored" and marked processed (ADR 0002 A8: the event'snodeTypewins; theStationViewis consulted only when the event carries none). A transient failure (database, concurrent update after the retry) is returned so the message is redelivered. NodeRegisteredkeeps onlyDELIVERY_STATIONnodes (first write wins; a node type never changes).ServiceAreaAssignedis applied only when itsassignmentVersionis higher than the stored one for the prefix.LabelIssuedkeeps the first values per tracking number; a label withoutstopKeyis ignored (A4).LoadArrivedrecords every tracking number inrm_inbound_packagesand inducts it under ADR 0002 A6 to A8, A18 and A19.
Relationships (model inbound)
- linehaul-transportation: Customer/Supplier (upstream, we conform to its fields and ask for additions through the orchestrator).
- node-topology: Conformist.
- shipping-and-tracking: upstream for
LabelIssued(Customer/Supplier), downstream of us forPackageOutForDelivery,DeliveryAttemptedandPackageReturnInitiated. - delivery-promise and order-sourcing: downstream of the wave events; the
published contract is
apis/asyncapi.yamland ADR 0004. - station planner and DSP driver app: UI over REST (
apis/openapi.yaml).
Publishing
Every published event leaves through a transactional outbox (outbox_events):
the aggregates and the encoded CloudEvents rows commit in one transaction and an
always-on relay writes them to Kafka (ADR 0004).
Consequences
- A station that was never registered cannot receive waves or partners. A
LoadArrivedfor it that carriesnodeType: DELIVERY_STATIONstill inducts or defers its packages (thePackageInductionDeferredrisk signal is kept); one with nonodeTypeis ignored until theNodeRegisteredis consumed. - The
rm_tables lag their producers; no aggregate holds a foreign key to them.
Known consumer mismatch on what this context publishes (checked 2026-10-23)
delivery-promise (apis/asyncapi.yaml on origin/feature/service) consumes PackageInductionDeferred under the type
com.retailnetwork.logistics.last-mile-delivery.package.PackageInductionDeferred. This context publishes it under
...last-mile-delivery.packageattempthistory.PackageInductionDeferred, because the entity segment is the raising
aggregate (contracts-delta, wire conventions) and the aggregate is PackageAttemptHistory. shipping-and-tracking
accepts the packageattempthistory type for PackageReturnInitiated. Nothing is adapted here: the producer type stays
as catalogued in ADR 0004, and delivery-promise has to accept it (or the orchestrator has to rule on the entity name).
Addendum 2026-11-13: current state
The mismatch above is closed. delivery-promise consumes PackageInductionDeferred under the type this context publishes, ...last-mile-delivery.packageattempthistory.PackageInductionDeferred (its internal/adapters/inbound/kafka/dispatch.go and apis/asyncapi.yaml on develop; changed by its commit e99c9a1, "PackageInductionDeferred entity is packageattempthistory"). shipping-and-tracking accepts the packageattempthistory type for PackageReturnInitiated and tolerates a route entity segment (its internal/adapters/inbound/kafka/handlers.go).
The other published events with a named reader outside this repository: delivery-promise and order-sourcing consume DeliveryWaveCancelled; order-sourcing consumes WaveCostDeclared; shipping-and-tracking consumes StopEtaWindowAssigned and DeliveryPointFlagged. The current list is in docs/docs/ddd/domain-events.md.