Skip to main content

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​

  • specversion 1.0; id a UUID persisted with the outbox row (stable across relay retries; consumers dedupe on it); source /warehouse/slotting-optimization; subject the plan id (plan-<uuid>); time the occurred-at instant in UTC; datacontenttype application/json; dataschema urn: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.
  • data is 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).

typestreamsraised whendata
com.warehouse.wms.slotting-optimization.slotplan.SlotPlanGeneratedevents + analyticsa 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.SlotPlanApprovedevents + analyticsa 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.SlotPlanRejectedevents + analyticsa Draft plan is rejected{plan_id, site_id, rejected_at, reason?}

Payload rules:

  • SlotPlanApproved carries 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. kind is Assign, Relocate or Vacate. For Vacate, to_slot is omitted and from_slot is set; for Assign, from_slot is omitted.
  • supersedes_plan_id is the site's previously Approved plan, omitted when there was none. No event announces the supersession itself.
  • SlotPlanGenerated carries sizes only, not the assignments: a Draft is a proposal and is not part of the published picture.
  • reason on SlotPlanRejected is omitted when no reason was given.
  • A breaking payload change is a new .v2 type and dataschema, never a mutation of v1.

Consumed (ADR 0003)​

typetopicconsumer group env
com.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChangedwarehouse.order-management.eventsDEMAND_CONSUMER_GROUP
com.warehouse.wms.product-master.product.ProductClassifiedwarehouse.product-master.eventsPRODUCT_CONSUMER_GROUP
com.warehouse.wms.product-master.product.ProductDimensionsDeclaredwarehouse.product-master.eventsPRODUCT_CONSUMER_GROUP
com.warehouse.wms.product-master.product.ProductMeasuredwarehouse.product-master.eventsPRODUCT_CONSUMER_GROUP
com.warehouse.wms.facility-layout.zone.ZoneRegisteredwarehouse.facility.eventsLAYOUT_CONSUMER_GROUP
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredwarehouse.facility.eventsLAYOUT_CONSUMER_GROUP
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedwarehouse.facility.eventsLAYOUT_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 SlotPlanApproved makes the message grow with the forward-slot count (a few kilobytes per thousand slots); that is accepted so consumers stay lookup-free.