CodingNodes Space play · ←→ step · R restart

The problem

A maps product looks like a picture of the world, but it is really two completely different services wearing one face. One is a rendering service — it turns a coordinate and a zoom level into a tile, fast, for every device that looks at the map. The other is a routing service — it turns two addresses into a sequence of turns, by searching a graph with billions of edges. Confusing the two, or building one to do the other's job, is the mistake this chapter is about avoiding.

We will make the split first, then build each side. The rendering side chops the world into a grid of tiles at a handful of zoom levels, pre-renders them, and serves them from a CDN so a pan is a fetch, not a draw. The routing side models the road network as a weighted graph, finds the fastest path with a best-first search, and re-weights the edges with live traffic so 'fastest' means 'least time right now'. Geocoding sits in front of both, turning a street address into the coordinates the services actually speak. By the end, a 'how do I get there?' has become a search over a graph, and a 'where am I?' has become a fetch of a tile — and we know which service owned each half of that.

Requirements

Functional — what it must do

  • Render: given a coordinate and a zoom level, return the map tiles that cover the viewport, so the user sees a map, not blank space.
  • Route: given a start and a destination, return the fastest path as an ordered list of segments and turns, with an estimated time of arrival.
  • Geocode: turn a human address into coordinates, and the reverse, so the other services can speak in latitude and longitude.

Non-functional — how well it must do it

  • A map pan answers in a few hundred milliseconds from the edge, by fetching pre-rendered tiles rather than drawing the world per request.
  • A route between two cities answers in a second or two, by searching a graph that is far too large to scan — the search must be guided, not exhaustive.
  • The route reflects the world right now: edges are weighted with live traffic, so 'fastest' is 'least travel time at this moment', not 'shortest on paper'.

Scale — how much it must take

  • On the order of billions of road segments, hundreds of millions of geocoded addresses, and tens of thousands of concurrent route requests at peak.

Assumptions — the numbers this design is sized for

A rate limit means nothing without a scale. These are the figures every later part relies on: how much traffic arrives, how much work the limiter has to do per second, and how much latency and memory it may spend doing it.

Road segments
~billions
The edges of the routing graph. Far too many to scan per request — the search must be guided.
Tiles
a handful of zooms
The world is pre-rendered at ~18 zoom levels, each a grid of tiles. Panning is a fetch, not a draw.
Route requests
~10K / s (peak)
Concurrent 'how do I get there' at peak. Each is a guided search over the graph.
Addresses
~hundreds of millions
The geocode database. A lookup by address must be a key, not a scan.
Tile latency
< 300 ms
A viewport fetch from the edge. Pre-rendering is what keeps it under this budget.
Route latency
< 2 s
A cross-city route. A* with a good heuristic keeps it well under this.
Traffic
live, per edge
Speed is recomputed continuously per segment and written to the edge weight.

Takeaways

Part 1

A map is two services

The first decision is the split: a rendering service that turns coordinates into tiles, and a routing service that turns coordinates into a path. They share coordinates as their language, and nothing else.

  1. 1
    Render and route, apart

    Rendering answers 'what does this look like' — a coordinate and a zoom level in, a picture out. Routing answers 'how do I get there' — two coordinates in, a list of turns out. They have different data, different latencies, and different scale profiles, so they are built and scaled separately. The product hides the seam; the architecture must not.

  2. 2
    Why they scale differently

    Rendering is read-heavy and cacheable: the same tile is requested thousands of times and served from the edge, so it scales by adding CDN capacity. Routing is compute-heavy and unique: each request is a different search that cannot be cached the way a tile can, so it scales by adding search capacity. One scales with storage and bandwidth, the other with CPU — and they must not be forced to share a ceiling.

  3. 3
    Coordinates are the contract

    Both services speak the same language: a point is a (latitude, longitude) pair, and a path is a sequence of such pairs. That shared contract is the whole integration. Geocoding sits in front, turning an address into a point, and the rendering and routing services never see a string — only coordinates.

Part 2

Render the world as tiles

The rendering service pre-renders the world into a grid of tiles at each zoom level. A pan is a fetch of a handful of tiles from the CDN, not a draw of the world.

  1. 1
    Chop the world into a grid

    At a given zoom level, the map is a fixed grid of square tiles — the world divided into equal squares. A viewport at any position and zoom covers a small, fixed number of those squares, which is the whole reason tiling works: the amount to fetch is bounded no matter where you are.

  2. 2
    Zoom is a level, not a scale

    Zoom is a discrete level, and each level is its own grid with its own tiles. Zooming in does not scale up the parent tile — it fetches a finer grid. A pan at a level is a horizontal fetch of neighbors; a zoom is a switch to a different grid. That discreteness is what lets every tile be pre-rendered and addressed by a single (zoom, x, y) key.

  3. 3
    Pre-render, then serve from the edge

    The tiles are rendered ahead of time — the world is not drawn per request, it is drawn once and stored. A viewport request fetches the handful of tiles it covers from the CDN, and the CDN serves them from the nearest edge. A pan is therefore a bounded set of edge fetches, and the origin only sees a miss.

Part 3

The road network is a graph

