Skip to main content

Domain events

This bounded context emits fifteen past-tense domain events. Together they are its Published Language — the vocabulary downstream Conformists key off.

Published to Kafka, specified in AsyncAPI

Every domain event is published to the warehouse.facility.events integration topic (ADR 0009) and, in the same call, to the separate warehouse.facility.analytics topic that feeds the analytical data product (ADR 0010). The integration topic, its CloudEvents 1.0 envelope (ADR 0024) and all fifteen messages are specified in apis/asyncapi.yaml (AsyncAPI 2.6.0).

Publishing always goes through the transactional outbox (outbox_events, ADR 0018): the use case writes the aggregate row and one outbox row per topic in one transaction, and the in-process relay drains them onto Kafka. There is no log-only mode (ADR 0039). The old events table was dropped by migration 0005_outbox. See Publishers and the Context map for who consumes what.

The type convention​

Identical to the other warehouse-systems services: reverse-DNS, lowercase except the final PascalCase event name, and the entity segment carries no hyphen even for multi-word aggregate names.

com.warehouse.<subdomain>.<bounded-context>.<entity>.<EventName>

This service's subdomain segment is wms. "Bin-accurate location" is classified WMS-tier in the e-commerce-fulfillment reference — the "Inventory & Slotting" Core subdomain references it as WMS's Open Host Service — and this service is the generalized, multi-consumer version of that same concern. The wms segment is shared with inventory-storage and product-master; every other fleet context uses wes.

com.warehouse.wms.facility-layout.site.SiteRegistered
com.warehouse.wms.facility-layout.site.SiteCapabilityChanged
com.warehouse.wms.facility-layout.site.SiteRoleChanged
com.warehouse.wms.facility-layout.zone.ZoneRegistered
com.warehouse.wms.facility-layout.aisle.AisleRegistered
com.warehouse.wms.facility-layout.locationtype.LocationTypeRegistered
com.warehouse.wms.facility-layout.placementrule.PlacementRuleDefined
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissioned
com.warehouse.wms.facility-layout.locationslot.FacilityLayoutImported
com.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclared
com.warehouse.wms.facility-layout.locationslot.LocationGeometryUpdated
com.warehouse.wms.facility-layout.aisle.AisleGeometryUpdated
com.warehouse.wms.facility-layout.structure.FixedStructureRegistered
com.warehouse.wms.facility-layout.crossaisle.CrossAisleRegistered

Entity segments in use: site, zone, aisle, locationtype, placementrule, locationslot, structure, crossaisle.

The DomainEvent interface​

// DomainEvent is a past-tense fact published by an aggregate. Adapters
// (outbound/events) serialize and publish these; the domain never depends
// on the publishing mechanism. EventType is this context's Published
// Language: downstream Conformists key off it.
type DomainEvent interface {
EventName() string
EventType() string
OccurredAt() time.Time
}

Every event embeds the same base, serialized as:

{
"eventName": "LocationSlotRegistered",
"eventType": "com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered",
"occurredAt": "2026-08-22T09:00:00Z"
}

OccurredAt comes from the injected Clock port, never from time.Now() inside the domain — which is what makes event timestamps deterministic in tests.

The fifteen events​

SiteRegistered​

A physical facility was added to the warehouse map.

FieldType
siteCodestring
siteNamestring
siteRolestring — the site's role in the fulfilment network, UNSPECIFIED when none was stated (additive, ADR 0037)
glnstring — the site's GS1 Global Location Number (13 digits, mod-10 check digit); omitted when none was recorded (additive, ADR 0045)

SiteRoleChanged​

An operator changed a site's role in the fulfilment network (ADR 0037), raised by PUT /sites/{siteCode}/role (use case ChangeSiteRole) once per real change. It never implies a transfer-capability change. The one-time backfill of migration 0009 publishes none.

FieldType
siteCodestring
siteRolestring — the new role
previousSiteRolestring — the replaced role (UNSPECIFIED the first time)

