Integration Guide
Everything a downstream team needs to consume this service, and everything an operator needs to run it against the shared broker.
Every edge at a glance
The relationship patterns, code paths on both sides and live/wired status are on the context map; this table is the operational view: how each edge behaves when the other side fails, as implemented here.
Upstream (this service consumes or calls)
| Upstream | Protocol and contract | Switch here | When it fails |
|---|---|---|---|
| facility-layout | Kafka warehouse.facility.events (ZoneRegistered, LocationSlotRegistered, LocationSlotHandlingUnitDeclared, LocationSlotDecommissioned) → in-process location cache | LOCATION_LOOKUP_MODE=kafka | Startup blocks up to 60 s for the replay and fails if it does not finish; malformed facts go to warehouse.facility.events.dlq; an empty cache answers Known=false (stow allowed, fail-open). |
| facility-layout | REST GET /locations/{locationCode}/classification | LOCATION_LOOKUP_MODE=http + FACILITY_LAYOUT_BASE_URL | 3 attempts per call inside a circuit breaker; an open breaker falls back to permissive (fail-open); a plain error blocks only hazmat / temperature-sensitive SKUs (409 location-classification-unavailable). |
| product-master | Kafka warehouse.product-master.events: ProductClassified → product_classifications; ProductPackLevelDeclared / ProductPackLevelRetired → pack_levels (the local packaging view, ADR 0046) | PRODUCT_MASTER_CONSUMER_GROUP (mandatory) | Transient errors retry the same message without limit; poison is logged and skipped. While the consumer is behind, stows use the last local copy (or none). |
| slotting-optimization | Kafka warehouse.slotting-optimization.events, SlotPlanApproved → forward_pick_face_plans / forward_pick_faces (the forward-slot map ReserveStock draws from first, ADR 0050) | SLOT_PLAN_CONSUMER_GROUP (optional, default inventory-storage-slot-plan) | Same retry rule; a plan older than the held one is a no-op; no synchronous call to slotting-optimization at reservation time. Until the first plan is consumed no SKU has a forward face and the draw order falls back to smaller usable first, bin id, stock unit id. |
| network-inventory-planning | Kafka warehouse.network-inventory-planning.events, TransferAllocationRequested and TransferAllocationReleaseRequested (commands, ADR 0030, ADR 0051) | TRANSFER_ALLOCATION_CONSUMER_GROUP (mandatory) | Same retry rule; replies (TransferStockAllocated / ...Rejected / ...Released) are only sent once the command is handled. |
| inbound-receiving | Kafka warehouse.inbound-receiving.events, ReceiptLineReceived → ReceiveStock; ReceiptCartonReceived → Containers (ADR 0045, ADR 0046) | INBOUND_RECEIPT_CONSUMER_GROUP (mandatory) | Same retry rule; dedupe through processed_events. |
| returns-processing | Kafka warehouse.returns-processing.events, ReturnLineStaged → BookReturnLine → ReceiveStock (ADR 0044) | RETURN_LINE_CONSUMER_GROUP (mandatory) | Same retry rule; dedupe through processed_events. |
| fulfillment-execution | Kafka warehouse.fulfillment.events, TaskCompleted (PICK, order_ref, optional line_no → confirm picks; REPLENISH with request_ref → replenishment relocation, ADR 0041) | TASK_COMPLETED_CONSUMER_GROUP (mandatory) | 5 attempts, then warehouse.fulfillment.events.dlq; poison straight to the DLQ. A consumer that dies ends the process non-zero (ADR 0042). |
Downstream (others consume or call this service)
| Downstream | Protocol and contract | Failure behaviour on this side |
|---|---|---|
| wes-work-planning | Kafka warehouse.inventory.events: StockReserved, ReservationRevoked | Outbox: a broker outage delays events (relay retries the oldest row) but never loses or reorders them per key. |
| network-inventory-planning | Kafka warehouse.inventory.events: TransferStockAllocated, TransferStockAllocationRejected, TransferReceiptStaged, TransferStockStowed | Same outbox guarantee. |
| slotting-optimization | Kafka warehouse.inventory.events: StockRelocated (ADR 0039) | Same outbox guarantee. |
| pick-face-replenishment | Kafka warehouse.inventory.events: BinStockLevelChanged (ADR 0040), StockRelocated | Same outbox guarantee. |
| exception-management | Kafka warehouse.inventory.events: bin.DiscrepancyDetected, stock.ItemUnlocated (promoted ADR 0043) | Same outbox guarantee. |
| returns-processing | none yet: stock.ItemStowed is on Kafka warehouse.inventory.events for it (promoted ADR 0043), but returns-processing has no consumer for it | Same outbox guarantee. |
| order-management | REST POST /reservations (Idempotency-Key), DELETE /reservations/{id} | Synchronous: 409 insufficient-usable / concurrent-modification, 409 idempotency-key-reused (told apart from a business 409 by its problem type). A retried POST with the same key and body replays the stored success with Idempotency-Replayed: true; 409 insufficient-usable and concurrent-modification are not stored (ADR 0053), so a retry under the same key executes again. |
| network-fulfillment | REST GET /inventory/{sku}/usable | Read-only; no side effects. |
| warehouse-ops-agent | REST GET /reservations?demandRef= (answers {items, nextCursor}; loop on nextCursor); reports REST GET /reports/flow-accuracy, /reports/flow-accuracy/freshness; MCP check_availability, get_bin_occupancy (MCP tools) | Read-only. MCP sessions are per process; reports reflect the projector's lag. |
| warehouse-console | the inventory micro-frontend (web/) calls this REST API through Kong; CORS allows CORS_ALLOWED_ORIGINS | Standard RFC 7807 problems. |
| inventory-projector (this repo) | Kafka warehouse.inventory.analytics | Analytics only; invalid CloudEvents are skipped, no DLQ. |
Absent on purpose: no edge to workforce-management (Separate Ways), and no outbound REST or MCP call from this service to any sibling except the optional facility-layout lookup. Every route, topic and group is also on the Runbook.
What this service publishes
| Topic | warehouse.inventory.events |
| Events | StockReserved, ReservationRevoked, the transfer replies and facts (ADR 0030, ADR 0033), StockRelocated (ADR 0039), BinStockLevelChanged (ADR 0040) and the promoted exception facts bin.DiscrepancyDetected, stock.ItemUnlocated, stock.ItemStowed (byte-identical copies of the analytics feed, ADR 0043); the legacy ProductClassified was removed at stage E (2026-10-17) |
| Client library | github.com/segmentio/kafka-go |
| Balancer | Hash (message key = reservation id, ADR 0021), AllowAutoTopicCreation: true |
| Consumers today | wes-work-planning (StockReserved, ReservationRevoked); network-inventory-planning (the transfer replies); slotting-optimization (StockRelocated); pick-face-replenishment (BinStockLevelChanged, StockRelocated); exception-management (DiscrepancyDetected, ItemUnlocated); nobody consumes ItemStowed yet (returns-processing has no consumer for it) |
What this service consumes
Operator and sibling commands against this service's own aggregates arrive as
explicit HTTP commands against the REST API, which runs
this service's own invariants before anything is written. The exceptions are
event-driven: transfer allocation commands (ADR 0030, see the README), pick
confirmation from TaskCompleted (below), and product classification, which
this service no longer authors (below).
One Kafka topic, read into a local read model (ADR 0013). StowStock
needs the target bin's zone attributes when the SKU being stowed carries the
Hazmat or TemperatureSensitive handling tag, to enforce placement rules
(hazmat-rated zone, matching temperature class — see
ADR 0009 for the
fail-open/fail-closed asymmetry). With LOCATION_LOOKUP_MODE=kafka those
attributes come from internal/adapters/outbound/facilitycache, which
replays facility-layout's warehouse.facility.events from the earliest
offset into memory on every start, under a unique per-process consumer group,
and blocks startup until the replay is complete (up to 60s). See
ADR 0013.
Messages are CloudEvents 1.0; the consumer dispatches on these exact type
strings (ADR-0024):
com.warehouse.wms.facility-layout.zone.ZoneRegisteredcom.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredcom.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclared(the bin handling unit, ADR 0047)com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissioned
Any other type is ignored; a message that is not a valid CloudEvent (e.g. the
retired flat envelope) is dead-lettered to warehouse.facility.events.dlq
and the replay — and the readiness gate — moves past it.
| Env var | Default | Purpose |
|---|---|---|
LOCATION_LOOKUP_MODE | (none, required) | kafka: Kafka-fed local cache (what the warehouse-infra cluster runs). http: synchronous GET /locations/{locationCode}/classification on facility-layout per stow — the rollback for kafka. Unset and permissive are boot errors since ADR 0042: a lookup that answers Known=false for every location validates nothing (the 2026-10-06 "kept permissive" decision of ADR 0013/0020 no longer applies). |
FACILITY_LAYOUT_BASE_URL | (unset) | Base URL for the http mode client, e.g. http://facility-layout:80; required in that mode. |
KAFKA_BROKERS | (none, required) | Required by every mode and every binary except cmd/mcp; the process exits at boot if it is missing. |
A second Kafka topic, picks confirmed from an event (ADR 0035, per line ADR 0036). The
physical decrement of reserved stock is not an HTTP command in production:
this service always consumes
com.warehouse.wes.fulfillment-execution.task.TaskCompleted from
warehouse.fulfillment.events under the stable group
TASK_COMPLETED_CONSUMER_GROUP (mandatory; the chart default is
inventory-storage-confirm-pick). For
a PICK task (one per order line) with the additive optional order_ref and line_no
it confirms exactly the ACTIVE reservation of (order_ref, line_no) through the
existing ConfirmPick use case, in one transaction with the CloudEvents-id claim
(ADR 0036); without a line_no, or for reservations that have
none, it falls back to counting the order's picks (order_pick_progress) and
confirming every ACTIVE reservation of the order when the last one completes
(ADR 0035); a redelivery changes
nothing, an expired reservation is skipped and counted
(inventory.pick_confirmations), and short picks are not modelled. Poison and
exhausted messages go to warehouse.fulfillment.events.dlq. See
ADR 0035.
| Env var | Default | Purpose |
|---|---|---|
TASK_COMPLETED_CONSUMER_GROUP | (none, required) | Stable consumer group id (chart default inventory-storage-confirm-pick). The consumer always runs; StockPicked leaves through the outbox. |
TASK_COMPLETED_CONSUMER_MODE | (unset) | Legacy guard: unset or kafka; off or anything else is a boot error. |
A third Kafka topic, product-master's classifications (ADR 0034).
product-master owns SKU product classification. This service always consumes
(under the mandatory PRODUCT_MASTER_CONSUMER_GROUP)
com.warehouse.wms.product-master.product.ProductClassified from
warehouse.product-master.events (key = SKU) and keeps a version-guarded
local copy in product_classifications: ApplyProductClassification claims
the CloudEvents id in processed_events and upserts the row in one
transaction, applying a message only when its version is greater than the
stored one. The same consumer also reads two pack-level types from that topic,
com.warehouse.wms.product-master.product.ProductPackLevelDeclared and
com.warehouse.wms.product-master.product.ProductPackLevelRetired, into the local
packaging view pack_levels (keyed by GTIN, version-guarded, retired levels stay
resolvable; ADR 0046): Declared inserts or updates a level, Retired end-dates it
(effective_to); each claims its CloudEvents id in processed_events in the same transaction. Every
other product-master type is committed past; a message that is not a valid
CloudEvent, or breaks the classification or pack-level invariants, is logged and committed past. The copy is what StowStock reads for its placement and
DOT segregation rules. PUT and GET /products/{sku}/classification were
removed at stage E (2026-10-17): the router registers neither, so both answer
404. See ADR 0034.
| Env var | Default | Purpose |
|---|---|---|
PRODUCT_MASTER_CONSUMER_GROUP | (none, required) | Stable consumer group id (chart default inventory-storage-product-master). The consumer always runs. |
A fourth Kafka topic, inbound-receiving's receipts (ADR 0037).
inbound-receiving owns ASNs, dock appointments and receipts. This service always
consumes (under the mandatory INBOUND_RECEIPT_CONSUMER_GROUP)
com.warehouse.wms.inbound-receiving.receipt.ReceiptLineReceived from
warehouse.inbound-receiving.events (key = ASN number). A condition=Good
line runs the existing ReceiveStock use case, in one transaction with the
CloudEvents-id claim in processed_events: the same StockReceived as
POST /stock-receipts, the quantity staged and not yet usable, stow still the RF
action. A Damaged line is booked as HELD stock in the same
transaction (ADR 0052): StockHeld, never usable and never reservable until a
disposition settles it (inventory.inbound_receipt_units{outcome=held}). Every other
inbound-receiving type is committed past; a message that is not a valid
CloudEvent, or carries an empty sku, a non-positive quantity or an unknown
condition, is logged and committed past. POST /stock-receipts is unchanged.
See ADR 0037.
| Env var | Default | Purpose |
|---|---|---|
INBOUND_RECEIPT_CONSUMER_GROUP | (none, required) | Stable consumer group id (chart value config.inboundReceiptConsumerGroup). The consumer always runs; StockReceived leaves through the outbox like every other event. |
A fifth Kafka topic, slotting-optimization's approved slot plans (ADR 0050).
slotting-optimization owns the slot plan. This service always consumes
com.warehouse.wms.slotting-optimization.slotplan.SlotPlanApproved from
warehouse.slotting-optimization.events (key = plan id; SlotPlanGenerated and SlotPlanRejected are committed
past) under SLOT_PLAN_CONSUMER_GROUP and keeps a local read model of each site's forward pick faces:
forward_pick_face_plans (the plan whose map is currently applied, with its approved_at) and
forward_pick_faces (that plan's full sku → bin_id assignment map). ApplySlotPlan claims the CloudEvents id
in processed_events and replaces the site's whole map in one transaction; a plan applies only if its approved_at
is later than the held plan's, or equal with a higher plan_id, so a late older plan is ignored. A malformed plan is
logged and committed past; a transient error retries the same message. ReserveStock reads only these local tables
and draws a SKU's forward pick face before its reserve bins. A new group starts at the earliest offset, so the map is
rebuilt from the approved plans' history. The consumer raises no domain event: nothing from it reaches the outbox.
| Env var | Default | Purpose |
|---|---|---|
SLOT_PLAN_CONSUMER_GROUP | inventory-storage-slot-plan | Stable consumer group id. The consumer always runs; the default lets a deployment that predates it boot unchanged. |
Configuration
| Env var | Default | Purpose |
|---|---|---|
KAFKA_BROKERS | (none, required) | Comma-separated broker list. No localhost:9092 default: the process exits at boot without it. |
EVENT_PUBLISHER | (unset) | Guard only: unset or kafka. Use cases write outbox_events rows inside their own transaction and a background relay in cmd/inventory drains them onto the topics (ADR 0017, OUTBOX_RELAY_INTERVAL, default 1s). There is no log publisher and no direct publishing (ADR 0042). |
There is one Kafka broker platform-wide: the in-cluster broker deployed by
warehouse-infra, whose external listener is published on the host at
localhost:9092. This repository's docker-compose.yml defines its own
disposable Kafka on localhost:19092 (KAFKA_HOST_PORT) so local runs never
collide with it.
# local Postgres and Kafka from the compose file; the other required variables
# (LOCATION_LOOKUP_MODE and the four *_CONSUMER_GROUP ids) are listed in the
# quickstart
docker compose up -d --wait postgres kafka
DATABASE_URL=postgres://inventory:inventory@localhost:5432/inventory?sslmode=disable \
KAFKA_BROKERS=localhost:19092 go run ./cmd/inventory
Message shapes
Every message is a CloudEvents 1.0 structured-mode event with the Kafka
header content-type: application/cloudevents+json; charset=UTF-8
(ADR-0024); the full
attribute table is on the Events page. What
lands on the topic:
{
"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" }
}
{
"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" }
}
Both carry the identical data shape, deliberately: the downstream projection
applies one to decrement and the other to increment the same counter.
The downstream projection
wes-work-planning turns these two events into UsableInventoryObserved,
a read model keyed by SKU (package internal/domain/inventoryview/,
table usable_inventory_view, exposed at GET /inventory-view/{sku}).
Two design notes that a consumer must respect:
- Keyed by SKU, not by path. Inventory reservations are SKU-scoped;
wes-work-planning's ownCLAUDE.mdcalls out explicitly that a path mapping must not be forced onto them because it does not exist. - Idempotency is mandatory. Kafka delivery is at-least-once.
wes-work-planninginserts each CloudEventsidinto aprocessed_eventstable before applying the effect, and skips on a primary-key violation — without that, one redelivery double-decrements observed usable.
Consuming this topic yourself
If you are building another consumer:
- Read the spec, not this page.
apis/asyncapi.yamlis the contract and is Spectral-linted in CI. - The integration topic carries
StockReserved,ReservationRevoked, the transfer replies and facts (ADR 0030, ADR 0033),StockRelocated(ADR 0039) andBinStockLevelChanged(ADR 0040). The legacyProductClassifiedwas removed at stage E (2026-10-17, ADR 0034): product classification is owned by product-master, so readcom.warehouse.wms.product-master.product.ProductClassifiedfromwarehouse.product-master.events.warehouse.inventory.analyticsis internal to this service's analytics projector; do not build against it. - Dispatch on the full
typestring; ignore unknown types. The catalog grows. Reject (DLQ/skip) anything that is not a valid CloudEvent. - Deduplicate on the CloudEvents
id. At-least-once. - Ordering is per reservation only (Kafka key = reservation id,
Hashbalancer — ADR-0021). - Treat the events as a projection, not as truth. For an authoritative
answer, call
GET /inventory/{sku}/usable. The event stream exists so consumers can keep a cheap local view warm, not so they can reimplement the ledger.
Verifying end to end
The integration was smoke-tested for real against the shared broker, not just unit-tested. To repeat it:
# 1. Postgres and Kafka up (compose Kafka: host port 19092)
docker compose up -d --wait postgres kafka
# 2. service up (DATABASE_URL, KAFKA_BROKERS, LOCATION_LOOKUP_MODE and the four
# *_CONSUMER_GROUP variables exactly as in the quickstart)
go run ./cmd/inventory &
# 3. seed a bin + stow, then reserve (the Idempotency-Key header is mandatory)
curl -s -X POST localhost:8080/reservations \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: smoke-1' \
-d '{"sku":"SKU-1","quantity":5,"demandRef":"order-42"}'
# 4. confirm it landed
docker compose exec kafka kafka-console-consumer \
--bootstrap-server localhost:29092 \
--topic warehouse.inventory.events --from-beginning
The unit-level equivalent lives in
internal/adapters/outbound/kafka/golden_test.go, which asserts the exact
CloudEvent JSON and content-type header the adapter produces against an in-memory Writer fake — no broker
required, which is why it runs in the default go test ./... suite.
Deployment
The service ships as a container (Dockerfile at the repo root, published to
GHCR by the docker-publish CI job on main) and as a Helm chart
(charts/inventory-storage, linted by the helm-lint job). In the local
Kubernetes stack its REST API is reached through Kong at
http://localhost:8000/api/inventory-storage, and it runs inside the Istio
mesh for east-west traffic; KAFKA_BROKERS and the consumer-group ids are
ordinary (mandatory) chart values (kafka.brokers comes from warehouse-infra's
_platform.yaml); LOCATION_LOOKUP_MODE=kafka is the chart default
(config.locationLookupMode), which warehouse-infra also sets explicitly.