Latest Stock State Across Distribution Centers
Ingest distribution-center updates and serve the latest quantity and availability for each location–item pair.
Problem statement
For this exercise, assume distribution centers send complete stock snapshots for a location–item pair. Each pair has one authorized source, and updates carry a source epoch and increasing sequence number; a new authorized epoch supersedes an older one.
Quantity is nonnegative, availability means quantity is greater than zero, and the reported observation time must remain separate from ingestion time.
Design the service that maintains the newest authoritative state and lets callers look up quantity, availability, and last-update time. Duplicate retries and out-of-order delivery must never replace newer stock with older stock.
Retain update history for analytics separately from the current-state read path. Explain partitioning, failure recovery, and how callers distinguish stale data during an outage.
This exercise covers reported stock, rather than reservations, order allocation, payments, or promises that inventory cannot be oversold.
What to build
- Accept authenticated complete stock snapshots, including retries, from the source authorized for each location–item pair.
- Return the newest authoritative quantity, availability, and observation time for an exact location–item pair, with a visible freshness indicator.
- Retain update history for asynchronous analytics without delaying current-stock lookups.
At scale
- For this exercise, assume 5,000 distribution centers, 2 million item identifiers, and up to 100 million active location–item pairs; store active pairs rather than the full Cartesian product.
- For this exercise, assume 50,000 stock updates per second and 100,000 exact-pair lookups per second, with p99 lookup latency below 100 ms under normal load.
- For this exercise, assume normally delivered updates are reflected within 2 seconds, and retain update history for 30 days; during a disconnected-source outage, expose the last observed time rather than claiming fresh stock.