SiteCapabilityChanged​

A site's transfer capability changed (ADR 0035). A full last-write-wins snapshot raised by PUT /sites/{siteCode}/transfer-capability (use case ChangeSiteTransferCapability) once per real change, and re-emitted by the periodic freshness heartbeat (ADR 0041, use case PublishSiteCapabilityHeartbeats) with the current values, a new CloudEvents id, a fresh time (the consumers' as_of) and the revision advanced by one. Its fields are snake_case, unlike every other payload here: recasing them would be a breaking .v2 for network-inventory-planning, so ADR 0035 keeps them.

FieldType
site_codestring
transfer_origin_enabledboolean — the site may donate stock
transfer_destination_enabledboolean — the site may receive stock
capability_revisioninteger — 1 on the first change, +1 per later event of the same site, change or heartbeat (ADR 0041); keep the highest

ZoneRegistered​

A behavioral zone was added inside a Site's area.

FieldType
zoneIdstring (WH1-STOR-AMB)
siteCodestring
areaCodestring
zoneCodestring
temperatureClassAmbient | Chilled | Frozen
hazmatboolean
glnstring — the zone's GS1 Global Location Number; omitted when none was recorded (additive, ADR 0045)

AisleRegistered​

A physical corridor was added inside a Zone.

FieldType
aisleIdstring (WH1-STOR-AMB-A07)
zoneIdstring
aisleCodestring
sequenceHintinteger — walk-order position
directionOneWay | TwoWay

This is the event a travel-path consumer cares about most: sequenceHint and direction are the two structural inputs to walk-order reasoning.

LocationTypeRegistered​

A reusable slot shape/kind was defined.

FieldType
locationTypestring (PalletRack)
roleLocationRole — Storage (default), Dock, Yard, WorkCenter, Drop, Staging, QC, Consolidation, Shipping
maxWeightKgnumber — omitted when zero
maxVolumeM3number — omitted when zero

Capacity is optional for the roles that do not hold stock at rest (Dock, Yard, WorkCenter, QC, Shipping), so the two capacity fields may be absent (ADR 0016).

PlacementRuleDefined​

A rule constraining which LocationTypes are legal in which Zones was declared.

FieldType
ruleIdstring
locationTypestring
effectAllow | Deny
predicatestring — the human-readable predicate, e.g. temperatureClass=Frozen

LocationSlotRegistered​

A coded leaf slot now exists on the warehouse map. This is the event inventory-storage consumes to learn that a new Bin location is legal to stow into.

FieldType
locationCodestring (WH1-STOR-AMB-A07-03-02-B)
aisleIdstring
zoneIdstring
locationTypestring
roleLocationRole, inherited from the LocationType
dockFlowInbound | Outbound | Both — only on a Dock slot
activitiesarray of Pack | Sort | QC | VAS | Deconsolidate | Receive | Kit — only on a WorkCenter slot
maxWeightKgnumber — omitted when zero
maxVolumeM3number — omitted when zero
glnstring — the slot's GS1 Global Location Number; omitted when none was recorded (additive, ADR 0045)
spotKindPARKING | HOLDING | REEFER_PLUG | HAZMAT | STAGING_LANE — only on a Yard slot, omitted when none was recorded (additive, ADR 0045)

aisleId and zoneId are denormalised into the payload deliberately: a consumer should not have to know how to parse this context's code format to route on zone. That is what makes it a Published Language rather than a leaked internal representation.

LocationSlotDecommissioned​

A coded slot was permanently retired. The signal for a downstream context to stop offering that location for new work.

FieldType
locationCodestring

FacilityLayoutImported​

A bulk layout import completed. Emitted once per import call; the individual LocationSlotRegistered events still fire per-slot within the same import.

FieldType
rowsSubmittedinteger
slotsImportedinteger
rowsRejectedinteger

The summary event exists so that a consumer can distinguish "the building was loaded" from a burst of unrelated single registrations, without having to infer it from event volume.

