# Maps routing - precompute, then watch it go stale

> Teaches how a shortest path over a continental road graph is bought with precomputation, and what live traffic does to work that was done last night. Live…

Source: https://tierslate.com/templates/maps-routing

Location & logistics · System design · deep · 8 step walkthrough · 5 tables

Teaches how a shortest path over a continental road graph is bought with precomputation, and what live traffic does to work that was done last night.

**Own this board: 800 credits.** The first act plays on the page. Owned once with credits, never a subscription.

## What this board gets wrong on purpose

The tension: Live traffic is applied as a penalty overlay at query time rather than being contracted into the hierarchy, because re-running forty minutes of preprocessing for one blocked road is absurd. The cost is that contraction hierarchies are only CORRECT for the weights they were built with: a shortcut was inserted because it preserved a shortest path under last night's weights, and an overlay that makes one edge ten times slower can make that shortcut a lie. The board handles it by letting the search relax downwards when an overlay edge is on the shortcut path, which turns a 12 ms query into a 60-90 ms one exactly during rush hour, when both the traffic and the query volume peak together. Nothing here measures how often that happens, and the ETA is computed from the same overlay, so a route the search declined to re-examine carries an ETA that is confidently wrong. The rebuild runs every three hours and takes forty minutes, which means the hierarchy is on average ninety minutes out of date with the road network itself - fine for traffic, quietly wrong for a road that closed permanently this morning.

## Practise this as an interview

Take Maps routing - precompute, then watch it go stale as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

## Start here

### Why this design

Maps routing is the cleanest example in system design of buying query time with precomputation - and of paying for it when the world changes. A continental road graph is 60 million nodes, and plain Dijkstra settles most of them, so a 12 ms answer is only possible because most of the work was done hours earlier. Interviewers use it to probe whether you can reason about preprocessing versus freshness, and whether you notice that the expensive tier is probe ingest rather than routing. Google Maps, Apple Maps and every logistics router make this exact trade.

### What you will learn

- Why plain Dijkstra fails at continental scale, and how**contraction hierarchies**- node ordering plus shortcut edges - turn a search into a few hundred settled nodes.
- What the trade costs:**about 40 minutes of contraction on 64 cores, every 3 hours**, so the hierarchy is on average 90 minutes behind the road.
- Why live traffic is a**query-time overlay**rather than a rebuild, and how a large weight change can invalidate the very shortcut that made the query fast.
- Why ingest dominates:**500,000 probes/s at peak against 8,100 route requests/s**, each probe map-matched to an edge.
- Why snapping a GPS point to a road is an**S2 level-16 cell lookup**over line segments.
- Why an ETA is a forecast - historical speed profiles per edge per hour of week for the part of the route not reached yet - not a sum of current speeds.

### How to read this board

1. Press play once: the walkthrough follows one route request from a GPS point to an ETA.
2. **THE QUERY**, then**PRECOMPUTED**: the request with its graph version pin, and the forty-minute build it depends on.
3. **TWELVE MILLISECONDS**: snapping, the bidirectional upward search and the overlay check.
4. **LIVE TRAFFIC**: the probe stream that exists to invalidate the band above it.
5. **DATA MODEL**: the source of truth for the graph, not the serving path.
6. Then pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.

## 1 · Requirements

Two hundred million route requests a day over a graph of 130 million edges whose weights change every five minutes. Every requirement below is really a question about how much work may be done before the question is asked.

### Ask these before designing

- **Is the cost function fixed?**Contraction hierarchies are precomputed FOR a cost function. One metric (fastest by car) is one hierarchy. Fastest, shortest, avoid-tolls, lorry-with-a-height-limit and bicycle are five hierarchies, or one much harder algorithm.
- **Must the route be optimal, or merely good?**Optimal permits CH and forbids most heuristics. "Good" permits A\* with landmarks and a much simpler operation. Interviewers rarely say which they want, and the answer changes the entire board.
- **How live is live traffic?**Five-minute aggregates are a different system from thirty-second ones. The second forces the overlay design; the first would almost permit folding traffic into a nightly rebuild.
- **Does the route have to stay stable during the trip?**If a reroute may fire whenever a better path appears, the driver is sent round in circles as the traffic oscillates. Stability is a product requirement that constrains the algorithm.
- **Is the road graph the same for everybody?**Turn restrictions, vehicle profiles and access rules make it not quite one graph, and every per-user variation is either a filter at query time or another hierarchy.
- **What is the acceptable staleness for a road that closed permanently?**This is the requirement that decides the rebuild cadence, and it is usually stated as traffic freshness by mistake.

### Functional

- Given two points, return an optimal route with a distance, a duration and turn-by-turn geometry.
- Snap each endpoint to a real road edge, respecting direction and access rules.
- Apply live traffic to the duration and, where it is severe enough, to the route itself.
- Serve an ETA that accounts for expected conditions along the route at the time the driver will actually be there.
- Ingest GPS probes from navigating devices, map-match them to edges, and aggregate speeds.
- Rebuild the hierarchy on a schedule without interrupting queries.

### Non-functional

- **Route p50 12 ms, p99 90 ms.**The p99 is dominated by queries whose shortcut path has been invalidated by the overlay, which is the design’s honest cost rather than a tuning problem.
- **The answer must be the true optimum under the applied weights**, or the product is quietly wrong in a way no user can detect and every competitor comparison exposes.
- Traffic visible in the ETA within**90 s**of the probes that imply it.
- **99.99%**for routing, degrading to free-flow weights rather than failing.
- The graph is**immutable per version**. A route computed against version N must be unpackable against version N, which makes version pinning per session a correctness requirement.

### Explicitly out of scope

Map data production and conflation, geocoding and address search, indoor and pedestrian routing, ride dispatch (that is the matching board), multi-stop vehicle routing, which is a different NP-hard problem wearing the same coat.

## The rest of this board

This page publishes the question. The answer - 5 more written pages, an 8-step narrated walkthrough and a 5-table schema - is the board itself, and it opens in Tierslate.

- 5 written pages
- 8 walkthrough steps
- 5 tables (33 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [Fleet tracking system design](https://tierslate.com/templates/fleet-tracking) - Teaches how a continuous position firehose is split into a tiny live picture and an enormous history, and how retention rather than hardware decides what it costs.
- [Geofencing system design](https://tierslate.com/templates/geofencing) - Teaches how a covering index reduces every-point-against-every-fence to a handful of tests, and why a jittery GPS makes the crossing itself the harder problem.
- [Proximity search system design](https://tierslate.com/templates/proximity-search) - Teaches how to size a geospatial index against the query it serves, and why the nearest answer is usually in the cell next door.
- [Ride matching system design](https://tierslate.com/templates/ride-matching) - Teaches how a geospatial index turns supply and demand into a dispatch decision, and why that decision is an assignment over a batch rather than a nearest-neighbour lookup.
- [Parking reservation system design](https://tierslate.com/templates/parking-reservation) - How spots are booked by time window without double booking, and what happens when a car overstays.
- [Package tracking system design](https://tierslate.com/templates/package-tracking) - How carrier scan events become one shipment timeline, and why events arrive late and out of order.
- [Surge pricing system design](https://tierslate.com/templates/surge-pricing) - How supply and demand per map cell set a multiplier, and why the price must be locked when it is shown.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
