ADR 0003: consumed contracts, local facts, relationships and recompute
Status
Accepted (2026-10-23).
Context
node-performance is a measuring context: it consumes thirteen events from five
producers, publishes two, and serves two reads. It makes no synchronous call to a
sibling (sync_calls: []); the only in-organization caller is vendor-connectivity
reading GET /scorecards/{nodeId}.
Decision
-
Consumed contracts. The inbound contract is restated, tolerantly, in
apis/asyncapi.yaml(receiveoperations), built from each producer'sapis/asyncapi.yamlonorigin/feature/service(delivery-promise, node-topology, offer-availability, shipping-and-tracking, vendor-connectivity), re-checked at the end of the build. Only the fields below are required; unknown fields and unknown types are ignored; dispatch is on the FULL CloudEventstype.Producer topic Full type Fields relied on Effect retailnetwork.vendor-connectivity.eventscom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorOnboardedvendorIdnone (ADR 0002, A4) com.retailnetwork.partner.vendor-connectivity.purchaseorder.PurchaseOrderIssuedpoNumber,nodeId,requiredShipBy,ackBy, envelopetimeupserts PurchaseOrderFacts...purchaseorder.PurchaseOrderAcceptedpoNumber,nodeId,acceptedAtobservation ACK_ACCEPTED...purchaseorder.PurchaseOrderRejectedpoNumber,nodeId,rejectedAtobservation ACK_REJECTED...purchaseorder.PurchaseOrderExpiredpoNumber,nodeId,ackByobservation ACK_EXPIRED...purchaseorder.VendorShipmentConfirmedpoNumber,nodeId,requiredShipByupserts PurchaseOrderFacts...submission.SubmissionProcessednone none (A4) retailnetwork.shipping-and-tracking.eventscom.retailnetwork.logistics.shipping-and-tracking.journey.PackageHandedOverpoNumber,nodeId,handedOverAtobservation HANDOVERretailnetwork.delivery-promise.eventscom.retailnetwork.commerce.delivery-promise.promise.PromiseKeptnodeId,deliveredAtobservation PROMISE_KEPT...promise.PromiseBrokennodeId,causeobservation PROMISE_BROKENfor node-attributable causes (A8)retailnetwork.offer-availability.eventscom.retailnetwork.commerce.offer-availability.inventoryfeed.InventoryFeedAppliednodeId,appliedAtobservation FEED_APPLIEDretailnetwork.node-topology.eventscom.retailnetwork.logistics.node-topology.node.NodeRegisterednodeIdnone (A4) ...node.NodeOperationalProfileDeclarednodeIdnone (A4) -
Relationships. Conformist toward every producer (the model): the local copies take the producers' shapes and never negotiate them. Customer/Supplier toward vendor-connectivity for
GET /scorecards/{nodeId}: the supplier is this service, the contract isapis/openapi.yaml. delivery-promise and order-sourcing are downstream ofNodeScorecardUpdatedand call nothing here. -
Local facts. One read model,
PurchaseOrderFacts(tablepurchase_order_facts), keyed bypoNumber:nodeId,issuedAt,ackBy,requiredShipBy. It is written byPurchaseOrderIssuedandVendorShipmentConfirmed(a field is only ever filled, never erased) and read by the acknowledgement and handover use cases to judge lateness. It is a view of what the producers said, never an aggregate. An acceptance, rejection or handover whose facts are missing is a transient failure (ErrPurchaseOrderUnknown): the producers' events race on different topics, so the message is retried, then dead-lettered. -
Inbox. Every consumer is idempotent on the CloudEvents
id: the use case inserts the id intoprocessed_eventsin the same Postgres transaction that applies the change (aggregate saves and facts upsert). A duplicate id makes the whole message a no-op that is acknowledged. Event types with no effect (A4) write only the inbox row. -
Consumer groups. One stable group per consumed topic, each from a mandatory environment variable, read at boot before the listener binds:
VENDOR_CONNECTIVITY_CONSUMER_GROUP,SHIPPING_AND_TRACKING_CONSUMER_GROUP,DELIVERY_PROMISE_CONSUMER_GROUP,OFFER_AVAILABILITY_CONSUMER_GROUP,NODE_TOPOLOGY_CONSUMER_GROUP(ADR 0009 adds a sixth,SELLER_INBOUND_CONSUMER_GROUP). A message is committed only after its handler returned nil; a transient failure is retried with capped backoff and dead-lettered to<topic>.dlqafter the attempt cap; a payload that can never be applied is dead-lettered at once. A message that is not a CloudEvents 1.0 event, or whose type has no handler, is skipped. -
Outbox publishing.
Recomputewrites the scorecard and oneoutbox_eventsrow per raised event, the CloudEvents envelope already encoded and itsidminted once, in ONE Postgres transaction. An always-on relay drains the rows to Kafka with a capped attempt count (at-least-once, in id order, key = scorecardId). -
Recompute. A scheduler in
cmd/apiruns theRecomputeuse case everyRECOMPUTE_INTERVALover the scorecards that are due (ADR 0002, A15); it is a worker with the same shutdown discipline as the consumers and the relay. -
Readiness.
/readyzanswers 503dependency-unavailablewhile draining, or when the Postgres ping or a Kafka metadata request (an empty, non-nil topic list) fails;/healthzis liveness only.
Consequences
- The service boots only with
DATABASE_URL,KAFKA_BROKERSand the five consumer group variables; a missing one is a boot error naming it. - Adding a consumed event is an
apis/asyncapi.yamlchange plus a handler ininternal/adapters/inbound/kafka; no shared code with the producer.