Inside the Courier Assignment Problem: Decisions Every 90 Seconds

It was a rainy Friday evening; on the food side, order volume had climbed to 2.3 times that of a normal Friday. On the screen in the operations center, p90 delivery time was climbing from 34 minutes to 61 minutes, and the dashboard showed a strange contradiction: we had enough active couriers, there were even couriers showing as idle, yet orders were piling up and customer cancellations were rising. When we switched to the map view, we saw the real oddity: a significant share of the couriers weren't moving. They were waiting at restaurant doors. That night we lived through the most instructive failure of the dispatch system we'd been running for two years, and in this post I'll open up that system's internals, along with what we learned that night.

A Ninety-Second Breather

Let me start with the architecture. We don't assign couriers the moment an order comes in, instantly and greedily; we accumulate orders in 90-second windows and solve each window as a batch when it closes. That duration is itself an engineering decision and a balance between two forces: the longer the window, the more orders and courier options you have to work with, and matching quality measurably improves; but every second an order waits, it ages. In A/B tests, compared to instant assignment, a 30-second window improved average delivery time by 1.9 minutes and a 90-second window by 3.4 minutes; at 150 seconds the gain plateaued and the cost of delay took over. 90 isn't a round number; it's an experimental result. There are exceptions within the window, too: VIP restaurants and time-critical orders (for example, a reassignment that's already running late) can be assigned instantly without waiting for the window; the rules engine handles these exceptions ahead of the batch solver.

We don't solve the problem at city scale in each cycle; the map is divided into zones whose boundaries are updated weekly based on order density. In a busy evening cycle, a typical zone has around 40 pending orders and around 120 candidate couriers. A cost matrix is built: for each order-courier pair, the estimated total delivery time, the cost of inserting the order into the courier's current route, the synchronization gap between the restaurant's estimated preparation finish time and the courier's arrival, and a fairness term for a balanced distribution of work. At this scale, solving the assignment problem with a variant of the Hungarian algorithm takes milliseconds; our real budget is 800 milliseconds, and most of it is eaten up by filling in the matrix itself, that is, by producing thousands of ETA predictions. This is what the optimization literature doesn't tell you: the hard part of the assignment problem isn't the solver; it's the predictions inside the cost function.

Orders are accumulated for 90 seconds, a cost matrix is built for each zone, and the assignment problem is solved as a batch.
90 seconds isn't a round number; it's the result of an A/B experiment.

The backbone of those predictions is the ETA model. A courier's travel time to an order can't be calculated from straight-line distance; vehicle type (motorbike, bicycle, on foot), time of day, one-way streets, even a building entrance being on the back street can shift things by minutes. Our ETA model layers a correction learned from historical actuals on top of the route duration over the road network: in this zone, at this hour, with this vehicle, how many minutes above the routing engine's estimate does a trip typically come in? Every cell in the cost matrix goes through this model; tens of thousands of predictions per cycle fit into the 800-millisecond budget thanks to cached zone-hour corrections. And every completed delivery flows back as a prediction-actual pair; a dispatch system is an organism that relearns its own error every day, or at least it should stay one.

The Wrong Diagnosis: A Courier Shortage

That Friday night, our first diagnosis was a reflex: "We don't have enough supply." When it rains, demand goes up and couriers' willingness to go out goes down; it's the classic equation. We immediately turned on dynamic incentives and shifted couriers in from surrounding zones. Half an hour later the picture had barely improved. In fact, the numbers didn't support the hypothesis either: completed orders per courier per hour had dropped from 1.9 to 1.1. If it had been a supply problem, couriers would have been running harder and throughput would have held steady; for us, per-courier throughput had collapsed. The couriers were working, but their time was evaporating somewhere.

The Blind Spot in the Restaurant Kitchen

Where it was evaporating showed up in the courier app's status transition logs: the time between "arrived at restaurant" and "picked up order," which averages 3.5 minutes on a normal evening, had risen to 12 minutes that night. Our dispatch system sends couriers on their way based on the finish time given by the preparation time prediction model. That model had been trained on historical data and saw the restaurant's current load only through a weak signal. On the rainy night, restaurants were going through the same demand shock we were: kitchens were full, and actual preparation times had climbed to nearly twice the prediction. The model said "ready in 18 minutes," the courier showed up at the door at minute 18, and the food came out at minute 29. For the 11 minutes in between, the courier was busy in the system's eyes but, in reality, stuck in front of a door. So what was eroding capacity wasn't the number of couriers; it was a bad prediction holding courier-hours hostage. In dispatch systems, the most expensive mistake isn't the wrong match; it's triggering the right match at the wrong time.

The move to increase supply didn't work; the lost courier-hours came from waiting at restaurant doors, in other words from a wrong preparation time prediction.
The most expensive mistake isn't the wrong match; it's matching at the wrong time.

Fixing the Prediction, Then Not Trusting It

The fix moved forward on two tracks. The first was the model itself: real-time signals such as the number of orders the restaurant had accepted in the last 30 minutes, the queue of pending orders in the kitchen, and the weather were added to the preparation time prediction; the model now runs on features fed in real time rather than daily. On its own, this reduced the peak-hour prediction error (MAE) from 6.8 minutes to 2.9 minutes. The second track is less glamorous but, in my view, more important: we gave the system the ability not to trust its own predictions. If prediction uncertainty is high, dispatch can postpone the assignment by a cycle or two instead of sending the courier early; if actual wait times at a restaurant start systematically exceeding the prediction, assignments to that restaurant are automatically delayed and a "kitchen busy" signal shows up on the restaurant's panel. On top of that, the threshold of the bundling logic, which combines orders from the same restaurant going to nearby addresses into a single courier's run, loosens at peak load: if the wait is going to happen anyway, piggybacking a second order onto it is almost free capacity.

We didn't test any of these changes directly in production; our most valuable investment on the dispatch side is the simulator. We record every order, courier location, and restaurant event from past days, and we can replay any algorithm change, for example against that rainy Friday's data, compressing an hours-long day into minutes. The new preparation model and the postponement logic first "relived" that night in the simulator: p90 delivery dropped from 61 minutes to 44 in the simulation, and the gap between that and the 41 we later saw in production became a separate lesson about the simulator's calibration. Developing dispatch without a simulator is like adjusting a drug dose blindfolded; your patient is hundreds of thousands of orders every evening.

There's also a human side to the equation. We didn't add the fairness term to the cost function for decoration: pure efficiency optimization piles orders onto the fastest and most centrally located couriers; the courier in the outlying neighborhood wraps up the evening with two deliveries and leaves the platform the following week. We also track the variance of the hourly earnings distribution per courier, because the fairness you sacrifice today gets billed three months later as a supply crisis. Whose income you write into your optimization function is as much a business decision as an engineering one.

The preparation prediction was strengthened with real-time signals, assignments were postponed under uncertainty, changes were tested in the simulator, and fairness was monitored.
The error (MAE) dropped from 6.8 minutes to 2.9 minutes.

In the next big rainstorm, p90 delivery peaked at 41 minutes instead of 61; the average wait at the door stayed under 4 minutes, and hourly deliveries per courier held at 1.7 during peak hours. It's not perfect; rain still takes its tax, but now we know the line items of that tax. The lesson I took away from this work was this: optimization systems are only as good as their weakest predictions, and a good system has to be able to notice when its own predictions are lying. If you're working on a similar dispatch, field operations, or assignment problem, reach out through the contact page; even just comparing stories about couriers waiting at the door is instructive in itself.