Design Instacart
Understanding the Problem
🛒 What is Instacart? Instacart lets you order groceries from local stores (Costco, Safeway, Kroger, the corner shop) and have a personal shopper walk the aisles, pick your items, check out and deliver them, often within a couple of hours. Instacart doesn't own the stores or their inventory. It sits on top of thousands of retailers, keeps a copy of their catalogs and prices, and coordinates a fleet of independent shoppers.
You may also be asked to design 10-minute grocery delivery like Zepto, Blinkit or Swiggy Instamart. It's the same problem with a different fulfillment model. Instead of shoppers picking in a retailer's store, the company runs small dark stores (warehouses closed to the public) every couple of kilometers, owns the inventory, and has pickers pack orders in a minute or two while riders wait outside. The customer experience is the same (browse, cart, checkout, track), but owning the inventory flips several design decisions. We'll design the marketplace first and cover quick commerce as a deep dive.
Functional Requirements
Core Requirements
- Customers should be able to browse and search a store's catalog, with prices, for stores that deliver to their address.
- Customers should be able to place an order for a delivery window (or "as soon as possible") and pay for it.
- A shopper should be assigned to the order, pick the items in the store and handle out-of-stock items with replacements the customer approves in real time.
- Customers should be able to track their order until it's delivered.
Below the line (out of scope)
- Retailer onboarding and the retailer-facing dashboards.
- Shopper sign-up, pay calculation and payouts.
- Ads and sponsored products (a big business for Instacart, but a separate design).
- Ratings, support and refunds.
Non-Functional Requirements
Ask about scale. We'll assume about 1,500 retailers with 80,000 store locations, each store carrying 30,000 to 50,000 items, and 1M orders a day averaging around 40 items each.
Core Requirements
- Catalog search and browsing should return in under 300ms at p99, and stay available even when a retailer's systems are down.
- Prices and availability shown to customers should be as fresh as the retailer can give us, ideally within minutes for prices.
- Delivery windows must not be overbooked: if we promise 2-3pm, enough shopper capacity must exist to meet it.
- Order placement and payment must be strongly consistent and idempotent.
- Substitution prompts from the shopper should reach the customer within a couple of seconds.
Below the line (out of scope)
- Multi-region active-active order storage.
- Detailed payment processing (we'll use a payment provider).
Now the math, because it shapes the catalog design. 80,000 stores × 40,000 items is 3.2 billion store-item rows, each with a price and an availability status that can change daily. The product catalog (what a "Chobani Greek Yogurt 32oz" is: name, brand, images, nutrition) is much smaller, maybe 10-20 million distinct products, because the same product is sold in thousands of stores.
Orders are modest: 1M a day is about 12 per second on average, maybe 50 per second at peak. The write load on orders is easy. The hard parts are keeping 3.2 billion prices fresh, predicting what's actually on the shelf, and not over-promising delivery slots.
Separate the product (shared across stores, rarely changes) from the store item (this store's price and availability, changes often). Almost every good decision in the catalog design follows from that split.
The Set Up
Planning the Approach
We'll build the four requirements in order, then go deep on catalog freshness, predicting availability, delivery slot capacity, efficient picking, and the 10-minute variant.
Defining the Core Entities
- Product: a canonical item (brand, name, size, images, barcode/UPC), shared across retailers.
- Store Item: one product at one store: price, unit, aisle location if known, and an availability status or score.
- Store: a retailer location with an address, hours and a delivery zone.
- Delivery Slot: a time window at a store (say 2-3pm) with a capacity, the number of orders we can fulfill in it.
- Order: a customer's cart from one store, a slot, the payment authorization, and line items, each of which can be found, replaced or refunded.
- Shopper: the person picking and delivering, with a status and a location.
API or System Interface
GET /stores?lat=..&lng=.. -> [{ storeId, retailer, nextSlot, fee }]
GET /stores/{storeId}/search?q=yogurt&cursor=..
-> { items: [{ productId, name, price, availability: "likely" | "low" }], nextCursor }
GET /stores/{storeId}/slots?date=.. -> [{ slotId, window, available }]
POST /slots/{slotId}/holds -> { holdId, expiresAt } // hold for checkout
POST /orders
{ storeId, holdId, items: [{ productId, qty, replacementPref }], paymentMethodId, idempotencyKey }
-> 201 { orderId, status, total }
// shopper app
POST /shopper/orders/{orderId}/items/{lineId} { action: "found" | "not_found" | "replace", productId? }
// customer app
WS /orders/{orderId}/live // status, substitution prompts, shopper location
POST /orders/{orderId}/items/{lineId}/decision { accept: true | false, productId? }
High-Level Design
1) Customers should be able to browse and search a store's catalog
First, which stores serve this address. Each store has a delivery zone, and a Store Service answers "which stores deliver here" with a geo query, the same way a restaurant list works in food delivery. With 80,000 stores this is small enough to keep in memory.
Then the catalog. Retailers send us their data in many ways: nightly CSV files, hourly price feeds, real-time APIs, or a point-of-sale integration. A Catalog Ingestion pipeline normalizes it: it matches each retailer item to a canonical Product (by UPC barcode first, then by name and size with fuzzy matching), and writes Store Items to a store-item database. A wide-column or key-value store fits this well: Cassandra or DynamoDB with the key (storeId, productId) handles billions of rows and heavy write volume.
Search runs against Elasticsearch. A Catalog Service takes the query, searches the index for that store and returns items with their current price.
The open question is how to lay out the search index, since 3.2 billion store-item documents would be expensive to keep in sync. We'll get to that in the deep dives.
2) Customers should be able to place an order for a delivery window
At checkout the customer picks a slot. Each slot has a capacity: the number of orders our shoppers at that store can fulfill in that hour. If we let 200 people book a slot with capacity 50, 150 of them get late groceries.
This is a small contention problem, the same shape as flash sale inventory but with far less traffic. The simplest correct version is a conditional decrement:
UPDATE delivery_slots SET booked = booked + 1
WHERE slot_id = :slotId AND booked < capacity;
-- 1 row -> create a hold that expires in 10 minutes
-- 0 rows -> slot is full, show the next one
The Order Service then:
- Reprices the cart from current store-item prices (never trust client prices).
- Writes the order and links the slot hold, under a unique
idempotencyKey. - Authorizes the payment for the estimated total plus a buffer (often 10-20%), because the final total isn't known until the shopper checks out. Weighted items like produce and meat vary, and replacements can cost more or less.
An expiry job (or a delayed queue keyed on expiresAt) releases holds that never turned into orders, with a conditional update so it can't race checkout.
3) A shopper picks the order and handles replacements
When it's time to start shopping (the slot start time minus the expected shopping and driving time), the Dispatch Service offers the order to a shopper near the store. The shopper accepts with a conditional update on the order's assignment, so two shoppers can't claim the same order.
The shopper app shows a pick list. For each item the shopper scans the barcode to confirm the right product (scanning catches wrong sizes and flavors), and marks it found, not found or replaced. Each action is a call to the Shopping Service, which updates the order's line items.
The interesting part is replacements. When the shopper can't find the yogurt, the app suggests replacements ranked by a model (same brand different size, same size different brand) and the customer's stated preference ("pick best match," "pick specific item," "refund"). If the customer is in the app, they get a live prompt and can approve, pick something else or ask for a refund. If they don't answer in a few minutes, the shopper uses the default preference.
Shopper and customer are connected through a Live Service with WebSockets. Each order has a channel; the Shopping Service publishes line-item changes and replacement prompts to it, and both apps receive them. A push notification goes out too, because the customer probably isn't staring at the app.
At the end, the shopper pays at the register with a company-issued card that's authorized for that order's amount, and the order's final total is computed from what was actually picked. We capture that amount on the customer's authorization, which is why we authorized with a buffer.
4) Customers should be able to track their order
Tracking uses the same Live Service channel. Status changes (shopper assigned, shopping, checking out, on the way, delivered) are published by the Order and Shopping services, and the shopper's location is published while they drive, from their app's GPS pings every few seconds. The customer app shows each item's state in real time while shopping is underway ("12 of 38 items found"), which is a nice touch that also cuts support contacts.
Location handling is the same as in ride sharing: latest position in an in-memory geo store, history to a stream. The volume is small here (tens of thousands of active shoppers, not millions).
Potential Deep Dives
1) How do we keep 3.2 billion store-item prices fresh and searchable?
Retailers change prices all the time: weekly promotions, loyalty prices, regional pricing. Some send a full file nightly, some send deltas every few minutes, a few have real-time APIs.
Bad Solution: One Search Document per Store Item
Approach
Index every store item as its own Elasticsearch document: product text, plus storeId, price and availability. Search filters by storeId.
Challenges
3.2 billion documents, each carrying the full product text, is a huge index, and most of it is duplicated (the same yogurt description 30,000 times). Every price change becomes a document reindex. A retailer's weekly promo touching 5,000 items across 2,000 stores is 10 million reindexes in one go. Elasticsearch can do it, but you'd be paying for an enormous cluster that spends most of its time reindexing.
Good Solution: Index Products, Join Prices at Query Time
Approach
Index the ~20M products once, with their text, category and attributes, plus a list of retailer IDs that carry them (so we can filter by retailer). At query time:
- Search the product index filtered by the store's retailer, take the top few hundred matches.
- Batch-fetch
(storeId, productId)rows from the store-item store to get this store's price and availability. - Drop items this store doesn't carry and re-rank with price and availability.
Price changes now only touch the store-item store, which is a simple key-value write (DynamoDB or Cassandra handles tens of thousands per second easily), and they're visible immediately without any reindex.
Challenges
Step 2 is an extra round trip with a few hundred keys per search. A batched key-value read is typically a few milliseconds, so it fits in the latency budget, but you need to over-fetch in step 1 because some products won't be carried by this particular store. Filtering by "on sale" or sorting by price across the whole catalog also gets harder, because price isn't in the index.
Great Solution: Per-Retailer Indexes with Store-Level Fields for What Ranks
Approach
Combine the two. Most retailers price the same way across a region, so we can index by retailer and price zone instead of by store: a Safeway in one region shares one price list. That cuts the index from 80,000 stores down to a few thousand price zones. Index product text plus the zone's price and a "carried" flag for each zone, so search can filter and sort by price without a join. Per-store details that change constantly (availability scores, aisle locations) stay in the key-value store and are joined at query time for just the top results.
Ingestion is a streaming pipeline: retailer feeds land in S3 or arrive through an API, go through Kafka, get normalized and matched to products, and are written to the store-item store. A separate consumer applies changes to the search index in batches, coalescing many updates to the same document.
Challenges
Price zones vary by retailer, and some retailers really do price per store. The index layout needs per-retailer configuration, which is operational work. The payoff is a search index sized to the real number of distinct price lists, not the number of stores.
2) How do we know what's actually on the shelf?
This is the problem that makes the marketplace model hard. Most retailers can't tell us in real time what's on the shelf. Even their own inventory systems are often wrong: a store's system says 6 avocados, but they're bruised or sitting in the back.
Bad Solution: Trust the Retailer's Feed
Approach
Show an item as available if the retailer's last inventory file says it's in stock.
Challenges
Feeds arrive hours late and are often wrong for fast-moving or perishable items. Customers build carts around items that aren't there, shoppers spend time searching, and too many replacements make customers unhappy.
Great Solution: Predict Availability from Shopper Signals
Approach
We have a great real-time sensor that the retailer doesn't: thousands of shoppers walking the aisles and marking items found or not found. Every pick event is a data point: (storeId, productId, time, found). Feed it into a model that predicts the probability an item is on the shelf right now, using:
- Recent found/not-found events for this item in this store, weighted by recency.
- The retailer's feed, as one input among many.
- Time of day and day of week (bread is gone by 7pm on Sundays), restock patterns and the item's category.
The output is an availability score per store item. Score updates stream into the store-item store, and the Catalog Service uses them to rank, label ("Many in stock," "Low stock") or hide items. The same signal powers replacement suggestions: when something is likely out, we suggest replacements that are likely in.
Challenges
Most store items get no pick events on a given day, so the model has to generalize from similar items and stores. Feedback loops also bite: if we hide an item as "likely out," nobody orders it, so nobody tries to pick it, and we never learn it's back. Keep some exploration: show low-confidence items with a label rather than hiding them entirely.
In the marketplace model, inventory is a prediction, not a fact. In the dark-store model, it's a fact, and you can reserve it. Saying this out loud is a good way to show you understand why the two variants are designed differently.
3) How do we avoid overbooking delivery slots?
The conditional decrement in the high-level design stops us from exceeding a slot's capacity. The harder question is what the capacity number should be.
Capacity is a forecast. A slot's capacity comes from how many shoppers we expect to be active near that store in that window, times how many orders each can handle (a function of average order size and drive distance). A Capacity Service computes it from forecasted shopper supply and updates it through the day. If more shoppers come online than expected, capacity goes up and more slots open. If a storm keeps shoppers home, it goes down, but only for unbooked capacity: we never cancel a booked slot to fix a forecast.
Hot slots. Saturday morning slots at a popular Costco fill fast. The traffic is nowhere near flash-sale level, so a conditional update on one row in Postgres is plenty. If one slot ever gets truly hot, the same tricks apply: a Redis counter as a gate in front of the database.
Holds expire. Slots are held for about 10 minutes during checkout. Abandoned carts release them through a delayed queue. Every release is a conditional update on the hold's status, so a hold that's being turned into an order at the same moment can't also be released.
Pricing as a valve. When capacity is tight, raise the delivery fee for popular slots and lower it for quiet ones. It nudges customers toward the slots we can serve.
4) How do we make shoppers efficient?
Shopper time is the biggest cost in the business. Two things matter: how many orders a shopper handles per trip, and how fast they move through a store.
Batching. A shopper can pick two or three small orders in one store trip, using a cart with separate bags per order, and deliver them on one route. The Dispatch Service groups orders at the same store with nearby delivery addresses and compatible windows into a batch, and offers the batch as one job. Like courier matching in food delivery, this is an optimization over many orders at once, run every few minutes per store: minimize total shopper time subject to each order meeting its window.
Pick order. A raw pick list in cart order sends the shopper back and forth across the store. Sort it by the store's layout instead: produce, then bakery, then aisles in order, then frozen last so it stays cold. Most retailers don't give us a planogram, but shoppers do: the sequence of scans across many trips tells us which items are near each other, and we can learn an approximate aisle order per store from it.
Scan to confirm. Barcode scanning catches wrong items before they reach the customer. Weighted items (deli, produce) are entered with weight, so the final price is right.
5) How do we deliver in 10 minutes (Zepto, Blinkit)?
Ten minutes leaves no room for a shopper driving to a store, so quick commerce changes the physical setup and then the software follows.
Dark stores. Small warehouses, each stocking a few thousand of the fastest-selling items, placed so that most customers in a dense city are within about 2-3 km. A rider on a scooter covers that in 5-7 minutes in traffic. That leaves around 2-3 minutes to pick and pack, and a minute for the order to be assigned.
Serviceability first. The app checks which dark store serves the customer's location before it shows anything. If no store is within range, or the store is overloaded, the app says so (or offers a later slot) rather than promising 10 minutes it can't meet.
Real inventory, reserved at checkout. Unlike the marketplace, we own the stock and know the count of every SKU in every dark store, because every inbound shipment and every pick is scanned. So availability isn't predicted; it's reserved. Checkout decrements stock for each item atomically, in the same way as a flash sale, but per dark store and per item. A Redis Lua script can reserve all items of a cart in one step, with the database as the source of truth:
-- KEYS = stock:{store}:{sku} for each line, ARGV = quantities
for i, key in ipairs(KEYS) do
if tonumber(redis.call('GET', key) or '0') < tonumber(ARGV[i]) then return {0, i} end
end
for i, key in ipairs(KEYS) do redis.call('DECRBY', key, ARGV[i]) end
return {1}
The check-all-then-decrement-all happens atomically, so a cart is either fully reserved or not at all. Keys are hash-tagged by store (stock:{store42}:sku9) so one store's keys live on the same Redis shard and the script can touch them together. A cancelled order puts the stock back.
Pick and pack fast. The moment the order is placed, it appears on a picker's handheld with items sorted by bin location in the dark store's fixed layout (here we do have a precise map, because we designed the building). Riders are already waiting at the store; assignment is "next rider in the queue," not a marketplace search.
Forecasting. The real limit is stocking the right few thousand items in each dark store. Demand forecasts per store and per hour drive replenishment from a central warehouse. A dark store that's out of milk at 8am has failed regardless of how good the software is.
Final Design
The full flow, for the marketplace:
- Retailer feeds are ingested through Kafka, matched to canonical products and written to the store-item store; a consumer updates the per-retailer price-zone search index.
- The customer picks a store that delivers to them and searches; the Catalog Service queries Elasticsearch and joins availability scores from the store-item store.
- At checkout, the Order Service holds a slot with a conditional update against its capacity, reprices the cart, writes the order and authorizes payment with a buffer.
- Dispatch batches orders per store and offers them to nearby shoppers, who accept with a conditional update.
- The shopper picks in aisle order, scanning each item. Not-found items trigger replacement prompts to the customer over the Live Service, and every pick event feeds the availability model.
- After checkout at the register, the final amount is captured, and the customer tracks the shopper to their door.
For quick commerce, steps 1-2 are replaced by our own inventory per dark store, and step 3 reserves stock atomically instead of predicting it.
What is Expected at Each Level?
Mid-level
You should design the core flow: stores that deliver to an address, a searchable catalog, checkout with a slot, a shopper who picks and delivers, and live updates. You should notice that many stores carry the same product and avoid duplicating everything per store, and use a conditional update to keep slots from being overbooked. With prompting, you should handle replacements and explain why payment is authorized with a buffer before the final total is known.
Senior
You should split products from store items and pick an index layout that doesn't reindex billions of documents for every price change. Expect to explain that availability at third-party stores is unknown and how shopper pick events become a real-time availability signal. You should discuss slot capacity as a forecast, hold expiry races, and batching orders per shopper. If quick commerce comes up, you should explain how owning inventory turns availability from a prediction into an atomic reservation.
Staff+
You should frame the two variants as one platform with different fulfillment models and show which components change between them. Expect to discuss the economics: shopper time per order, batching and pick-path optimization, and dynamic delivery fees as a way to balance demand against capacity. You should talk about feedback loops in the availability model, how forecasting drives both slot capacity and dark-store stocking, and how the system degrades when a retailer's feed breaks or a dark store runs out.