The routing service models the road network as a weighted graph: intersections are nodes, road segments are edges, and the weight of an edge is the time it takes to drive it. A route is a shortest-path search over that graph.

  1. 1
    Nodes, edges, weights

    An intersection is a node. A road segment between two intersections is an edge. The weight of an edge is not its length — it is the time it takes to traverse, which depends on length, speed limit, and, live, on traffic. The routing problem is now pure graph theory: find the minimum-weight path between two nodes.

  2. 2
    Why a scan does not work

    The graph has billions of edges. A search that considered them all for every request would be a full scan per route, and at ten thousand routes a second that is untenable. The escape is a guided search: instead of exploring every edge, the search follows a promise about which edges are likely to lead to the destination, and expands from the most promising one first.

  3. 3
    The search, step by step

    The search starts at your position and keeps a frontier of the edges it has not yet committed to. At each step it picks the frontier edge with the best estimate of total cost — the time so far, plus the estimated remaining time — and expands it. It stops when it reaches the destination, and the path it has built is the fastest one it found.

Part 4

Guide the search with a heuristic

A plain shortest-path search can wander. A heuristic — a cheap estimate of the remaining time — steers the search toward the destination and cuts the edges it must expand to a small fraction of the graph.

  1. 1
    A cost, plus a promise

    The search keeps, for each node, the actual time to get there. A heuristic adds a second number: an estimate of the time from that node to the destination. The node with the smallest sum — actual plus estimate — is expanded next. The estimate does the steering; the actual time does the bookkeeping.

  2. 2
    The heuristic must not lie

    For the search to be correct, the estimate must never overstate the remaining time — it can understate, but never overstate. If it overstated, the search could prune the true fastest path and return a worse one. A straight-line distance scaled by the minimum speed is a safe estimate: it is always a lower bound on the real remaining time.

  3. 3
    Guided, so it is fast

    Because the estimate points the search at the destination, it expands only the edges along and near the true path, not the whole graph. A cross-city route touches a small corridor of the road network rather than the city's billions of edges — and that is what keeps a route under a couple of seconds.

Part 5

Weight the edges with live traffic

The graph is static; the world is not. A continuous feed of speeds per segment is written to the edge weights, so the search's 'time' is the time right now, and a route reroutes when the traffic does.

  1. 1
    Speeds are a live feed

    A fleet of anonymized, consented location reports is aggregated into a current speed for each road segment. That speed is a number that changes every minute, and it is the raw material for the edge weight. The graph's topology is fixed; its weights are a live stream.

  2. 2
    The weight is time, not distance

    The edge weight is the segment's length divided by its current speed. A segment that is one kilometre long but crawling in traffic weighs more than a slightly longer segment flowing freely. The search, which minimizes total weight, therefore minimizes total time — and 'fastest' means 'least time right now'.

  3. 3
    Reroute when the world changes

    Because the weights are live, a route computed at 4:55 is not the route at 5:10. As the driver progresses and the traffic ahead changes, the service recomputes the remaining path against the current weights and, if a better path now exists, sends a reroute. The route is a hypothesis tested continuously, not a fixed answer.

Part 6

Turn addresses into coordinates

Both services speak coordinates, but users type addresses. Geocoding is the translation: a forward lookup turns an address into a point, and a reverse lookup turns a point back into an address.

  1. 1
    Forward: address to point

    The user types '1600 Amphitheatre Parkway'. The geocoder looks that address up in a database of known addresses and returns its coordinates. The lookup is by a normalized key — the address, lowercased and trimmed — not a scan, so it is a hash lookup against hundreds of millions of rows.

  2. 2
    Reverse: point to address

    The other direction takes a coordinate and returns the nearest known address. That is a spatial lookup — find the address whose point is closest to this one — and it is answered from the same grid the tiles use: the point falls in a cell, and the addresses in that cell are the small candidate set.

  3. 3
    The gate in front of both services

    Geocoding is the only piece that sees a string. It sits in front of the rendering and routing services and converts the human input into the coordinate contract they both speak. A route request is really: geocode the start, geocode the destination, then search the graph between the two points.

★ Finale

End to end

One 'how do I get there?': the addresses are geocoded to points, the graph is searched between them with live weights, and the route is drawn on tiles fetched from the edge.

  1. 1
    The whole system

    Every piece in one frame. The user's addresses are geocoded to coordinates; the routing service searches the weighted graph between them and returns a path with an ETA; the rendering service fetches the tiles that cover the route and the viewport; and a live speed feed keeps the weights — and the ETA — current.

  2. 2
    Geocode, then search

    The user asks for a route between two addresses. The geocoder turns each into a point, and the routing service searches the weighted graph between the two points — guided by the heuristic, weighted by the live speeds — and returns the fastest path with its total time. The string has become a coordinate, and the coordinate has become a path.

  3. 3
    Drawn on tiles, from the edge

    The route's points are handed to the rendering service, which resolves them to the tiles that cover the route and the viewport. Those tiles are fetched from the CDN, and the route is drawn on top of them. The picture and the path come from two different services, but the user sees one map with one route on it.

  4. 4
    Live, and honest about time

    As the driver moves, the live speed feed keeps rewriting the edge weights, and the routing service recomputes the remaining path against them — rerouting if the traffic makes a different path faster. The ETA is not a prediction frozen at the start; it is a running estimate, and the route is a hypothesis the world keeps testing.

🌐 In the wild

In the wild

The render/route split is the backbone of every major maps product. The boxes below are anchored to the classes of well-known systems that run each piece — an illustrative mapping, not a claim about any one product's internals.

  1. 1
    The pattern, piece by piece

    Each box is a standard building block of a maps and routing service. Anchoring them to the classes of production systems that run that piece turns the abstract design into 'the shape behind every turn-by-turn you've followed'.

  2. 2
    Why the same split keeps winning

    Independent maps products converge on the same split because each piece removes a real cost: tiling removes the per-request draw, the heuristic removes the full-graph scan, the live weights remove the 'static route is wrong' failure, geocoding removes the string-vs-coordinate mismatch, and the CDN removes origin load. That convergence is the evidence the design is load-bearing.