KatInterview

Fresh Food Stock and Fleet Tracking Platform Design

System DesignModel answer
MediumModel answerSystem Designsystem-designgeospatialstreaming

Last updated

Design a backend that follows perishable stock across warehouses and trucks, answers nearest-and-soonest-expiring queries, prevents overselling, and raises expiry warnings.

Scenario

A national grocery retailer wants a single platform that knows where its short-shelf-life stock is (dairy, produce, chilled goods) at any moment. Stock moves between distribution centers, stores, and delivery trucks. Design the backend.

What the platform must do

  1. Report the current position of every stock unit in near real time.
  2. Capture each unit's expiry date when it is received.
  3. Answer: "Give me the N closest units of product X that expire within the next T hours/days."
  4. Notify the right people when stock approaches its expiry date.

Quality attributes

  • Accepting position updates must stay highly available.
  • Inventory lookups must be fast.
  • Stock counts must be exact so the same unit is never sold twice.
  • The system must scale to millions of tracked units and thousands of updates per second.

What to cover in your answer

  • The API for reporting positions and for querying and reserving stock.
  • A data model for products, items, containers, and warehouse or vehicle locations.
  • Which storage you would choose for geospatial tracking versus authoritative stock state, and why.
  • How you absorb a high rate of position updates without overloading your main inventory database.
  • Any trade-offs, failure modes, and follow-up scaling concerns you would raise.

State your assumptions about scale before you start designing.

Hints

Hint 1

Ask who actually moves. Cartons sit in cases, cases on pallets, pallets in a zone or on a truck. If only containers and vehicles report positions, the write volume drops sharply.

Hint 2

Split data by the consistency it needs: positions can be slightly stale but must always be writable, while stock counts and reservations need strong consistency. Put a stream between ingestion and the inventory database.

Hint 3

For nearest-N queries, index the thousands of locations (warehouses, stores, vehicles) rather than millions of items, then read per-location stock buckets keyed by SKU and expiry day. For overselling, think conditional updates plus idempotency keys.

Hint 4

Expiry alerts can be driven by an index on expiry time bucketed by hour, scanned ahead of time by idempotent, partitioned workers.