Async API — Narrative
This page is the prose walkthrough of inventory-storage's asynchronous
contract. The authoritative, machine-checked source is
apis/asyncapi.yaml (AsyncAPI 2.6.0), Spectral-linted in CI by the
api-lint job — everything below is drawn from it. For the full generated
reference (every message schema, in full), see
/api-reference/async/inventory-storage.
Topic
| Topic | warehouse.inventory.events |
| Protocol | Kafka |
| Client library | github.com/segmentio/kafka-go |
| Balancer | Hash on the Kafka key (the reservation id), AllowAutoTopicCreation: true — one reservation's events land on one partition, so they stay ordered per reservation (inventory-storage ADR-0021); there is no per-SKU ordering |
| Broker | KAFKA_BROKERS, default localhost:9092 (shared broker at ~/warehouse-systems/docker-compose.kafka.yml) |
| Selected by | EVENT_PUBLISHER=kafka (default is log, so tests and local runs never need a broker). With Postgres, events go through a transactional outbox (outbox_events, ADR-0017) drained by a relay in cmd/inventory |
| Direction | Publish on this topic. (Separately, this service consumes six sibling topics, every group set in warehouse-infra develop: facility-layout's ZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned and LocationSlotHandlingUnitDeclared from warehouse.facility.events into its location cache (LOCATION_LOOKUP_MODE=kafka, ADR-0013, ADR-0047 for the bin handling unit); product-master's ProductClassified, ProductPackLevelDeclared and ProductPackLevelRetired from warehouse.product-master.events under PRODUCT_MASTER_CONSUMER_GROUP (ADR-0034, ADR-0046's local packaging view); ReceiptLineReceived and the identity-only ReceiptCartonReceived from warehouse.inbound-receiving.events under INBOUND_RECEIPT_CONSUMER_GROUP (ADR-0037, ADR-0045, ADR-0046); returns-processing's ReturnLineStaged under RETURN_LINE_CONSUMER_GROUP (ADR-0044); network-inventory-planning's TransferAllocationRequested (TRANSFER_ALLOCATION_CONSUMER_MODE=kafka); and fulfillment-execution's TaskCompleted from warehouse.fulfillment.events when TASK_COMPLETED_CONSUMER_MODE=kafka: PICK confirms reservations, ADR-0035 and ADR-0036, RELOCATE moves stock, ADR-0039, and REPLENISH moves stock with reason REPLENISHMENT, ADR-0041, see below. See Domain Events.) |
| Consumers | wes-work-planning, projecting StockReserved and ReservationRevoked into its own UsableInventoryObserved read model, keyed by SKU; slotting-optimization, consuming StockRelocated into its plans' execution progress (RELOCATION_MODE=kafka, ADR-0039 and slotting ADR 0010; only reason SLOTTING executes a plan move); pick-face-replenishment, consuming BinStockLevelChanged (ADR-0040) and StockRelocated with reason REPLENISHMENT (ADR-0041); exception-management, consuming DiscrepancyDetected and ItemUnlocated (promoted onto this topic by ADR-0043); network-inventory-planning, reading the transfer replies and destination facts (its TRANSFER_REPLY_CONSUMER_GROUP); it is also the producer of the TransferAllocationRequested command this service consumes. ItemStowed and the four container facts have no consumer |
| Default content type | application/cloudevents+json |
There is a second, separate topic, warehouse.inventory.analytics, carrying
nine domain events for this service's own analytical read model
(the Inventory Flow & Accuracy report). That topic has exactly one
consumer — this service's own cmd/inventory-projector — and is not part of
the cross-context integration contract described on this page.
What events are on the topic
The synced apis/asyncapi.yaml declares fifteen types on the integration
topic:
StockReservedandReservationRevoked, the reservation contract thatwes-work-planningprojects (described below);- four transfer replies and destination facts (
TransferStockAllocated,TransferStockAllocationRejected,TransferReceiptStaged,TransferStockStowed) fornetwork-inventory-planning(ADR-0030, ADR-0033); StockRelocated(com.warehouse.wms.inventory-storage.stock.StockRelocated), raised byRelocateStockforPOST /relocationsand for a completedRELOCATEorREPLENISHtask (ADR-0039, ADR-0041), consumed byslotting-optimizationandpick-face-replenishment. Integration topic only: it has no analytics variant. Key andsubjectare the relocation id;BinStockLevelChanged(com.warehouse.wms.inventory-storage.stock.BinStockLevelChanged, ADR-0040), the absoluteon_handandreservedof one SKU in one bin after a ledger change, with a per-(bin, sku)versionand areason(STOW,PICK,RELOCATE,REPLENISHMENT,COUNT,RESERVE,REVOKE;UNLOCATEDis reserved). Key<bin>:<sku>, raised in the same transaction as the change through the outbox, consumed bypick-face-replenishment;DiscrepancyDetected,ItemUnlocatedandItemStowed, promoted from the analytics topic (ADR-0043);exception-managementconsumes the first two;- the container (LPN) facts
ContainerRegistered,ContainerStowed,CaseBrokenandContainerEmptied(ADR-0045 sealed cases and break-case, ADR-0046), with no consumer yet.
The legacy com.warehouse.wms.inventory-storage.product.ProductClassified is
gone: product-master owns classification (ADR-0034), and the type, its
backfill and the classification routes were removed at product-master's
migration stage E (this repository's PR #218; fleet edge K21, retired).
See Domain Events for the complete catalog and which topic each event reaches, if any.
The envelope: CloudEvents 1.0 (mandatory)
Every message is a CloudEvents 1.0 event in structured content mode, per
the fleet-wide, mandatory Event Standard. Kafka header
content-type: application/cloudevents+json; charset=UTF-8; context
attributes carry routing and identity; the business payload lives entirely
under data:
{
"specversion": "1.0",
"id": "1f7a4c30-9b2d-4e85-a6c1-7d3f0b5e8a94",
"source": "/warehouse/inventory-storage",
"type": "com.warehouse.wms.inventory-storage.reservation.StockReserved",
"subject": "res-1",
"time": "2026-08-21T22:00:00Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:inventory-storage:events:StockReserved:v1",
"data": { "sku": "SKU-1", "quantity": 5, "demand_ref": "order-42" }
}
| Attribute | Required | Value |
|---|---|---|
specversion | ✅ | Always "1.0" |
id | ✅ | UUID v4 minted once per domain event and persisted with the outbox row (stable across redelivery). (source, id) is the deduplication key. |
source | ✅ | Always /warehouse/inventory-storage |
type | ✅ | Reverse-DNS event type, pinned per message |
subject | ✅ | The aggregate instance the event is about — a reservation id, a stock unit id, or a bin id |
time | ✅ | RFC 3339 UTC, taken from the injected Clock port — the time it occurred in the domain, not at publish |
datacontenttype | ✅ | Always application/json |
dataschema | ✅ | urn:warehouse:inventory-storage:events:<EventName>:v1 (integration topic) or urn:warehouse:inventory-storage:analytics:<EventName>:v1 (analytics topic) |
There is no flat envelope and no envelope toggle; consumers reject (skip, never parse) any message that is not a valid CloudEvent.
The type convention
The platform-wide convention:
com.warehouse.<subdomain>.<bounded-context>.<entity>.<EventName>
All lowercase except the final PascalCase event name. For this context,
<subdomain> is wms (Warehouse Management System, a Core subdomain);
<bounded-context> is inventory-storage; <entity> is the aggregate that
raises the event — stock, reservation, or bin. Each concrete message
pins type to a single enum value, so consumers can discriminate safely and
a typo fails validation instead of producing a silently-unrouted message.
ReservationRevoked's enrichment, on the wire
The domain event ReservationRevoked carries only a reservationId — the
aggregate has no reason to repeat data the reservation already holds. But the
integration contract promises {sku, quantity, demand_ref}, because the
downstream projection is keyed by SKU and cannot afford a lookup. The Kafka
adapter bridges that gap by re-reading the reservation through
ReservationRepo at publish time, so the shape on the wire is identical to
StockReserved's:
{
"specversion": "1.0",
"id": "4b9e2f61-7c3a-4d08-85e2-1a6f9c0d3b72",
"source": "/warehouse/inventory-storage",
"type": "com.warehouse.wms.inventory-storage.reservation.ReservationRevoked",
"subject": "res-1",
"time": "2026-08-21T22:10:00Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:inventory-storage:events:ReservationRevoked:v1",
"data": { "sku": "SKU-1", "quantity": 5, "demand_ref": "order-42" }
}
The use case saves the reservation before publishing, so this lookup always
succeeds in practice; the ErrReservationNotFound guard exists but is not an
expected path.
Who consumes it
wes-work-planning is the consumer of the two reservation events. It projects both events
into UsableInventoryObserved, a read model keyed by SKU: StockReserved
decrements the observed usable count, ReservationRevoked increments it
back. Because the two events are exact inverses, the downstream projection
stays trivially simple — one decrement, one increment.
Relocation: TaskCompleted in, StockRelocated out
This is the stock-ledger end of the slot-plan chain (inventory-storage
ADR-0039, slotting-optimization ADR 0010): SlotPlanApproved →
wes-work-planning plans one RELOCATE work unit per move →
fulfillment-execution runs the task → this service moves the stock →
slotting-optimization records the progress.
In: TaskCompleted on warehouse.fulfillment.events. The same consumer
that confirms picks (fixed group TASK_COMPLETED_CONSUMER_GROUP, default
inventory-storage-confirm-pick, running only with
TASK_COMPLETED_CONSUMER_MODE=kafka; the chart default is off and the
reference deployment sets kafka) has a second branch. When task_type is
RELOCATE, the additive fields sku, from_bin, to_bin, quantity (the
operator-confirmed count) and relocation_ref (<plan_id>:<move_seq>) are
applied through RelocateStock, the use case behind POST /relocations, with
reason SLOTTING, the site taken from the source bin, and source_ref =
relocation_ref (the task id when the producer sent none). The CloudEvents
id is claimed in processed_events (consumer task-completed-relocate) in
the same transaction as the move, so a redelivery is a no-op. A completion
that can never apply (missing or invalid field, unknown bin, bins of different
sites, the same bin, too little usable stock, a full destination) is
dead-lettered at once to warehouse.fulfillment.events.dlq; a transient
failure retries 5 times and then dead-letters; a shutdown mid-move commits and
dead-letters nothing.
Out: StockRelocated. One event per relocation, from either door, on
warehouse.inventory.events through the outbox: relocation_id, site_code,
sku, from_bin, to_bin, quantity (at least 1), reason
(SLOTTING, CONSOLIDATION, MANUAL or, for a completed REPLENISH task, REPLENISHMENT), source_ref ("" when none) and
occurred_at. Because it is raised for every relocation, most
StockRelocated events (manual, consolidation) belong to no slot plan, and
slotting-optimization counts those as unmatched without storing them.
Replenishment: REPLENISH completions in, REPLENISHMENT relocations out
The ledger end of the pick-face replenishment chain (inventory-storage
ADR-0041, pick-face-replenishment → wes-work-planning → fulfillment-execution
→ this service → pick-face-replenishment). The TaskCompleted consumer that
confirms picks and applies RELOCATE moves has a third branch: a
task_type = REPLENISH completion carries the same additive sku, from_bin,
to_bin and quantity plus the REQUIRED request_ref
(internal/application/usecases/apply_replenish_task.go, wired in
cmd/inventory/confirmpick.go). It runs the same RelocateStock with reason
REPLENISHMENT, the site taken from the source bin and source_ref =
request_ref, with no task-id fallback, because pick-face-replenishment closes a
request by source_ref == request_id. The CloudEvents id is claimed in
processed_events (consumer task-completed-replenish) in the same transaction;
a completion without request_ref is dead-lettered at once to
warehouse.fulfillment.events.dlq. The move enqueues StockRelocated (reason
REPLENISHMENT) and two BinStockLevelChanged events, the source bin and then
the destination bin, like a RELOCATE. slotting-optimization ignores a
REPLENISHMENT relocation. Every hop of this chain is wired in
warehouse-infra develop (pick-face-replenishment registered,
REPLENISHMENT_MODE=kafka for wes-work-planning; fleet edges K43 and K44,
live); no request has been traced through all of them on a cluster.
Idempotency and consumer-group notes
- At-least-once delivery is every consumer's problem.
wes-work-planningdeduplicates with aprocessed_eventstable keyed by the CloudEventsid, so a redelivery does not double-decrement or double-increment its usable count. - Ordering is per reservation, not per SKU. The
Hashbalancer keys on the reservation id, so different reservations for the same SKU can land on different partitions. Acceptable for an increment/decrement projection, which tolerates reordering of independent events — but it is why the REST read remains authoritative. - Tolerate unknown
typevalues. The catalog grows as more of it is wired to the outbound adapter; a consumer that fails closed on an unrecognised type will break the first time that happens. - The authoritative answer is always the REST read. The event stream is
a convenience projection for keeping a cheap local view warm, not a
substitute for
GET /inventory/{sku}/usablewhen correctness matters. - A broker outage does not fail the request. With Postgres and
EVENT_PUBLISHER=kafka, the use case inserts the encoded events intooutbox_eventsin the same transaction as the aggregate write (ADR-0017), and the relay delivers them at-least-once later. The CloudEventsidis persisted with the outbox row, so a redelivery carries the sameid. Postgres and Kafka are the only runtime (ADR-0042), so every event goes through the outbox.
Building another consumer
- Read
apis/asyncapi.yaml, not this page — it is the linted contract. - Each message in the document says which topics it reaches in its own
description. Read product classification and pack levels from
product-master'swarehouse.product-master.events. - Deduplicate on the event id; do not assume ordering.
- Treat the event stream as a projection — call
GET /inventory/{sku}/usablefor the authoritative answer.
Full reference
The complete, generated AsyncAPI HTML — every message schema, in full, built
directly from apis/asyncapi.yaml — is at
/api-reference/async/inventory-storage.