The toll grew with every stop
The portal's map joined the day's stops with straight lines, and I decided the order by eye. The off-the-shelf option was a routing service that charges per query: every stop you add to the plan is one more billed query. A planner that charged me more the better it planned.
The portal needed three answers: which stop goes first, how many fit in one shift, and what time each customer's turn comes.
The time matrix is the expensive input
A route optimizer sounds like cartographic magic, and on the whiteboard it's boring: points, one vehicle with limited capacity, a time window per point (the slot when someone can receive the delivery), a cap on stops and a shift length. The solver looks for the order that respects those constraints and finishes earliest.
All of that feeds on a single heavy input: the time matrix, how long it takes to go from each point to every other one over real streets. I took two things for granted: that the matrix was the proprietary product, and that knowing the streets of Lima came at a high price. Neither turned out to be true.
Anyone can download the map extract from OpenStreetMap. OSRM, an open source routing engine, computes the street-by-street matrix in a container on the server where the portal already lived. What the per-query price buys is the convenience of not installing it.
Download the map, compute the matrix
Pay per query to look at the map
A small service that returns order, ETA and route
We set up a Python service with FastAPI that runs Google OR-Tools, the open source solver for routing with capacity and time windows. The portal sends it the stops already turned into coordinates and gets back the order, an ETA (estimated time of arrival) per stop and the street-by-street line of the route. Straight lines look fine on screen, but you can't promise anyone an arrival time with them.
If OSRM doesn't answer, the plan comes out anyway
A service of your own goes down the same way a paid one does, with the detail that you're the one bringing it back up at nine at night. So the planner doesn't wait: if OSRM goes past the timeout, the matrix gets computed with straight-line distance. The estimate gets worse and the plan still comes out complete.
The other decision was about what the customer sees. When the vehicle's last position is more than 3 minutes old, the page shows it interpolated over the planned route and labelled "approximate location". An old pin presented as live GPS is a small lie that uncovers itself when nobody rings the doorbell.
Zero per query, and a map I have to update
The five planned phases shipped: geocoding, optimization, notifications, proof of delivery and reports. The routes we loaded by hand for testing came out verified end to end, with ETAs computed over the street network. The cost per routing query is zero, and it stays at zero the day deliveries grow.
The map extract has to be updated by hand. OpenStreetMap changes, Lima changes faster, and nobody is going to tell me when a street turns one-way. The vendor used to do that maintenance, and now it's part of the price of keeping it at home.
Before I accept a per-query charge I check whether the vendor sells data only they have, or math published decades ago. The second kind I run next to the portal, and the map no longer charges me a toll for looking at it twice.
