Skip to main content

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:

MetricMeaningValue
receivedQuantitySummed quantity of StockReceived in the bucket.quantity
stowedCountCount of ItemStowed in the bucket.count
pickedQuantitySummed quantity of StockPicked in the bucket.quantity
reservationsCreatedCount of StockReserved in the bucket.count
reservationsExpiredCount of ReservationExpired in the bucket.count
reservationsRevokedCount of ReservationRevoked in the bucket.count
cycleCountsCompletedCount of CycleCountCompleted in the bucket.count
discrepanciesDetectedCount of DiscrepancyDetected in the bucket.count
unlocatedCountCount 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. + …)ContributesKeyed by
stock.StockReceivedreceivedQuantitySKU
stock.ItemStowedstowedCountSKU + bin
reservation.StockPickedpickedQuantitySKU
reservation.StockReservedreservationsCreatedSKU
reservation.ReservationExpiredreservationsExpiredSKU (enriched)
reservation.ReservationRevokedreservationsRevokedSKU (enriched)
bin.CycleCountCompletedcycleCountsCompletedbin
bin.DiscrepancyDetecteddiscrepanciesDetectedbin
stock.ItemUnlocatedunlocatedCountSKU + 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 against hourBucket.
  • sku, binId — optional exact-match filters.
  • granularity — optional, defaults to hour.

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 (the max(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 .v2 type plus a new dataschema.

Runbook notes​

  • Two processes, one writer. cmd/inventory-projector is the only writer of the analytical DB; cmd/inventory-reports connects read-only. The OLTP cmd/inventory never opens the analytical DB.
  • Empty on first deploy. The report is empty until events flow. To backfill history, replay warehouse.inventory.analytics from 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.