Design an Inventory System for a Grocery Delivery Service
Company: Instacart
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
Design an inventory system. The report gives only the topic, so settle the scope with the interviewer first. For a grocery delivery service whose shoppers pick customers' orders from store shelves, the usual framing is: keep track of which products each store has, so that customers can order items that are likely to be on the shelf and shoppers can find them.
```hint Whose shelf is it?
Decide whether the system owns the stock it counts or only observes stock that someone else controls. That choice decides whether you can reserve units or only estimate availability.
```
```hint Signals disagree and go stale
Stock information arrives from several sources with different delays and reliability. Decide how a product's availability is computed when they conflict, and how confidence changes as they age.
```
### Constraints and Clarifications
- Not given: who owns the stock, where stock information comes from, the number of stores and products, how often stock changes and how fresh the data must be, and whether an order must reserve units. Ask, or state your assumptions.
### Clarifying Questions
- Does the service hold the stock itself, in warehouses where units can be reserved, or does it sell from partner stores whose shelves it does not control?
- Where does stock information come from: store systems, periodic files, sales, or shoppers reporting items found and not found?
- What must the system answer: whether a product is available at a store now, how many units there are, or when it will be back?
- How fresh must availability be while customers browse, and when an order is placed?
- How many stores, products per store, updates per second and reads per second?
- What happens when an ordered item turns out to be missing: a replacement, a refund, or another store?
### What a Strong Answer Covers
- Settles ownership of the stock, the data sources, freshness and reservation semantics before designing
- A data model for products, stores and per-store stock that records the source and time of each signal
- Ingestion of bulk files and real-time signals that is idempotent and tolerant of late or out-of-order data
- An availability estimate that reconciles stale and conflicting signals, or, for owned stock, reservations that cannot oversell
- A read path at catalog scale, with partitioning, caching and search index updates
- Protection against bad data, failure handling, and measurement of how accurate the shown availability is
### Follow-up Questions
- A store's data stops arriving for a day. What do customers see, and how do you notice?
- Shoppers report the same item missing in three orders within an hour. What should change, and how quickly?
- Two customers order the last unit of a product in a warehouse you own. How do you avoid selling it twice?
- How would you measure whether the availability shown to customers is accurate?
Overview: Design an inventory system for a grocery delivery service whose shoppers pick orders in stores, after settling who owns the stock and where stock signals come from. It tests the data model, ingestion of store data and shopper reports, availability estimates under stale or conflicting data, reservations for owned stock, and the read path at catalog scale.
Read the full Instacart Software Engineer interview experience this question came from