Inventory Flow & Accuracy Report
The analytical data product owned by Inventory & Storage. It is built entirely from this service's own domain events (never another service's database) and served read-only. See ADR-0011 for the decision.
Name & owner
- Report: Inventory Flow & Accuracy.
- Owner: the Inventory & Storage service/team (the same team that owns the OLTP write model).
Grain
One row per (SKU × bin × hour bucket), where hourBucket is the UTC hour
the row aggregates. Flow events (received, picked, reserved) carry a SKU but no
bin; accuracy events (cycle count, discrepancy) carry a bin but no SKU; stow and
unlocate carry both. The unused dimension is the empty string for a given event,
so a row is keyed by whichever dimension(s) its events actually carry. Metrics
per row:
| Metric | Meaning | Value |
|---|---|---|
receivedQuantity | Summed quantity of StockReceived in the bucket. | quantity |
stowedCount | Count of ItemStowed in the bucket. | count |
pickedQuantity | Summed quantity of StockPicked in the bucket. | quantity |
reservationsCreated | Count of StockReserved in the bucket. | count |
reservationsExpired | Count of ReservationExpired in the bucket. | count |
reservationsRevoked | Count of ReservationRevoked in the bucket. | count |
cycleCountsCompleted | Count of CycleCountCompleted in the bucket. | count |
discrepanciesDetected | Count of DiscrepancyDetected in the bucket. | count |
unlocatedCount | Count of ItemUnlocated in the bucket. | count |
Quantity metrics use the summed Quantity value object the event carries;
everything else is an event count.
Inputs (analytics topic events)
Consumed from warehouse.inventory.analytics (the dedicated analytics
topic, separate from the integration topic). Every message is a CloudEvents
1.0 event (ADR-0024) with
dataschema urn:warehouse:inventory-storage:analytics:<EventName>:v1. The
projector dispatches on the full type, dedupes on the CloudEvents id,
takes the bucket timestamp from time, and logs-and-skips (WARN) anything
that is not a valid CloudEvent.
type (com.warehouse.wms.inventory-storage. + …) | Contributes | Keyed by |
|---|---|---|
stock.StockReceived | receivedQuantity | SKU |
stock.ItemStowed | stowedCount | SKU + bin |
reservation.StockPicked | pickedQuantity | SKU |
reservation.StockReserved | reservationsCreated | SKU |
reservation.ReservationExpired | reservationsExpired | SKU (enriched) |
reservation.ReservationRevoked | reservationsRevoked | SKU (enriched) |
bin.CycleCountCompleted | cycleCountsCompleted | bin |
bin.DiscrepancyDetected | discrepanciesDetected | bin |
stock.ItemUnlocated | unlocatedCount | SKU + bin |
sku is enriched onto reservation-lifecycle events (ReservationExpired,
ReservationRevoked) by the publisher via a ReservationRepo lookup, since
those domain events carry only a reservation id. LocationRecorded is never
published to this topic — the analytics publisher's analyticsEventFor
returns "not part of the contract" for it, so no outbox row or Kafka message
is produced. ProductClassified (SKU master data) was published to this
topic from 2026-10-06 (ADR 0031) until
ADR 0034; it no longer reaches this topic (the one-shot
backfill that wrote the integration topic was removed at stage E, 2026-10-17).
The projector still acknowledges
and ignores it if one arrives: it moves no Flow & Accuracy metric.
Interface
REST (served by cmd/inventory-reports, read-only)
GET /reports/flow-accuracy?from=<RFC3339>&to=<RFC3339>&sku=&binId=&granularity=hour
GET /reports/flow-accuracy/freshness
GET /healthz
from,to— required, RFC3339,[from, to)compared againsthourBucket.sku,binId— optional exact-match filters.granularity— optional, defaults tohour.
Response (200):
{
"rows": [
{
"sku": "SKU-1",
"binId": "",
"hourBucket": "2026-08-26T14:00:00Z",
"receivedQuantity": 42,
"stowedCount": 0,
"pickedQuantity": 7,
"reservationsCreated": 3,
"reservationsExpired": 1,
"reservationsRevoked": 0,
"cycleCountsCompleted": 0,
"discrepanciesDetected": 0,
"unlocatedCount": 0
}
]
}
Freshness (200):
{ "lagSeconds": 4.2 }
Errors use RFC 7807 application/problem+json, consistent with the OLTP API
(ADR-0005).
MCP (curated, read-only)
Tool get_inventory_flow_accuracy_report — same filters as the REST
endpoint; it calls the reports REST rather than opening the analytical database.
Exposed by the existing cmd/mcp server (Streamable HTTP) when
REPORTS_BASE_URL is set, consistent with
ADR-0008.
Freshness SLA
- Definition:
lagSeconds= now − age of the most recently applied event. - Target: p95 event-to-report lag < 30s under normal load.
- Exposed:
GET /reports/flow-accuracy/freshness. - On an empty read model the lag is
0(themax(occurred_at)NULL row is read as "no events yet", not an error). - Breaching the SLA is an operational signal (projector lag / consumer down), not a correctness bug — the report catches up when the projector does.
Versioning
- Additive fields (new optional row metric, new query filter) are non-breaking.
- A breaking change to a row's shape or meaning is a new endpoint/tool version.
- The analytics event contract versions independently via the CloudEvents
dataschema(urn:warehouse:inventory-storage:analytics:<EventName>:v<N>); a breaking payload change is a new.v2type plus a newdataschema.
Runbook notes
- Two processes, one writer.
cmd/inventory-projectoris the only writer of the analytical DB;cmd/inventory-reportsconnects read-only. The OLTPcmd/inventorynever opens the analytical DB. - Empty on first deploy. The report is empty until events flow. To backfill
history, replay
warehouse.inventory.analyticsfrom earliest into a fresh projector; Kafka retention must cover the desired window. - Eventual consistency. The report is a projection, not a real-time view; it meets the freshness SLA, not transactional consistency.