LocationSlotHandlingUnitDeclared​

A slot's handling unit was set or changed (ADR 0040). LocationSlotRegistered also carries handlingUnit, omitted when none was recorded.

FieldType
locationCodestring — same identifier as in LocationSlotRegistered
handlingUnitstring — EACH, CASE or PALLET
declaredAtstring — RFC 3339 instant, equals occurredAt

LocationGeometryUpdated​

A slot's physical position and size were set (ADR 0017).

FieldType
locationCodestring
xM, yM, zMnumber — position in metres
widthM, depthM, heightMnumber — dimensions in metres
pickSequenceinteger — optional

AisleGeometryUpdated​

An aisle's travel centreline was set.

FieldType
aisleIdstring
startXM, startYM, startZMnumber
endXM, endYM, endZMnumber
lengthMnumber

FixedStructureRegistered​

A non-slot physical obstacle was added to a site.

FieldType
structureIdstring
siteCodestring
kindWall | Column | Office | Conveyor | Other
xM, yM, zM, widthM, depthM, heightMnumber — footprint in metres
labelstring

CrossAisleRegistered​

A walkable connection between two aisles of the same zone was declared.

FieldType
zoneIdstring
fromAislestring
toAislestring
atBaystring

Catalogue at a glance​

Every event is published to both topics: warehouse.facility.events (integration, dataschema urn:warehouse:facility-layout:events:<EventName>:v1) and warehouse.facility.analytics (analytics, dataschema urn:warehouse:facility-layout:analytics:<EventName>:v1), under the same CloudEvents id. The Kafka key is the partition key; the CloudEvents subject names the aggregate instance. Every event is keyed by its aggregate's identity (so all events about one aggregate share a partition and stay ordered); the only exception is FacilityLayoutImported, a batch outcome with no aggregate, which is keyed by its CloudEvents id (ADR 0032). Decided 2026-10-06: kept — no consumer needs import ordering, and keying by site would need an additive siteCode (a contract change) for no benefit (ADR 0034).

CloudEvents typeKafka key (partition)subjectProducer use case(s)Known consumers
com.warehouse.wms.facility-layout.site.SiteRegisteredsiteCodesiteCodeRegisterSite, ImportFacilityLayoutown projector
com.warehouse.wms.facility-layout.site.SiteCapabilityChangedsite_codesite_codeChangeSiteTransferCapabilitynetwork-inventory-planning (site_capability read model); own projector ignores it
com.warehouse.wms.facility-layout.site.SiteRoleChangedsiteCodesiteCodeChangeSiteRolenone; own projector ignores it
com.warehouse.wms.facility-layout.zone.ZoneRegisteredzoneIdzoneIdRegisterZone, ImportFacilityLayoutinventory-storage, slotting-optimization, pick-face-replenishment, task-interleaving, dock-scheduling, yard-management, outbound-shipping, own projector
com.warehouse.wms.facility-layout.aisle.AisleRegisteredaisleIdaisleIdRegisterAisle, ImportFacilityLayoutown projector
com.warehouse.wms.facility-layout.locationtype.LocationTypeRegisteredlocationTypelocationTypeRegisterLocationTypeown projector
com.warehouse.wms.facility-layout.placementrule.PlacementRuleDefinedruleIdruleIdDefinePlacementRuleown projector
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredlocationCodelocationCodeRegisterLocationSlot, ImportFacilityLayoutinventory-storage, warehouse-planning, inbound-receiving, slotting-optimization, pick-face-replenishment, task-interleaving, dock-scheduling, yard-management, outbound-shipping, own projector
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedlocationCodelocationCodeDecommissionLocationSlotinventory-storage, warehouse-planning, inbound-receiving, slotting-optimization, pick-face-replenishment, task-interleaving, dock-scheduling, yard-management, own projector
com.warehouse.wms.facility-layout.locationslot.FacilityLayoutImportedevent id (batch outcome, no aggregate)layout-importImportFacilityLayoutown projector
com.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclaredlocationCodelocationCodeDeclareLocationHandlingUnitinventory-storage
com.warehouse.wms.facility-layout.locationslot.LocationGeometryUpdatedlocationCodelocationCodeSetLocationGeometry, ImportFacilityLayouttask-interleaving
com.warehouse.wms.facility-layout.aisle.AisleGeometryUpdatedaisleIdaisleIdSetAisleGeometrynone
com.warehouse.wms.facility-layout.structure.FixedStructureRegisteredstructureIdstructureIdRegisterFixedStructurenone
com.warehouse.wms.facility-layout.crossaisle.CrossAisleRegisteredzoneId/fromAisle-toAisle@atBayzoneId/fromAisle-toAisle@atBayRegisterCrossAislenone

