Skip to main content

ADR 0003: consumed contracts, local read models and relationships

Status​

Accepted (2026-10-23).

Context​

customer-ordering consumes events of delivery-promise, order-sourcing and shipping-and-tracking, serves two in-organization callers and makes two synchronous calls to delivery-promise (plus the confirm added by G7 / E7). Hard rules: no live lookup into a sibling except the model's sync_calls; sibling data is an event-fed local read model; every consumer is idempotent on the CloudEvents id (inbox) and dispatches on the full type string; consumer groups are mandatory.

Decision​

Relationships (context map)​

CounterpartDirectionRelationshipWhat
shopper / storefrontin (REST)OHSPOST /checkout, GET /orders/{id}, GET /orders/{id}/tracking, POST /orders/{id}/cancellations, POST /shoppers
shipping-and-trackingin (REST)Customer/SupplierGET /orders/{id}/ship-to (restricted; the only PII exit - a pickup order answers {destinationKind, pickupPointId} with no address at all, ADR 0016)
delivery-promiseout (REST)Customer/SupplierQuoteDeliveryOffers POST /delivery-quotes, MakePromise POST /promises, ConfirmPromise POST /promises/{promiseId}/confirmations (E7), CancelPromise POST /promises/{promiseId}/cancellations (compensation of a failed checkout, A14)
delivery-promisein (events)Customer/SupplierPromiseAtRisk, PromiseRevised, PromiseKept, PromiseBroken, PromiseUnkeepable (E9)
order-sourcingin (events)ConformistFulfillmentLocked, FulfillmentShipped, FulfillmentUnsourceable, FulfillmentCancelled, FulfillmentCancelRefused (E11)
shipping-and-trackingin (events)ConformistLabelIssued, LabelVoided (E16), PackageScanned, PackageDelivered, PackageExceptionRaised, PackageLost, PackageReturned (A19), PackageEtaWindowAssigned (ADR 0014), PackageReadyForCollection and PackageCollected (ADR 0016)
order-sourcing, delivery-promiseout (events)published languageCustomerOrderPlaced, CustomerOrderCancelled

Consumed events and what each does​

Topics: retailnetwork.delivery-promise.events, retailnetwork.order-sourcing.events, retailnetwork.shipping-and-tracking.events; one consumer group each (DELIVERY_PROMISE_CONSUMER_GROUP, ORDER_SOURCING_CONSUMER_GROUP, SHIPPING_CONSUMER_GROUP, all mandatory; PackageLost and PackageReturned share the shipping-and-tracking consumer and its group). The inbox table processed_events (event id primary key) is written in the same transaction as the effect.

Full typeEffect
com.retailnetwork.commerce.order-sourcing.assignment.FulfillmentLockedlinks assignmentId to (orderId, groupNo) and its tracking rows; MarkInFulfillment
...assignment.FulfillmentShippedMarkGroupShipped (tracking numbers, shippedAt); reconciles deliveries that arrived first (A21)
...assignment.FulfillmentUnsourceabletracking: unsourceableReason of the group
...assignment.FulfillmentCancelledConfirmGroupCancelled
...assignment.FulfillmentCancelRefusedRefuseGroupCancellation
com.retailnetwork.commerce.delivery-promise.promise.PromiseAtRisktracking: atRiskReason of the group with that promiseId
...promise.PromiseRevisedUpdateGroupPromise (window, shipBy, node, revisionNo)
...promise.PromiseKept / PromiseBrokentracking: promiseVerdict, lateByMinutes
...promise.PromiseUnkeepablepolicy CancelOnUnfulfillable (A5): CancelUnkeepableGroup, publishes CustomerOrderCancelled
com.retailnetwork.logistics.shipping-and-tracking.label.LabelIssuedtracking package row (carrier, state LABELLED), linked by assignmentId
...label.LabelVoidedtracking package state VOIDED
...journey.PackageScannedtracking package: last scan node/time, journey state (older scans never overwrite newer ones)
...journey.PackageDeliveredtracking package delivered; MarkGroupDelivered
...journey.PackageExceptionRaisedtracking package exceptionReason
...journey.PackageLosttracking package outcome LOST; MarkGroupLost for the group that announced the package (terminal LOST); an early loss is replayed when FulfillmentShipped arrives (A19)
...journey.PackageReturnedtracking package outcome RETURNED; MarkGroupReturned (terminal RETURNED), same replay rule (A19)
...journey.PackageEtaWindowAssignedtracking package day-of window (etaStart, etaEnd, etaAssignedAt; the latest assignedAt wins); read model only, no order or promise field changes (ADR 0014)
...journey.PackageReadyForCollectiontracking package of a pickup journey: state READY_FOR_COLLECTION, pickupPointId, readyForCollectionAt, holdUntil; read model only, no aggregate change - the promise is judged at delivery-promise and the order keeps moving on the shipment events (ADR 0016)
...journey.PackageCollectedtracking package collected: state COLLECTED, collectedAt, optional proofCode and the point; read model only, like the deposit (ADR 0016)

Decoding is tolerant: only the fields listed in apis/asyncapi.yaml are read, unknown fields and unknown types are ignored. A message that is not a valid CloudEvents event, or whose data cannot be decoded, goes to the dead-letter topic <consumed topic>.dlq (for example retailnetwork.order-sourcing.events.dlq) with the failure in headers (A7 lists the errors that are recorded and skipped instead).

Local read models​

  • OrderTrackingView (GET /orders/{id}/tracking): the order's groups (status, promise window, lock/ship times) joined with
    • promise_signals (promiseId, orderId, atRiskReason, verdict, lateByMinutes, unsourceable reason), and
    • tracking_packages (trackingNumber primary key, assignmentId, orderId, groupNo, carrier, state, lastScanNodeId, lastScanAt, deliveredAt, exceptionReason, outcome, outcomeAt, etaStart, etaEnd, etaAssignedAt). Rows may be created before the order link is known (a scan can precede FulfillmentLocked); FulfillmentLocked fills orderId and groupNo of every row with the assignment id, FulfillmentShipped those of its tracking numbers.
  • assignment_links (assignmentId -> orderId, groupNo, promiseId): written by FulfillmentLocked; resolves the group of PackageDelivered.

Persistence of the cross-cutting parts​

  • Outbox: outbox rows (encoded CloudEvent, topic, key) are appended in the same transaction as the order save; the always-on relay drains them with an attempt cap.
  • Idempotency: idempotency_keys (route, key, request hash, response, 24 h TTL).
  • Inbox: processed_events.

Consequences​

  • No synchronous call is needed to render an order or its tracking.
  • The producers' own AsyncAPI files are the authority; this repo vendors only the tolerant subset in apis/asyncapi.yaml and must be re-checked when a producer publishes (the conformance check of the orchestrator).
  • Open points for the producers (see ADR 0002 model gaps): delivery-promise adds destinationPostalPrefix to its Promise response and fixes the confirm body.