Skip to main content

ADR 0004: CloudEvents envelope and type catalogue

Status​

Accepted (2026-10-23).

Context​

Every Kafka message in the retail network is a CloudEvents 1.0 event in structured mode (retail-network-docs model/model.yaml conventions.cloudevents; the repo rule .claude/rules/fleet/cloudevents.md). This ADR is the catalogue of every type delivery-promise publishes. TestEventCatalogueMatchesContract checks it against apis/asyncapi.yaml. The types delivery-promise only consumes are listed in ADR 0003; the ones added after the first release are also named at the end of this ADR.

Decision​

Envelope​

  • specversion 1.0; id a UUID persisted with the outbox row (stable across relay retries; consumers dedupe on it); source /retailnetwork/delivery-promise; subject the aggregate root id (promiseId, bookId, offerId or policyVersion); time the instant the change was committed, in UTC; datacontenttype application/json; dataschema urn:retailnetwork:delivery-promise:<stream>:<EventName>:v1 where <stream> is events or analytics.
  • Kafka value = the JSON event format; header content-type: application/cloudevents+json; charset=UTF-8; Kafka key = the subject, so all events of one aggregate stay ordered on one partition.
  • data is camelCase; optional fields are omitted when unset (never null); arrays are always present; timestamps are RFC 3339 UTC.
  • Built and decoded only through internal/adapters/kafka/cloudevents.
  • <entity> is the raising aggregate, lowercase, no separators: promise, promisebook, deliveryoffer, promisepolicy; the one non-aggregate fact, DeliveryRequestAnswered (ADR 0032), uses deliveryrequest and its subject is a fresh requestId. Tier is commerce.

Published types​

Integration events (stream: events) go ONLY to retailnetwork.delivery-promise.events; analytics-only events (stream: analytics) go ONLY to retailnetwork.delivery-promise.analytics.

type: com.retailnetwork.commerce.delivery-promise.promise.PromiseMade stream: analytics
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseConfirmed stream: analytics
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseAtRisk stream: events
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseRevised stream: events
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseKept stream: events
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseBroken stream: events
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseReleased stream: analytics
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseCancelled stream: analytics
type: com.retailnetwork.commerce.delivery-promise.promise.PromiseUnkeepable stream: events
type: com.retailnetwork.commerce.delivery-promise.promisebook.PromiseBookExhausted stream: events
type: com.retailnetwork.commerce.delivery-promise.deliveryoffer.DeliveryOfferQuoted stream: analytics
type: com.retailnetwork.commerce.delivery-promise.promisepolicy.PromisePolicyPublished stream: analytics
type: com.retailnetwork.commerce.delivery-promise.deliveryrequest.DeliveryRequestAnswered stream: analytics
EventStreamSubject / keyRaised whenConsumers
PromiseMadeanalyticspromiseIdMakePromise is saved (PROVISIONAL, capacity held)analytics only
PromiseConfirmedanalyticspromiseIdConfirmPromise is saved (the synchronous confirm of E7, or the reconciling consumer)analytics only
PromiseAtRiskeventspromiseIdFlagPromiseAtRisk is savedcustomer-ordering
PromiseRevisedeventspromiseIdRevisePromise is savedcustomer-ordering, order-sourcing
PromiseKepteventspromiseIdJudgePromise: delivered on or before deliverByLatestnode-performance, customer-ordering
PromiseBrokeneventspromiseIdJudgePromise: late, lost or returnednode-performance, customer-ordering
PromiseReleasedanalyticspromiseIdReleaseExpiredHolds released a holdanalytics only
PromiseCancelledanalyticspromiseIdCancelPromise on CustomerOrderCancelledanalytics only
PromiseUnkeepableeventspromiseIdRevisePromise found no path at any tier (E9)customer-ordering
PromiseBookExhaustedeventsbookIda hold made provisional + confirmed = shareorder-sourcing
DeliveryOfferQuotedanalyticsofferIdQuoteDeliveryOffers persisted an offer (one event per offer)analytics only
PromisePolicyPublishedanalyticspolicyVersionPublishPromisePolicy is saved (G19)analytics only
DeliveryRequestAnsweredanalyticsrequestIda quote or an estimate was answered with 200, best effort and only while DELIVERY_REQUEST_FACTS_ENABLED is true (ADR 0032)analytics only

Payload rules:

  • The data field lists are exactly the model's publishes[].data lists. PromiseUnkeepable (E9), DeliveryOfferQuoted and PromisePolicyPublished are not in the model; their lists are defined in apis/asyncapi.yaml (ADR 0002, assumptions A19 and A20). pickupDepartureId is omitted on a NOMINAL PromiseMade (contracts-delta E8). deliveredAt is omitted on a PromiseBroken of cause LOST or RETURNED.
  • PromiseBroken.cause is LATE, LOST or RETURNED.
  • A breaking change is a new .v2 type; a consumer ignores unknown fields.
  • The analytics-only events carry no PII (there is none in this context) and are not read by any integration consumer.

Consumed types added after the first release​

These are NOT published by this service; they are listed so the full type string is in the catalogue (the dispatch table and apis/asyncapi.yaml receive operations must match it).

type: com.retailnetwork.partner.node-performance.scorecard.NodeTierEligibilityChanged stream: events
EventStreamSubject / keyRaised when (by the producer)Effect here
NodeTierEligibilityChangedevents<nodeId>:7dnode-performance flips a node's fast-tier eligibility (one event per tier, SAME_DAY and NEXT_DAY)NodeTierEligibility read model; ineligible nodes are dropped from SAME_DAY and NEXT_DAY candidates (ADR 0022)

Consequences​

  • TestEventCatalogueMatchesContract fails when apis/asyncapi.yaml declares a type this table lacks.
  • Adding a published event needs: a line above, a message and schema in apis/asyncapi.yaml, an encoder in internal/adapters/outbound/kafka, and a golden JSON test.