Source: internal/domain/shared/events.go, internal/adapters/outbound/kafka/publisher.go (aggregateKey, partitionKey, SubjectOf), internal/adapters/inbound/kafka/analytics_consumer.go.

Which use case emits what​

Use caseEvents emitted
RegisterSiteSiteRegistered
ChangeSiteTransferCapabilitySiteCapabilityChanged (only when the snapshot changed or was never published)
PublishSiteCapabilityHeartbeats (timer, not a route)SiteCapabilityChanged heartbeat per active declared site every SITE_CAPABILITY_HEARTBEAT_INTERVAL (ADR 0041)
ChangeSiteRoleSiteRoleChanged (only when the role changed)
RegisterZoneZoneRegistered
RegisterAisleAisleRegistered
RegisterLocationTypeLocationTypeRegistered
DefinePlacementRulePlacementRuleDefined
RegisterLocationSlotLocationSlotRegistered
DecommissionLocationSlotLocationSlotDecommissioned
ImportFacilityLayoutper row: SiteRegistered / ZoneRegistered / AisleRegistered for each parent it creates on first sight, LocationSlotRegistered for each successful slot, LocationGeometryUpdated when the row carries geometry; then exactly one FacilityLayoutImported for the whole call
SetLocationGeometryLocationGeometryUpdated
DeclareLocationHandlingUnitLocationSlotHandlingUnitDeclared
SetAisleGeometryAisleGeometryUpdated
RegisterFixedStructureFixedStructureRegistered
RegisterCrossAisleCrossAisleRegistered
GetSiteLayout, GetZoneGrid, GetZoneTravelGraph, EstimateTravelDistance, ListLocationsByRole and the other readsnone — read models never write and never publish

Publishers​

Only one publisher is wired by the composition root (cmd/facility/main.go, buildAdapters): outbound/postgres OutboxPublisher — one outbox_events row per topic, in the use case's transaction — drained by the outbox relay. DATABASE_URL and KAFKA_BROKERS are mandatory (ADR 0039); EVENT_PUBLISHER accepts only kafka.

