30. CloudEvents 1.0 as the mandatory event envelope
Status
Accepted — fleet-wide standard, implemented in this service by the change
that introduces this record. Supersedes the envelope parts of
ADR 0005 (the flat
event_id/event_type/occurred_at/source/data integration envelope)
and ADR 0006 (the analytics
"Envelope v1" with schema_version), and the CloudEvents/flat dual-read
code this service carried for fulfillment-execution's ADR-0027 and
wes-work-planning's ADR-0021 migrations.
Context
The fleet had three envelope shapes in flight at once: a flat integration
envelope, an analytics variant of it with schema_version, and (in some
producers) CloudEvents 1.0 behind dual-write/dual-read toggles.
order-management decoded both flat and CloudEvents messages on its
fulfillment and path-capacity consumers via a specversion probe, still
dispatched on short event names (stripping the reverse-DNS type back to
TaskCPTMissed), and published only the flat shapes itself. Every consumer
had to carry two decoders and every producer had to decide which shape to
emit. The fleet decided to cut over in one coordinated release instead of
running a long coexistence period.
Decision
-
Scope. EVERY message this service writes to or reads from Kafka —
warehouse.order-management.events,warehouse.order-management.analytics,warehouse.fulfillment.events,warehouse.process-path-management.events,warehouse.work-planning.events— is a CloudEvents 1.0 event. No flat envelope, no dual-write, no dual-read, no envelope toggle. -
Encoding. Kafka protocol binding, structured content mode: the message value is the JSON event format; every produced message carries the header
content-type: application/cloudevents+json; charset=UTF-8. The Kafka key stays the aggregate id (OrderId) with thekafkago.Hashbalancer (ADR 0027). W3C trace context stays intraceparent/tracestateheaders. -
Library. Events are built, validated and (un)marshalled with
github.com/cloudevents/sdk-go/v2/event(v2.16.2) only — never a hand-rolled struct. Transport stayssegmentio/kafka-go. The single home for the helpers isinternal/adapters/kafka/cloudevents(New,Decode,ContentTypeHeader,Type,DataSchema). -
Attributes (all required).
attribute value in this service specversion1.0idUUID v4 minted once at encode time; the outbox persists the encoded bytes, so a relay redelivery carries the same idsource/warehouse/order-managementtypecom.warehouse.wes.order-management.order.<EventName>subjectthe order id (same as the Kafka key) timethe domain event's occurred-at, UTC datacontenttypeapplication/jsondataschemaurn:warehouse:order-management:<events|analytics>:<EventName>:v1datais byte-for-byte the payload this service published before the migration. The analyticsschema_versionfield is removed (replaced bydataschema). The sametypenames an occurrence on both topics;dataschemadistinguishes the integration and analytics payloads. -
Versioning. Additive payload changes keep
typeanddataschema. A breaking payload change requires a newdataschemaversion AND a new.v2-suffixedtype, published as a new event. -
Consumers. Decode with
cloudevents.Decode(SDK unmarshal +specversion == 1.0+Validate()), dispatch on the FULLtypestring, ignore unknown types, readtime/subjectfrom attributes and the payload viaDataAs, dedupe onid. A message that is not a valid CloudEvent (bad JSON, the retired flat envelope) is a deterministic poison message: the repromise consumer sends it unmodified to its existing<topic>.dlqand commits; the local-cache consumers and the analytics projector log it at WARN with topic/partition/offset and move on. Never crash, never block a partition, never parse a legacy shape.
Types this service publishes
com.warehouse.wes.order-management.order.OrderAllocated (events + analytics) com.warehouse.wes.order-management.order.OrderPartiallyAllocated (events + analytics) com.warehouse.wes.order-management.order.OrderRepromised (events + analytics) com.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChanged (events only, ADR 0035) com.warehouse.wes.order-management.order.OrderReceived (analytics) com.warehouse.wes.order-management.order.OrderAllocationPartiallyFailed (analytics) com.warehouse.wes.order-management.order.OrderReleased (analytics) com.warehouse.wes.order-management.order.OrderCancelled (analytics) com.warehouse.wes.order-management.order.OrderLineAllocated (analytics) com.warehouse.wes.order-management.order.OrderLineBackordered (analytics) com.warehouse.wes.order-management.order.OrderLineReleased (analytics) com.warehouse.wes.order-management.order.OrderReleaseUnconfirmed (analytics, ADR 0043)
OrderAllocated and OrderPartiallyAllocated are consumed by
wes-work-planning with these exact strings.
SiteSkuDemandChanged (ADR 0035) is the one type raised outside the
order entity: its subject/Kafka key is the line-scoped
<order_id>/line/<line_no>, not the bare order id, and it is emitted
only for an order that carries a fulfillment site (ADR 0044) or while
DEMAND_PROJECTION_SITE_ID is configured.
Types this service consumes (exact, fleet cross-service table)
com.warehouse.wes.fulfillment-execution.task.TaskCPTMissed (repromise consumer) com.warehouse.wes.fulfillment-execution.package.PackageManifested (repromise consumer) com.warehouse.wes.process-path-management.processpath.ProcessPathCreated (kafkacatalog) com.warehouse.wes.process-path-management.processpath.ProcessPathUpdated (kafkacatalog) com.warehouse.wes.process-path-management.processpath.ProcessPathDeactivated (kafkacatalog) com.warehouse.wes.process-path-management.cptschedule.CPTScheduleChanged (kafkacptschedule) com.warehouse.wes.work-planning.workpool.PathCapacityChanged (kafkapathcapacity) com.warehouse.wms.product-master.product.ProductClassified (product-classification copy, ADR 0036) com.warehouse.wes.order-management.order.* (the ten above, analytics projector)
Consequences
- One decoder and one encoder per service; the
specversionprobe,bareEventTypestripping, flat envelope structs andAnalyticsEnvelopeare deleted. - The
outbox_events.event_typecolumn now stores the full CloudEventstype(it is only used for inspection/logging).OrderRepromised'sreasonpayload field keeps its existing short values (TaskCPTMissed/PackageManifested) —datais unchanged. - Breaking wire change; no coexistence. This service must deploy
together with the rest of the fleet cutover. Before deploying, drain the
outbox (rows were pre-encoded in the flat shape), delete and recreate the
warehouse.*.events/warehouse.*.analyticstopics and re-seed the process-path catalogue so no flat message remains for a FirstOffset replay — see warehouse-infradocs/cloudevents-cutover.md. A flat message that slips through is skipped/dead-lettered, never applied. - Tests: a golden exact-JSON test per published type (all attributes, the type string and the content-type header), a legacy-flat-rejected test per consumer, and the testcontainers Kafka integration tests run on the CloudEvents wire format.
Alternatives considered
- Keep dual-read for a bake period. Rejected fleet-wide: it doubles every consumer's decode surface and the cutover is coordinated anyway.
- Binary content mode (attributes as
ce_*headers). Rejected: structured mode keeps the whole event in the value, which the outbox already persists verbatim, and keeps trace headers the only headers. - Hand-rolled CloudEvent structs. Rejected: the SDK's
Validate()is the conformance check every consumer relies on.