What it is
A maps and location platform answers three kinds of question: what does this area look like (map tiles), how do I get from A to B (routing), and when will I arrive (ETA from live and historical traffic). Each has a different load profile, so a good design treats them as separate subsystems that share data: a read-heavy static content system, a CPU-heavy query engine and a write-heavy telemetry stream.
Why it exists
Doing any of the three naively fails at scale. Rendering tiles on demand from one region overloads the renderer and adds a cross-continent round trip to every pan. Running Dijkstra per route on a continental graph costs seconds of CPU. Ignoring live traffic gives the shortest route, not the fastest. The case study is about deciding, for each subsystem, what to compute ahead of time and what to compute per request.
How it works
Requirements and estimates. Functional: show a pannable, zoomable map; compute routes for driving (and walking, cycling, transit); show ETAs with live traffic; ingest location updates from navigating devices. Non-functional: tiles fast everywhere (well under 100 ms at the edge), routes in a fraction of a second, ETAs that reflect current conditions within minutes, high availability for viewing even when other parts fail. An illustrative estimate: 50 M daily users × 20 map views × 20 tiles ≈ 20 billion tile requests per day, about 230 k/s on average and several times that at peak; probes from navigating devices every few seconds add billions of small writes per day. These numbers are illustrative, not measurements of any product.
Tiles. The world is cut into a quadtree of tiles addressed as z/x/y: zoom level z has 4^z tiles. Modern clients mostly use vector tiles (geometry plus attributes, styled on the device), which are smaller than raster images and let the client restyle without new downloads. Tiles are generated in a batch pipeline from the map database, written to object storage under versioned paths, and served through a CDN. Demand is extremely skewed (city centres, common zoom levels), so an edge cache holding a small fraction of tiles answers most requests; in the lesson’s simulation, an LRU of 10% of tiles answers about 70%. Low zoom levels are few and hot; high zoom levels over oceans and deserts are many and cold, and can be generated lazily or stored as a shared "empty" tile.
Routing. The road network is a weighted directed graph (intersections as nodes, road segments as edges, travel time as weight). Dijkstra’s algorithm explores outward until it reaches the destination; on a continent that settles millions of nodes. Contraction hierarchies (CH) precompute an ordering of nodes by importance and add shortcut edges so that contracting unimportant nodes preserves shortest-path distances. A query runs a bidirectional search in which each side only relaxes edges towards more important nodes; the searches meet near the top of the hierarchy after settling hundreds to a few thousand nodes. Customizable route planning (CRP) and customizable CH split preprocessing into a slow, metric-independent phase (graph partitioning or node ordering) and a fast customization phase that applies new edge weights, which is what makes live traffic practical. Open-source engines such as OSRM, Valhalla and GraphHopper implement variants of these ideas.
Live traffic. Navigating devices send GPS probes (position, time, heading, speed). They land on a durable stream (a log or topic) partitioned by region or road segment. Map matching snaps noisy points to the most likely road segments (typically with a hidden Markov model over candidate segments) and aggregates per-segment speeds over short windows into a live speed store. A second consumer archives every probe to build historical speed profiles (per segment, weekday and time of day) and to train ETA models. Location data is personal: aggregate early, drop identifiers, and keep raw traces only as long as needed.
ETA. The arrival time is the sum of segment travel times along the route, plus turn and intersection costs. Segments with fresh live data use it; others use the historical profile. Production systems add a learned correction for effects the sum misses (traffic lights, turns, how conditions will evolve during a long trip).
When to use it
This decomposition fits any product built on geography: navigation, delivery and logistics, ride-hailing dispatch (which also needs a geospatial index of moving vehicles), real-estate and travel maps. The tile part alone fits any large static, hierarchical image or geometry set (satellite imagery, game worlds, very large documents).
When not to
- Small, regional or internal maps: a hosted map provider or a single tile server with a CDN is enough; building routing and traffic is not justified.
- If you only need distance estimates (e.g. "within 5 km"), straight-line or cached travel-time matrices may do without a routing engine.
- Highly dynamic graphs where edge weights change every second for most edges make pure CH preprocessing a poor fit; use customizable approaches or accept slower queries.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Pre-rendered tiles behind a CDN | Low latency everywhere, origin protected, survives origin outages for hot tiles | Batch pipeline, storage for every zoom level, re-generation when map data changes |
| Vector instead of raster tiles | Fewer bytes, client-side styling, crisp rotation and zoom | Client rendering cost, more complex clients |
| Contraction hierarchies | Millisecond queries on continental graphs | Hours of preprocessing; live weights need a customizable variant |
| Stream pipeline for probes | Ingestion decoupled from processing, fan-out to many uses | Lag and stale data under failure; at-least-once processing needs idempotence |
| Live speeds with historical fallback | ETAs reflect current traffic | Freshness thresholds to tune; sparse roads rely on history |
Alternatives
- On-demand tile rendering with a render cache: less storage, more CPU and cold-start latency; reasonable for rarely viewed zoom levels.
- A* with a good heuristic, or ALT (landmarks): faster than Dijkstra with lighter preprocessing, but much slower than CH on long routes.
- Precomputed distance matrices for a fixed set of points (warehouses, stores): instant lookups, useless for arbitrary origins.
- Batch traffic (hourly aggregates only): far simpler, but blind to incidents.
Failure modes
- Origin outage: cache hits keep working; misses fail. Long TTLs on versioned URLs and stale-if-error turn most of the remaining errors into slightly old tiles.
- Cache cold start or purge: purging all tiles after a style change sends the full request rate to the origin. Version URLs and roll out gradually instead of purging.
- Routing preprocessing fails or lags: keep serving the previous graph version; a new road missing for a day is better than no routing.
- Traffic pipeline lag: consumers fall behind and live speeds go stale; ETAs silently degrade to history. Alert on consumer lag and data age, size consumers for catch-up, and skip probes too old to matter.
- Bad probe data: GPS drift, tunnels and parked phones create phantom jams. Filter and require a minimum number of distinct probes before trusting a live speed.
In production
Tiles are served from object storage through multiple CDN layers (edge and regional shield), with cache keys including the data version. Routing servers hold the preprocessed graph for a region in memory and are replicated behind load balancers; cross-region trips use overlay graphs or partition-aware algorithms. The probe stream is partitioned so that one segment’s probes land on one consumer, which keeps aggregation local. Dashboards track tile hit ratio and origin load, route latency per region, consumer lag and the age of live speed data, because a stale traffic layer produces no errors at all.
Common misconceptions
- "Routing is just Dijkstra." Correct, but far too slow per request at continental scale; production engines rely on preprocessing.
- "A CDN only helps latency." It also caps origin load and keeps serving hot content when the origin fails.
- "No traffic data means no traffic." It means unknown; fall back to historical profiles.
- "A stream pipeline outage causes errors." Usually it causes stale data, which is quieter and must be monitored explicitly.
Interview angle
Start with requirements and a tile estimate, then split the system into tiles, routing and traffic. Interviewers look for: the quadtree tile scheme and why a CDN fits; that you know plain Dijkstra does not scale and can name a preprocessing technique (CH, CRP, A* with landmarks) and its cost; how live traffic gets from phones to edge weights (stream, map matching, aggregation); how ETAs fall back when data is missing; and how each part degrades under failure. Mention privacy of location data unprompted.
Model assumptions
Simulated parts are a simplified model, not a benchmark. Tiles: 10,000 distinct tiles requested with Zipf(1) popularity and Poisson arrivals; the tile store has 16 connections and a 40 ms mean read (lognormal, cv 0.4, about 400 reads/s); the CDN edge is a server with a 1,000-tile LRU cache that fills on misses; network hops are fixed (viewer → origin region 50 ms, viewer → edge 10 ms, edge → origin 40 ms). Routing: the route service has 8 workers; a plain Dijkstra search is modelled as 1.5 s of work per route and a hierarchy query as 8 ms, both illustrative. Traffic: probes arrive at 200/s on a topic that copies each one to a map-matching and an archive subscription; map matching has 4 slots at 15 ms per probe (12 slots after scale-out), the archiver 4 slots at 5 ms; unacknowledged messages are redelivered. The contraction-hierarchy query and the ETA lookup are scripted illustrations (packets only, not simulated). Utilisation is the fraction of busy workers or connections, not CPU; all numbers show behaviour and orders of magnitude only.