AdapterUse
outbound/kafka — PublisherEncodes each event as a CloudEvents 1.0 event (structured mode, source=/warehouse/facility-layout, type = the event type, subject = aggregate id, dataschema=urn:warehouse:facility-layout:events:<EventName>:v1, data = the event's JSON wire DTO (cloudevents.WireData; domain events carry no struct tags); ADR-0024) for warehouse.facility.events. Writer: kafkago.Hash balancer (ADR 0021), RequireAll acks with a 10 ms batch timeout (ADR 0031); the W3C trace context of the publishing request is injected into the message headers.
outbound/kafka — AnalyticsPublisherThe same occurrence (same type and id) with dataschema=urn:warehouse:facility-layout:analytics:<EventName>:v1, for warehouse.facility.analytics.
outbound/kafka — FanOutTest double / library only: mints one id and sends the event through both publishers above. Not wired by any binary (ADR 0039).
outbound/postgres — OutboxPublisher + OutboxRelayThe only runtime path: enqueues both encodings into outbox_events inside the use case's UnitOfWork; the relay (OUTBOX_RELAY_INTERVAL, default 1s, batches of 100, FOR UPDATE SKIP LOCKED) sends them through RelaySink (ADR-0018). A row that fails OUTBOX_MAX_ATTEMPTS sends (default 20) is excluded and later rows with the same key overtake it (ADR 0036). Published rows are deleted after OUTBOX_RETENTION by the housekeeping sweeper (ADR 0026).
outbound/events — log publisherTest double (and a library for local experiments): writes each event to a log. Not wired by any binary (ADR 0039).
outbound/events — buffered publisherTests. Collects events in memory for assertion.

The EventPublisher port is one method — Publish(ctx context.Context, event shared.DomainEvent) error — which is why the Kafka adapters were a purely additive change.

Who consumes them​

ConsumerTopicGroupEvents used
inventory-storage (internal/adapters/outbound/facilitycache, with LOCATION_LOOKUP_MODE=kafka)warehouse.facility.eventsprocess-unique group, replays from the first offsetZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned, LocationSlotHandlingUnitDeclared — the rest are ignored (ADR 0013)
warehouse-planning (internal/adapters/inbound/kafka/storage_capacity_consumer.go, started when KAFKA_BROKERS is set)warehouse.facility.eventsSTORAGE_CAPACITY_CONSUMER_GROUP (default warehouse-planning-storage-capacity)LocationSlotRegistered (Storage and WorkCenter roles), LocationSlotDecommissioned — folded into a storage-position / station tally
network-inventory-planning (internal/adapters/inbound/kafka/consumers.go, SiteCapabilityConsumer)warehouse.facility.eventsenv-configured (SITE_CAPABILITY_CONSUMER_GROUP)SiteCapabilityChanged — upserted into its site_capability read model, last-write-wins on capability_revision
inbound-receiving (internal/adapters/inbound/kafka/dock_door_consumer.go)warehouse.facility.eventsDOCK_DOOR_CONSUMER_GROUP (required; inbound-receiving-dock-doors)LocationSlotRegistered (only role=Dock with dockFlow Inbound or Both), LocationSlotDecommissioned — kept in its dock_doors table
slotting-optimization, pick-face-replenishment (internal/adapters/inbound/kafka/layout_consumer.go)warehouse.facility.eventsslotting-optimization-layout, pick-face-replenishment-layoutZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned — local layout copies
task-interleaving (internal/adapters/inbound/kafka/layout_consumer.go)warehouse.facility.eventstask-interleaving-layoutZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned, LocationGeometryUpdated — local layout copy with positions
dock-scheduling (internal/adapters/inbound/kafka/facility_consumer.go)warehouse.facility.eventsFACILITY_CONSUMER_GROUP (required)ZoneRegistered, LocationSlotRegistered (only an explicit role=Dock slot becomes a bookable door), LocationSlotDecommissioned — zone-to-site join and dock-door view
yard-management (internal/adapters/inbound/kafka/facility_consumer.go)warehouse.facility.eventsFACILITY_CONSUMER_GROUP (required)ZoneRegistered, LocationSlotRegistered (only role=Yard spots and role=Dock doors are kept), LocationSlotDecommissioned — local zone and location copies
outbound-shipping (internal/adapters/inbound/kafka/cpt_layout_consumers.go)warehouse.facility.eventsLAYOUT_CONSUMER_GROUP (required)ZoneRegistered, LocationSlotRegistered (reads zoneId and role); it does not handle LocationSlotDecommissioned
this repository's cmd/facility-projectorwarehouse.facility.analyticsfacility-analytics (DLQ warehouse.facility.analytics.dlq)The original eight events (SiteRegistered … FacilityLayoutImported); the geometry events and SiteCapabilityChanged are ignored

No other service consumes either topic today: ten contexts read warehouse.facility.events (the rows above) and only this repository's facility-projector reads warehouse.facility.analytics. AisleGeometryUpdated, FixedStructureRegistered and CrossAisleRegistered are Published Language with no consumer yet (LocationGeometryUpdated is applied by task-interleaving only).