Skip to main content
~/Anil Goral
~/writing/how-google-maps-works-routing-and-gnns.md

Algorithms & Distributed Systems · 4 min

How Google Maps Works: Contraction Hierarchies, S2 Geometry, and Graph Neural Networks

From Edsger Dijkstra's twenty-minute Amsterdam café algorithm to Contraction Hierarchies, Hilbert curves on S2 spheres, and DeepMind's Graph Neural Networks for future traffic forecasting.

Frontier Technology & AI SystemsAlgorithmic systems studyAlgorithmsGraph theoryAIDistributed systems

01 · Foundations

From a twenty-minute café idea to combinatorial explosion

Planetary navigation begins by abstracting asphalt and concrete into a weighted mathematical graph: intersections and roundabouts become nodes, road segments become edges, and travel times become edge weights. In 1956, Dutch computer scientist Edsger Dijkstra sketched the canonical shortest-path algorithm for that graph in roughly twenty minutes while having coffee with his fiancée at an Amsterdam café.

Dijkstra's algorithm radiates outward from the origin like ripples across a pond, guaranteeing the mathematically optimal path. Across a small neighborhood, that symmetry is effortless. Across a continental road network containing hundreds of millions of vertices, searching radially from New York to Los Angeles wastes vast compute scanning dead-end cul-de-sacs and rural backroads in every wrong direction.

A* search trims that waste by adding a geometric heuristic, f(n) = g(n) + h(n), combining actual distance traveled with a straight-line Euclidean estimate toward the destination. Yet whenever coastlines, mountain ranges, rivers, or congested metro rings force detours, A* still expands far too many redundant nodes to serve billions of live queries within milliseconds.

  • Representing physical geography as a weighted graph remains the enduring core; modern routing layers speed and prediction onto Dijkstra rather than discarding it.
  • Pure runtime graph search hits a memory-bandwidth wall when millions of concurrent drivers request dynamic recalculations.

02 · Hierarchy

Contraction Hierarchies: precomputing the highway skeleton

Developed in the mid-2000s, Contraction Hierarchies (CH) solved continental latency by splitting pathfinding into heavy offline preprocessing and featherweight live queries. Rather than inspecting every street each time a user taps "Directions," the preprocessing pipeline ranks intersections by structural importance—placing residential turnarounds near the bottom and major interstate interchanges at the top.

Nodes are then systematically "contracted" from lowest to highest importance. Whenever removing a local node disrupts a shortest path between two remaining neighbors, the algorithm inserts a direct shortcut edge storing the exact precomputed cost. When a live driver asks for a route, two tiny searches run simultaneously—one climbing strictly upward in importance from the origin, and one climbing upward from the destination—until they meet along the upper highway spine.

Because queries only traverse upward shortcuts and are laid out for CPU cache locality, continental routes that once required inspecting millions of intersections collapse to a few hundred node evaluations in a fraction of a millisecond.

  • Precomputed shortcut hierarchies move expensive graph exploration offline so interactive queries stay sub-millisecond.
  • Deterministic hardware-friendly memory layouts echo the latency discipline behind compiler-scheduled inference accelerators.

03 · Indexing

S2 geometry, Hilbert curves, and urban-canyon map matching

Routing algorithms are useless until real-world latitude and longitude coordinates can be indexed and matched to road geometry at scale. To avoid slow spherical trigonometry during billions of spatial lookups, Google built the S2 Geometry library. S2 projects the curved Earth onto the six faces of a cube and threads a continuous 1D Hilbert space-filling curve across every face, subdividing space from Level 0 hemispheres down to Level 30 cells smaller than a centimeter.

Because Hilbert curves preserve spatial locality—points close in 2D space generally stay close along the 1D curve—nearby intersections, businesses, and live traffic probes collapse into ultra-fast 1D integer range lookups.

Ingesting live telemetry from billions of smartphones introduces another physical headache: GPS multipath errors inside steel-and-glass "urban canyons," where satellite signals bounce off skyscrapers and scatter position estimates across parallel streets. A Map Matching pipeline based on Hidden Markov Models combines raw position pings with velocity, heading, and legal turn topology to snap noisy coordinates onto the single physically coherent road segment—solving a geometric inference problem closely related to acoustic localization from noisy physical sensors.

04 · Forecasting

DeepMind Graph Neural Networks and proactive traffic routing

Knowing how fast cars are moving at the moment of departure still produces wrong ETAs on any trip longer than fifteen minutes, because traffic conditions mutate before a driver reaches the highway bottleneck. In partnership with Google DeepMind, Google Maps transitioned ETA forecasting from static lookup heuristics to Graph Neural Networks (GNNs).

Road traffic is inherently relational: a stalled merge on an off-ramp ripples backward along the expressway and spills onto surface arterials. Google groups strongly correlated road links into Supersegments and feeds live probe speeds alongside time-of-day historical baselines into a GNN architecture. Through iterative message passing between adjacent road segments, the model learns how shockwaves of congestion form, intensify, and dissipate 10 to 50 minutes ahead of real time.

Rather than reacting after a driver hits brake lights, the routing engine updates future edge weights along each leg of the journey before departure—turning planetary navigation from static geometry into continuous spatiotemporal forecasting alongside systems like autonomous maritime routing and large-scale predictive AI.

~/writing/graph·3 backlinks · 4 outgoing

Bidirectional references across the research vault. Hover inline [[wikilinks]] above to preview notes, or inspect this note’s neighborhood in the interactive graph.

Explore in Knowledge Graph
Linked mentions (Backlinks)[3]
Outgoing references & portals[4]

Editorial record

Sources and methodology

This systems analysis connects algorithmic routing fundamentals covered in Veritasium's technical deep dive with Google DeepMind's published research on Graph Neural Networks and the S2 Geometry specification.

  1. 01

    secondary

    Accessed November 16, 2026

  2. 02

    primary

    Accessed November 16, 2026

  3. 03

    primary

    Accessed November 16, 2026