ADR 0004: CloudEvents envelope and type catalogue
Status
Accepted (2026-10-08). The per-key ordering consequence is amended by ADR 0008 (outbox relay attempt cap).
Context
Every Kafka message in the fleet is a CloudEvents 1.0 event in structured mode
(fleet rule .claude/rules/fleet/cloudevents.md, warehouse-docs
docs/strategic-design/event-standard-cloudevents.md). This ADR is the
catalogue of every type slotting-optimization publishes or consumes;
TestEventCatalogueMatchesContract checks it against apis/asyncapi.yaml.
Decision
Envelope
specversion1.0;ida UUID persisted with the outbox row (stable across relay retries; consumers dedupe on it);source/warehouse/slotting-optimization;subjectthe plan id (plan-<uuid>);timethe occurred-at instant in UTC;datacontenttypeapplication/json;dataschemaurn:warehouse:slotting-optimization:events:<EventName>:v1.- Kafka value = the JSON event format; header
content-type: application/cloudevents+json; charset=UTF-8; Kafka key = the plan id, so all events of one plan stay ordered on one partition. datais snake_case; optional fields are omitted when unset; timestamps are RFC 3339 UTC.- Built and decoded only through
internal/adapters/kafka/cloudevents.
Published on warehouse.slotting-optimization.events (+ warehouse.slotting-optimization.analytics)
<entity> is the raising aggregate, lowercase, no separators: slotplan.
Every type below is published on BOTH streams (events + analytics) under one
id per occurrence; only the dataschema stream segment differs (ADR 0006).
| type | streams | raised when | data |
|---|---|---|---|
com.warehouse.wms.slotting-optimization.slotplan.SlotPlanGenerated | events + analytics | a Draft plan is generated | {plan_id, site_id, window_from, window_to, policy, assignment_count, move_count, unassigned_count} |
com.warehouse.wms.slotting-optimization.slotplan.SlotPlanApproved | events + analytics | a Draft plan is approved | {plan_id, site_id, approved_at, supersedes_plan_id?, assignments:[{sku, slot}], moves:[{sku, from_slot?, to_slot, kind}]} |
com.warehouse.wms.slotting-optimization.slotplan.SlotPlanRejected | events + analytics | a Draft plan is rejected | {plan_id, site_id, rejected_at, reason?} |
Payload rules:
SlotPlanApprovedcarries the full forward assignment map (every{sku, slot}of the plan) and the moves, so a consumer replaces its picture of the forward slots from this one message and needs no lookup.kindisAssign,RelocateorVacate. ForVacate,to_slotis omitted andfrom_slotis set; forAssign,from_slotis omitted.supersedes_plan_idis the site's previously Approved plan, omitted when there was none. No event announces the supersession itself.SlotPlanGeneratedcarries sizes only, not the assignments: a Draft is a proposal and is not part of the published picture.reasononSlotPlanRejectedis omitted when no reason was given.- A breaking payload change is a new
.v2type and dataschema, never a mutation of v1.
Consumed (ADR 0003)
| type | topic | consumer group env |
|---|---|---|
com.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChanged | warehouse.order-management.events | DEMAND_CONSUMER_GROUP |
com.warehouse.wms.product-master.product.ProductClassified | warehouse.product-master.events | PRODUCT_CONSUMER_GROUP |
com.warehouse.wms.product-master.product.ProductDimensionsDeclared | warehouse.product-master.events | PRODUCT_CONSUMER_GROUP |
com.warehouse.wms.product-master.product.ProductMeasured | warehouse.product-master.events | PRODUCT_CONSUMER_GROUP |
com.warehouse.wms.facility-layout.zone.ZoneRegistered | warehouse.facility.events | LAYOUT_CONSUMER_GROUP |
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered | warehouse.facility.events | LAYOUT_CONSUMER_GROUP |
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissioned | warehouse.facility.events | LAYOUT_CONSUMER_GROUP |
Every other type on those topics is ignored. A message that is not a valid CloudEvent is logged and skipped, never retried forever.
Analytics stream (ADR 0006)
Every published event above is ALSO written, in the same transaction and under
the same id, to warehouse.slotting-optimization.analytics (dead-letter
topic warehouse.slotting-optimization.analytics.dlq). The type, subject,
Kafka key and payload are identical to the integration message; only the
dataschema differs:
urn:warehouse:slotting-optimization:analytics:<EventName>:v1. Only this
service's cmd/slotting-projector consumes it (consumer group from env
ANALYTICS_CONSUMER_GROUP); it is not an integration contract, and other
contexts keep reading warehouse.slotting-optimization.events. The
projection and its slot-plan funnel report are specified in ADR 0006.
Consequences
- Consumers need nothing but this catalogue and
apis/asyncapi.yaml; there is no shared Go code. - The full assignment map in
SlotPlanApprovedmakes the message grow with the forward-slot count (a few kilobytes per thousand slots); that is accepted so consumers stay lookup-free.