24. CloudEvents 1.0 as the mandatory event envelope
Status
Accepted. Fleet-wide standard (2026-09-30), applied to this service in
the same change that introduces this record. Type catalogue extended by
ADR 0039 (StockRelocated) and by
ADR 0040 (BinStockLevelChanged). Supersedes
ADR 0004's flat envelope and the
"Envelope v1" (schema_version) of
ADR 0011. Every other decision in those
records (Kafka as transport, a separate analytics topic, the projector) still
stands.
Context
Until now this service emitted a flat envelope
(event_id / event_type / occurred_at / source / data, with a bare
event_type such as StockReserved) on warehouse.inventory.events, and a
near-identical Envelope v1 with an extra schema_version on
warehouse.inventory.analytics. apis/asyncapi.yaml meanwhile already
documented the CloudEvents attributes as a target, with a caveat that the
wire format was behind. The facility cache consumer matched facility-layout
events on the trailing name of a fully-qualified type and tolerated several
shapes.
Two descriptions of the same contract, a suffix match, and a per-service
schema_version field are exactly the drift a shared standard exists to
prevent. The fleet decided to make CloudEvents 1.0 mandatory everywhere at
once, with no dual-write or dual-read period: all services cut over together
and the topics are recreated (see warehouse-infra
docs/cloudevents-cutover.md).
Decision
Every Kafka message this service writes or reads is a CloudEvents 1.0 event in structured content mode. No flat envelope, no Envelope v1, no dual-write, no dual-read, no envelope toggle.
Encoding
- Kafka protocol binding, structured mode: the message value is the JSON
event format; every produced message carries the header
content-type: application/cloudevents+json; charset=UTF-8. - Kafka key is unchanged (the aggregate id each publisher already used —
ADR 0021) and the writer still uses
kafkago.Hash{}. - W3C trace context stays in Kafka headers (
traceparent/tracestate), not in CloudEvents extensions. - Events are built, validated and (un)marshalled with
github.com/cloudevents/sdk-go/v2/event(v2.16.2). Transport stayssegmentio/kafka-go; the SDK's protocol/client packages are not used. - One helper package owns the envelope:
internal/adapters/kafka/cloudevents(New,Decode,ContentTypeHeader,Type,DataSchema). Nothing else hand-builds one.
Context attributes (all required)
| attribute | value |
|---|---|
specversion | 1.0 |
id | UUID v4, minted once in Encode and persisted inside the outbox row's value, so every relay redelivery carries the same id. (source, id) is the consumer idempotency key. |
source | /warehouse/inventory-storage (both topics) |
type | com.warehouse.wms.inventory-storage.<entity>.<EventName> |
subject | the aggregate instance id (reservation id, SKU, stock unit id or bin id — see below) |
time | the domain event's occurred-at, UTC, RFC 3339 |
datacontenttype | application/json |
dataschema | urn:warehouse:inventory-storage:<events|analytics>:<EventName>:v<N> |
data is byte-for-byte the payload each topic carried before; only the
wrapper changed. The analytics schema_version field is removed —
dataschema replaces it.
The same type names an occurrence on both topics; dataschema names the
payload shape (...:events:... vs ...:analytics:...). A breaking payload
change requires a new dataschema version and a new .v2 type,
published as a new event, never a mutation of the old one.
This service's types
Entity segments are the ones already catalogued in apis/asyncapi.yaml:
stock (StockUnit), reservation, bin, container (ADR 0045, 0046).
| topic | type | subject |
|---|---|---|
warehouse.inventory.events | com.warehouse.wms.inventory-storage.reservation.StockReserved | reservation id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.reservation.ReservationRevoked | reservation id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.reservation.TransferStockAllocated | reservation id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.reservation.TransferStockAllocationRejected | transfer line id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.reservation.TransferStockAllocationReleased (ADR 0051) | transfer line id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.stock.TransferReceiptStaged | transfer line id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.stock.TransferStockStowed | transfer line id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.stock.BinStockLevelChanged (ADR 0040) | <bin>:<sku> |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.container.ContainerRegistered (ADR 0046) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.container.ContainerStowed (ADR 0046) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.container.CaseBroken (ADR 0046) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.container.ContainerEmptied (ADR 0046) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.tote.ToteRegistered (ADR 0054) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.tote.ToteFilled (ADR 0054) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.tote.ToteStowed (ADR 0054) | LPN |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.stock.StockHeld (ADR 0052) | held unit id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.stock.StockReleased (ADR 0052) | held unit id |
warehouse.inventory.events | com.warehouse.wms.inventory-storage.stock.StockDispositioned (ADR 0052) | held unit id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.stock.StockReceived | SKU |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.stock.ItemStowed | SKU |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.stock.ItemUnlocated | stock unit id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.reservation.StockReserved | reservation id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.reservation.StockPicked | reservation id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.reservation.ReservationExpired | reservation id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.reservation.ReservationRevoked | reservation id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.bin.CycleCountCompleted | bin id |
warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.bin.DiscrepancyDetected | bin id |
warehouse.inventory.events + warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.bin.DiscrepancyDetected | bin id — integration + analytics (promoted 2026-10-21, for exception-management; ADR 0043) |
warehouse.inventory.events + warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.stock.ItemUnlocated | stock unit id — integration + analytics (promoted 2026-10-21, for exception-management; ADR 0043) |
warehouse.inventory.events + warehouse.inventory.analytics | com.warehouse.wms.inventory-storage.stock.ItemStowed | SKU — integration + analytics (promoted 2026-10-21, for returns-processing; ADR 0043) |
| (none: in-process only, never published) | com.warehouse.wms.inventory-storage.stock.LocationRecorded | n/a |
ProductClassified (internal/domain/product), entity segment product
(com.warehouse.wms.inventory-storage.product.ProductClassified), retired at
product-master ADR 0003 stage E (2026-10-17), was
published on both topics by ADR 0031. Since
ADR 0034 it is emitted only by
the one-shot republish-product-classifications backfill, on
warehouse.inventory.events (subject = SKU), and is retired at
product-master ADR 0003 stage E.
Consumers
-
Decode with
cloudevents.Decode(SDK unmarshal +specversioncheck +Validate()). Anything else — the retired flat envelope, bad JSON, a missing required attribute — is a deterministic poison message:- facility cache (
facilitycache.Consumer): dead-lettered to<topic>.dlq(its existing ADR 0020 DLQ path) andobserve()still runs, so the FirstOffset replay readiness gate is never stalled by an invalid message; - analytics projector (
AnalyticsConsumer, no DLQ): WARN log with topic/partition/offset and commit past it.
Never crash, never block the partition, never fall back to a flat parse.
- facility cache (
-
Dispatch on the full
type, byte-identical to the publisher. Unknown types are ignored. This service consumes:com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredcom.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclared(ADR 0047)com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedcom.warehouse.wms.facility-layout.zone.ZoneRegisteredcom.warehouse.wms.product-master.product.ProductClassified(topicwarehouse.product-master.events, source/warehouse/product-master; the local classification copy, ADR 0034 — every other product-master type on that topic is ignored)com.warehouse.wms.inbound-receiving.receipt.ReceiptLineReceived(topicwarehouse.inbound-receiving.events, source/warehouse/inbound-receiving;condition=Goodlines are booked as staged stock through ReceiveStock, ADR 0037 — every other inbound-receiving type on that topic is ignored)- its own nine analytics types above (projector).
-
Dedupe on the CloudEvents
id(the projector'sanalytics_processed_events.event_idcolumn is now populated fromid). The facility cache's updates are idempotent upserts/deletes keyed by aggregate, so a redelivery re-applies harmlessly. -
time/subjectcome from attributes; the payload fromDataAs.
Fleet cross-service contract
These strings must be byte-identical on both sides:
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered -> inventory-storage
com.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclared -> inventory-storage
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissioned -> inventory-storage
com.warehouse.wms.facility-layout.zone.ZoneRegistered -> inventory-storage
com.warehouse.wms.product-master.product.ProductClassified -> inventory-storage (ADR 0034)
com.warehouse.wms.inbound-receiving.receipt.ReceiptLineReceived -> inventory-storage (ADR 0037)
com.warehouse.wms.inventory-storage.reservation.StockReserved -> wes-work-planning
com.warehouse.wms.inventory-storage.reservation.ReservationRevoked -> wes-work-planning
com.warehouse.wes.order-management.order.OrderAllocated -> wes-work-planning
com.warehouse.wes.order-management.order.OrderPartiallyAllocated -> wes-work-planning
com.warehouse.wes.order-management.order.OrderRepromised -> (published contract)
com.warehouse.wes.process-path-management.processpath.ProcessPathCreated -> fulfillment-execution, wes-work-planning, workforce-management, order-management
com.warehouse.wes.process-path-management.processpath.ProcessPathUpdated -> same four
com.warehouse.wes.process-path-management.processpath.ProcessPathDeactivated-> same four
com.warehouse.wes.process-path-management.cptschedule.CPTScheduleChanged -> order-management
com.warehouse.wes.labor-performance.performance.TaskPerformanceRecorded -> workforce-management (and labor-performance itself)
com.warehouse.wes.workforce-management.shiftplan.ShiftPlanCommitted -> wes-work-planning
com.warehouse.wes.fulfillment-execution.task.TaskCompleted -> wes-work-planning, labor-performance
com.warehouse.wes.fulfillment-execution.task.TaskCPTMissed -> order-management
com.warehouse.wes.fulfillment-execution.package.PackageManifested -> order-management
com.warehouse.wes.work-planning.workunit.WorkReleased -> fulfillment-execution
com.warehouse.wes.work-planning.workpool.PathCapacityChanged -> order-management
Consequences
Positive
- One envelope, one parser, one documented contract;
apis/asyncapi.yamlnow describes the actual wire format with no caveat. - Full-type dispatch removes the suffix-match ambiguity in the facility cache.
dataschemaversions the payload per stream without a bespoke field.
Negative / costs
- Breaking wire change, no coexistence. This service must deploy
together with the fleet cutover. Before deploying, drain the outbox (rows
written before this change are pre-encoded in the flat shape), then delete
and recreate
warehouse.inventory.events,warehouse.inventory.analyticsand every otherwarehouse.*topic so no flat message remains for a FirstOffset replay. A flat message that does survive is dead-lettered or skipped, never applied. - Messages are slightly larger (two more attributes plus the header).
Verification
internal/adapters/kafka/cloudeventsunit tests (builder, decode, legacy rejection).internal/adapters/outbound/kafka/golden_test.go: exact-JSON golden per published type on both topics, plus thecontent-typeheader.- Legacy-flat-message rejection tests for every consumer (facility cache unit + testcontainers integration, analytics projector unit).
publisher_integration_test.goreads the CloudEvents back from a real (testcontainers) broker.
Addendum 2026-11-13: current state
The catalogue row for ItemStowed on both topics names returns-processing as the reason for the
promotion (ADR 0043). returns-processing has no ItemStowed consumer today (its Kafka
consumers are allocated_lines, manifests and product_classes); the row records the contract, not a live consumer.