KatInterview

Design a Real-Time Stock Availability Service

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsconcurrencycaching

Last updated

Design a distributed inventory service that tracks stock across many locations, handles concurrent reservations without overselling, and pushes availability updates to clients in near real-time.

Scenario

You're joining the platform team at a company that connects shoppers to retail locations. The platform needs an inventory service that can tell shoppers whether a product is available at a nearby store, hold stock while a cart is being checked out, and keep displayed availability reasonably fresh without hammering the database on every page load.

Unlike a warehouse system where the company controls every shelf, store stock levels here are tracked indirectly: data comes from retailer feeds, point-of-sale integrations, and signals from field workers reporting what they actually found. That makes the inventory count an estimate with a confidence level, not a hard truth.

What to Cover

Spend a couple of minutes scoping the problem before diving in. Then walk through:

  1. Functional and non-functional requirements — what operations the system must support, and what consistency and latency targets matter
  2. Scale estimates — order-of-magnitude numbers for locations, SKUs, read QPS, and write throughput
  3. API design — key endpoints for reads, reservations, commits, releases, and adjustments
  4. Data model — schema for inventory state, reservations, and an audit ledger; justify your storage choices
  5. Architecture — how components fit together end-to-end (read path, write path, real-time fan-out)
  6. Deep dives on at least two of:
    • Preventing overselling under high concurrency
    • Handling hot SKUs (a promoted item that gets hammered all at once)
    • Keeping the read cache fresh without dual-write bugs
    • Expiring abandoned reservations safely
    • Ingesting large bulk retailer feeds reliably

A strong answer surfaces trade-offs rather than presenting one approach as obviously correct. Numbers, even rough ones, are better than vague adjectives like "high traffic."

Hints

Hint 1

Start by separating the read path (browse/search, very high QPS, tolerates slight staleness) from the write path (reservations, requires strong consistency per location+SKU). The two paths have different consistency needs and can be optimized independently.

Hint 2

The safest way to reserve stock without a race condition is a conditional UPDATE — decrement the count in the WHERE clause rather than reading first and writing second. Think about what happens when multiple orders hit the same popular SKU at the same millisecond.

Hint 3

A reservation that is never committed or released will lock up stock forever. How does the system recover from a shopper who abandons their cart or whose app crashes mid-checkout? And how do you make sure retried requests don't double-reserve?