0043. Promote DiscrepancyDetected, ItemUnlocated and ItemStowed to the integration topic
Status
Accepted (2026-10-21). Amends ADR 0011 (these three types were analytics-only) and the type catalogue of ADR 0024 (rows appended there). No payload, subject or Kafka-key change; no consumer of this repo changes.
Context
Until now only the Inventory Flow & Accuracy data product (ADR 0011) saw the three facts that record inventory exceptions:
bin.DiscrepancyDetected— a cycle count found the bin's system quantity did not match physical reality ({bin_id, counted, system}),stock.ItemUnlocated— a short count flagged stock units Unlocated ({sku, bin_id, stock_unit_id, quantity}),stock.ItemStowed— the chaotic-stow fact that makes quantity usable ({sku, bin_id, quantity}).
They were published to warehouse.inventory.analytics only. That was
deliberate while no other bounded context needed them: the fleet rule is
that a cross-context contract lives on the producer's integration topic
(warehouse.inventory.events), and an analytics-only fact is not a contract.
Two new contexts change that:
- exception-management (WES) opens and triages exception cases from
DiscrepancyDetectedandItemUnlocated— a cycle-count shortfall is the canonical source of a warehouse exception case; - returns-processing (WMS) closes its restock loop on
ItemStowed— a dispositioned RESTOCK line is staged, and the loop ends when the returned quantity is actually stowed.
Keeping them analytics-only would force a sibling context to subscribe to another context's internal data product, coupling public contracts to a private stream.
Decision
Promote all three types to warehouse.inventory.events — also, not
instead: each continues to reach warehouse.inventory.analytics
unchanged. On the integration topic they carry exactly what the
analytics publisher emits:
- the same full
typestring (com.warehouse.wms.inventory-storage.bin.DiscrepancyDetected,com.warehouse.wms.inventory-storage.stock.ItemUnlocated,com.warehouse.wms.inventory-storage.stock.ItemStowed), - the same
subjectand the same Kafka key, including the one deliberate split:ItemUnlocatedis keyed by SKU (all facts about one SKU's units stay on one partition) while itssubjectis the lost stock unit id, - byte-identical
data— the payload mapping exists twice (once per encoder) andTestPromoted_DataIsByteIdenticalAcrossTopicspins the rawdatabytes,type, key and subject equal across the two encoders.
The only difference is the dataschema stream:
urn:warehouse:inventory-storage:events:<Event>:v1 on the integration
topic vs ...:analytics:<Event>:v1 (ADR 0024's per-topic stream rule).
The events leave through the transactional outbox like every other
integration fact (ADR 0017); no new publisher path exists.
Consequences
- These three types are now a breaking-change surface. Before the
promotion a payload change was an internal analytics matter; now it
breaks exception-management and returns-processing. Any change to a
field, the subject or the Kafka key is a new
.v2type +dataschemaversion, never a mutation (ADR 0024). - The payload mapping is deliberately duplicated in
promoted.gorather than shared withanalytics_publisher.go; the byte-identity test makes drift a build failure rather than a silent contract fork. - Consumers must keep ignoring unknown
typevalues (fleet rule): a consumer that only wants the exception facts simply does not act on the other eleven types on the topic. apis/asyncapi.yamlreferences the same message components from both channels; thedataschemapattern widens to(events|analytics)per promoted type. The CloudEvents catalogue in ADR 0024 gains one appended row per type.- Volume: the integration topic now carries every stow. Consumers that
were already on the topic (wes-work-planning, pick-face-replenishment)
see new
typevalues they must skip — they already do, by dispatching only on their known full type strings.
Addendum 2026-11-13: current state
ItemStowedis published to both topics as decided here (isIntegrationEventininternal/adapters/outbound/kafka/publisher.go). exception-management consumesDiscrepancyDetectedandItemUnlocated(internal/adapters/inbound/kafka/inventory_exceptions_consumer.goin that repo).- returns-processing does not consume
ItemStowed: its Kafka consumers (internal/adapters/inbound/kafka/) areallocated_lines,manifestsandproduct_classes, and its ADR 0003 ("Restock loop closure") defers the consumer. No sibling context consumesItemStowedtoday; the "closes its restock loop" sentence above is the intent, not the current state.