Real architecture · Mid
Instacart: shopper routing
Real production architecture. Key points: learned layout and ML + operations research.
Short answer
Real production architecture. Key points: learned layout and ML + operations research. Instacart delivers groceries and takes on the challenge of completing each delivery on time and with the right products.
01 · CONTEXT
Delivering groceries on time
Instacart delivers groceries and takes on the challenge of completing each delivery on time and with the right products.
Over a few hours there are thousands of orders to deliver, and doing this efficiently is the job of logistics systems. This case is based on a 2017 post written by a former VP of Data Science at the company, which describes a classic optimization problem combined with machine learning.
02 · THE PROBLEM
From TSP to SCVRPTWMT
The simplest formulation is a traveling salesman problem in which the shopper must go to the store first. With a fleet, each shopper receives a batch of orders to buy and then deliver in sequence, and the problem becomes a VRP, which generalizes the TSP.
Exact algorithms exist for TSP up to tens of thousands of deliveries, and even with millions of deliveries heuristics land within 2–3% of optimal.
| Variante | What it adds |
|---|---|
| TSP | The shopper must go to the store first. |
| VRP | A fleet of shoppers, each with a batch of orders delivered in sequence. |
| VRPTW | Narrow delivery windows, so only part of the assigned routes is feasible. |
| Capacitado (C) | Large or small vehicles, club cards, and alcohol orders differ among shoppers. |
| Multiple trips (MT) | Each vehicle can make more than one trip. |
| Stochastic (S) | New orders, shifts, and events such as weather and traffic change the plans. |
The sum of all the constraints is described in the post as an SCVRPTWMT.
03 · FROM GREEDY TO NEW
The fulfillment engine
The starting point was a variation of a greedy algorithm: sort orders by deadline, find the free shopper who can do the first order fastest, look for orders that fit without delay, and dispatch.
Since then the company has introduced new approaches, with a large impact on speed. In the post, minutes per delivery in San Francisco were cut in half, without compromising late deliveries or order quality.
One of the changes is to decompose the problem into subproblems, and one of them is batching deliveries.
A machine learning model predicts the expected time distribution for each combination of shopper and assignment.
Another subproblem is shopper assignment; the subproblems are solved nearly to optimality.
Heuristics limit the search space, handle anomalies, refine the solutions, and help adapt to uncertainty.
The batch plan is recalculated every minute and the dispatch decision is made at the right time.
04 · THE SURROUNDING SYSTEM
The engine is just one piece
The application that decides which orders each shopper handles is the fulfillment engine, but it is only one component of the logistics system, which also predicts demand and behavior, manages capacity and peak pricing, and plans the schedule.
The fulfillment engine is only one of the components of the logistics system.
Another component predicts demand and shopper behavior.
Another manages capacity and peak pricing.
Another plans and adapts the shopper schedule.
The systems are highly interdependent, and the company increasingly uses simulations to optimize them together.
05 · GPS DATA
Seeing the system with location data
To optimize shopper assignment and routing, and to communicate with consumers, Instacart collects a GPS data stream stream. Roughly every 10 seconds, the device reports timestamp, latitude and longitude, speed, direction, and accuracy, and the whole adds up to tens of millions of updates per day across the country.
The shopper's device periodically reports timestamp, position, speed, direction, and accuracy.
The platform collects this stream of location data.
Location is used to optimize shopper assignment and routing.
The data is also used to communicate well with consumers.
Datashader turns millions of points into visualizations that generate hypotheses and confirm changes in production.
| Data slice | What the visualization reveals |
|---|---|
| Accuracy | Accuracy is worse in the financial district, where tall buildings obstruct GPS, and the signal is lost inside stores. |
| Velocidade | Shoppers move faster on highways and slower in the financial district. |
| Direction | The layout of the city's streets becomes visible. |
| Origin store | Shows which stores deliver frequently in each neighborhood. |
| Shopper state | Lets you see what the shopper does inside the store, when the measurement is accurate enough. |
In short, the case combines optimization with real constraints, machine learning to estimate times, and field data to analyze the system.
Frequently asked questions
What is Instacart: shopper routing?
Real production architecture. Key points: learned layout and ML + operations research.
What does the Instacart: shopper routing design cover?
It is organized in these sections: Delivering groceries on time, From TSP to SCVRPTWMT, The fulfillment engine, The engine is just one piece, and Seeing the system with location data.
How long is Instacart: shopper routing and what level is it?
It takes about 15 minutes to read and is rated Mid level.
Now design it yourself
Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.