SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
  • Design Ride Sharing (Uber/Lyft)
  • Design a Payment System
  • Design Ticket / Hotel Booking
  • Design a Search Engine
  • Design Google Maps
  • Design a Collaborative Editor (Google Docs)
  • Design a Metrics and Monitoring System
  • Design a Distributed Message Queue (Kafka-like)
  • Design an E-commerce System (Amazon)
  • Design a Content Recommendation System (YouTube/Netflix)
System Design/Case Studies/Hard
Interview case study

Design Google Maps

Show a map, find the fastest route and estimate arrival time for a whole planet of roads.

⏱ 38 min readHard case studyAdvanced26 cross-questionsHas visualizer
Prompt60-sec answer45-min plan1 Clarify2 Estimate3 API + Data4 Design5 Deep dives6 Scale7 Wrap upCross-questionsVariationsScoringMistakesCheat-sheet

StartThe prompt and what is really being tested

The interviewer says

“Design Google Maps.”

It is short on purpose. Your first job is to make it specific.

What they checkWhy it matters
Splitting a huge product into services“Maps” is at least four systems: drawing the map, finding a place, finding a route, and live traffic. A strong candidate names them, draws the line between them, and picks the one to go deep on.
Thinking in tiles, not in picturesA planet cannot be sent to a phone. The interviewer wants to hear about a pyramid of tiles, what each zoom level costs, and why a CDN does almost all of the work.
Knowing why Dijkstra is not enoughEveryone can say “shortest path”. A senior candidate knows that plain Dijkstra on a whole continent takes seconds, and that the real answer is preprocessing the graph.
Live data versus precomputed dataPreprocessing makes queries fast but goes stale when traffic changes. How you keep both ideas is the heart of the problem.
Privacy and honest accuracyTraffic comes from people’s phones. The interviewer wants aggregation, anonymity and an ETA you can measure, not a number made up from distance.

TL;DRThe whole design in 60 seconds

Google Maps is four systems that share one map. Tiles draw the map: the world is cut into a pyramid of small vector tiles, pre-built in batch, stored in object storage and served almost entirely by a CDN. Search turns text into a place. Routing finds the fastest path on a road graph that is preprocessed so a query takes milliseconds. Traffic turns phone location pings into live speeds on every road segment, which routing uses for its costs and its ETA.

  • Scale: 15 billion tile requests a day is about 174,000 a second and 520,000 at peak. A 97% CDN hit ratio leaves about 15,600 a second for the origin. Routing is only 1,850 a second on average. Tiles are the traffic, routing is the hard part.
  • Tiles: zoom level z has 4^z tiles. Build the low zooms for the whole world, build the high zooms only where there are roads. Vector tiles are small (about 10 KB) and the phone draws them.
  • Routing: the road graph is 500 million nodes and a billion edges, about 32 GB, so it fits in memory. Dijkstra would look at tens of millions of nodes for a long trip. We preprocess with contraction hierarchies, so a query looks at a few thousand.
  • Live traffic: phone pings are snapped to roads (map matching), averaged per road segment per minute, and blended with a typical speed for that hour of the week. Fast preprocessing methods let us recompute costs without redoing the whole structure.
  • Navigation: the phone follows the route and asks again only when it leaves it or when traffic changes a lot. We do not stream a route to a million drivers.
  • Privacy: aggregate and drop trip starts and ends. A road segment’s speed is published only when enough different phones contributed.
💡How to use this page
Read the 60-second answer first. Then work through steps 1 to 7 in order, and try each step yourself before reading the model answer. Finish with the cross-questions: say your answer out loud, then open the model one.

PlanA 45-minute plan

4
3
5
8
16
6
3
Minutes per step (total 45). A guide, not a rule: move time to the part the interviewer cares about.
StepMinutesWhat to get done
1. Clarify4Which parts of Maps: display, search, driving routes, live ETA, rerouting. What is out: walking, transit, offline, street view.
2. Estimate3Tile requests and egress, graph size in memory, route queries, and traffic pings.
3. API and data5Tile, geocode, route and probe calls, and the road graph, tile and traffic data models.
4. High-level design8A build pipeline, a tile path through the CDN, a routing service, a traffic pipeline.
5. Deep dives16Tiles, then fast routing, then live traffic and ETA, then search, then navigation and rollout.
6. Scale and failures6A CDN miss storm, a routing node down, missing traffic data, a map update mid-trip.
7. Wrap up3Recap, the preprocessing trade-off, and what you would build next.

Step 1Clarify requirementsabout 4 min

🤔
Pause. Try it yourself first
You have 60 seconds. Write five questions that would change your design. Hint: what does “Maps” include, which vehicles, how fresh is traffic, and does it work offline?

Questions to ask, and why

AskWhy you ask itTypical answerHow it changes the design
Which features are in scope: showing the map, searching a place, routes, live traffic, turn-by-turn?Maps is a family of products. Without a boundary we will draw thirty boxes and go deep on none.Display the map, search a place, driving routes with an ETA that uses live traffic, and turn-by-turn with rerouting.Four subsystems: tiles, geocoding, routing and traffic. Navigation sits on top of routing.
Driving only, or also walking, cycling and public transport?Each mode is its own graph with its own costs. Transit adds timetables, which is a different problem.Driving. Mention that other modes reuse the same design with another graph and cost function.One road graph, one cost function (travel time for a car). We name the extension.
How live must traffic be?It sets whether we need a stream pipeline or a batch job, and how often costs change.Speeds refreshed about every minute, and ETAs that reflect them.A streaming pipeline with one-minute windows, and routing that accepts changing costs.
How many users, and how many are navigating at once?Map browsing, search and navigation have very different loads.100 million daily users who open the map about 10 times a day. 40 million of them navigate, for about 25 minutes.Tile traffic is huge and cacheable. Routing is modest. Probes come only from people who are navigating.
How big is the map, and how often does it change?It decides storage, the build pipeline and how we roll out a new version.Hundreds of millions of road junctions. The base map changes weekly. Closures and incidents change within minutes.A batch rebuild for the base map and a separate fast path for incidents.
Do we need offline maps?Offline means downloading regions and routing on the phone.Out of scope. Mention it as an extension.We skip on-device routing, and design the phone as a thin client of tile and route services.
How accurate must the ETA be?A target we can measure turns “good enough” into a number.Typically within 10% for trips under an hour. We track it.We log predicted versus actual trip times and use them to tune.
Do we care about privacy of location data?Traffic comes from individual phones. A design that stores everyone’s path is a liability.Yes. Traffic must be anonymous and aggregated.Probes are stripped of identity, trip ends are trimmed, and speeds are published only above a minimum count.
One region or global? What availability?A global map is served from many regions, but a route crosses borders and data regions.Global, 99.95% for tiles and routing, with regional data owners.CDN everywhere, regional routing clusters, and a global graph partitioned across regions.

Write the scope on the board

Functional (must do)
  • •Show a map at any zoom level and pan smoothly (tiles)
  • •Search for a place or address, and turn a point into an address (geocoding)
  • •Find the fastest driving route between two places, with steps
  • •Give an ETA that reflects live traffic, and update it along the way
  • •Guide the driver turn by turn and reroute when they leave the route
Non-functional (how well)
  • •Tiles: 99.95% available, first tiles in under 200 ms for most users (served by a CDN)
  • •Routes: a typical answer in under 500 ms, and a continental route in about 1 second
  • •Traffic: speeds refreshed about every minute
  • •Scale: 15 billion tile requests a day, about 5,600 route queries a second at peak
  • •Privacy: no stored personal trip history in the traffic system, aggregates only
Out of scope (say it)
  • •Walking, cycling and transit routing
  • •Offline maps and on-device routing
  • •Street-level imagery, 3D buildings and satellite imagery
  • •Business reviews, photos and ads
🎤
Say it out loud
“Let me confirm the scope. We show the map, search a place, find driving routes with an ETA that reflects live traffic, and guide turn by turn with rerouting. Walking, transit and offline maps are out. I will design for 100 million daily users who open the map about ten times a day, and 40 million of them navigating for about 25 minutes. Traffic speeds refresh about every minute and must be anonymous and aggregated. I will treat it as four services that share a map: tiles, search, routing and traffic, and go deepest on routing. Does that match?”

Step 2Estimate the scaleabout 3 min

🤔
Pause. Try it yourself first
On paper: how many tile requests, how much egress, how big is the road graph in memory, how many route queries, and how many location pings from phones?

Assumptions (say them first)

AssumptionValue
Daily users100 million, each opens the map about 10 times a day
Tiles per map viewabout 15 (a screen plus a border), average 10 KB each (vector)
CDN hit ratio97% for tiles
Peak versus averageabout 3 times
Road graph500 million nodes, 1 billion edges (illustrative)
Graph bytesabout 24 bytes per edge and 16 per node
Navigating users40 million a day, about 25 minutes each, 4 route queries a trip (start, reroutes)
Location pingone every 5 seconds from a navigating phone, about 100 bytes
One route query on a preprocessed graphabout 5 ms of one CPU core (assumption)
Plain Dijkstra on a long tripabout 100 million nodes at about 20 million a second, so 5 s (assumption)
Place searches3 per user per day

The arithmetic, line by line

WhatMathsResult
Tile requests per day100,000,000 × 10 views × 15 tiles15 billion per day
Tile requests per second15,000,000,000 ÷ 86,400, and × 3 at peakabout 174,000 per second, 520,000 at peak
Origin requests at a 97% hit ratio520,000 × 3%, and 174,000 × 3%about 15,600 at peak, 5,200 on average
The same at a 90% hit ratio174,000 × 10%about 17,400 on average (3.3 times more)
Tile egress15,000,000,000 × 10 KB150 TB per day, about 14 Gbps average, 42 Gbps at peak
Tiles in the pyramid (all of it, to zoom 18)(4^19 − 1) ÷ 3about 91.6 billion, which is too many to store densely
What we actually storezoom 0 to 14 in full: (4^15 − 1) ÷ 3 = 358 million; zoom 15 to 18 where there are roads, 3% of tiles = 2.7 billionabout 3.1 billion tiles × 10 KB = 31 TB per map version
Road graph in memory1,000,000,000 edges × 24 B + 500,000,000 nodes × 16 B24 GB + 8 GB = 32 GB (about 56 GB with shortcuts)
Route queries40,000,000 × 4 per day, then ÷ 86,400, × 3 at peak160 million a day, 1,850 per second, 5,560 at peak
CPU for routing at peak5,560 × 5 ms, and the plain way 5,560 × 5 sabout 28 cores busy (about 56 at half utilisation) against about 27,800 cores
Concurrent navigators40,000,000 × 25 min ÷ 1,440 min per day, × 3 at peakabout 694,000 on average, 2.1 million at peak
Location pings2,083,000 ÷ 5 s, and × 100 Babout 417,000 per second at peak, about 42 MB per second
Map matching CPU417,000 per second × about 200 microsecondsabout 83 cores busy at peak (about 170 at half utilisation)
Place searches100,000,000 × 3 ÷ 86,400, × 3 at peakabout 3,500 per second, 10,400 at peak
What the numbers tell us about the design
  • •Tiles are the traffic: 174,000 a second. The only way this works is a CDN with a very high hit ratio. At 90% the origin sees over three times the load, so the hit ratio is a design goal, not a detail.
  • •The pyramid has 91.6 billion tiles to zoom 18, but we store about 3.1 billion by filling the low zooms in full and the high zooms only where there are roads. A dense zoom 21 would be 4.4 trillion tiles.
  • •The road graph is only 32 GB, so one machine holds a whole region in memory. Routing is a compute problem, not a storage problem.
  • •Plain Dijkstra would need about 27,800 cores for routing at peak. Preprocessing brings that to about 28. That 1,000-times gap is the reason the interview question exists.
  • •Location pings are 417,000 a second at peak, but only 42 MB a second. Map matching, not bandwidth, is the cost: about 170 cores.
🎤
Say it out loud
“Let me do the maths. A hundred million daily users opening the map ten times, fifteen tiles each, is 15 billion tile requests a day, about 174,000 a second and half a million at peak. That is 150 terabytes a day, so a CDN has to serve at least 97% of it. The pyramid is 4 to the power of z tiles per zoom level, so to zoom 18 it is 91 billion tiles. We store about 3 billion by building the low zooms in full and the high zooms only where there are roads. The road graph is 500 million nodes and a billion edges, about 32 gigabytes, so it fits in memory. Plain Dijkstra would take seconds per long route and 28,000 cores at peak. With preprocessing, a query is about 5 milliseconds and 28 cores.”

Step 3Define the API and the data modelabout 5 min

🤔
Pause. Try it yourself first
Write the four calls a phone makes: a tile, a search, a route, and a location ping. Which ones can a CDN answer, and which carry a user’s private data?

Endpoints

MethodPathRequestResponseNotes
GET/tiles/{version}/{z}/{x}/{y}.pbfnone200 vector tile (compressed)Versioned path, so it can be cached for a long time and a new map is a new path. Never personal. Served by the CDN, with the origin as a fallback.
GET/v1/search?q=&near=&limit=none200 { places: [{ id, name, address, lat, lon, score }] }Text plus a location bias. Cached for common queries. Returns candidates, not a route.
GET/v1/geocode/reverse?lat=&lon=none200 { address, placeId }A point to an address. Safe to cache by rounded coordinates.
POST/v1/route{ origin, destination, mode: "drive", departAt?, avoid? }200 { routes: [{ distance, etaSeconds, polyline, steps, mapVersion }] }The polyline is encoded to save bytes. mapVersion lets the client check that the drawn roads match the route. Returns up to 3 alternatives.
POST/v1/probes{ batch: [{ t, lat, lon, speed, heading, accuracy }] }202Anonymous, batched on the phone and sent every few seconds. No account id, and a rotating random session id that changes every few minutes.
WS/v1/navigate{ routeId, position }events: reroute, incident, new ETAOptional stream for turn-by-turn updates. A phone that is on its route sends nothing, and the server stays quiet.

Data model

Road graph (in memory, per region)FieldsWhy it is there
Node (junction)id, lat, lon, levelA point where roads meet. level is its importance after preprocessing.
Edge (road segment, one direction)from, to, length, class, speed limit, base time, profile idThe unit routing and traffic work on. Two-way roads are two edges.
Turn restrictionfrom edge, to edge, forbidden or costNo left turn here, a U-turn costs 20 s.
Shortcutfrom, to, cost, via nodeAdded by preprocessing. Standing for a whole stretch of road.
Other storesKeyValue
Tiles (object storage)version / z / x / yA compressed vector tile. Immutable. A new map is a new version.
Live traffic (fast key-value)edge idspeed now, sample count, updated at. About 8 bytes per edge.
Typical speeds (read-only table)profile id × 168 hours of the weekA typical speed. About 11 MB for 65,536 profiles.
Place indexword + cellPlace ids with a text and distance score.
How an edge cost is made
cost(edge, t) = length / speed(edge, t) + turn_delay(edge)

speed(edge, t) =  live       if samples(edge) >= MIN_SAMPLES and fresh
                  typical    otherwise: typical[edge.profile][hour_of_week(t)]
                  (blend towards typical as the live reading gets old)
📝Which store, and why
Tiles are immutable blobs read by key, so object storage behind a CDN. The road graph is read-mostly and needs random access with no disk in the hot path, so it is built offline into a compact binary file and loaded into memory on each routing node. Live traffic is a tiny value per edge that changes every minute, so a fast key-value store or memory on the routing nodes. Places need text search plus a location filter, so an inverted index with spatial cells (for example Elasticsearch-style).
🎤
Say it out loud
“Four calls matter. A tile is a GET on a versioned path, so a CDN can cache it for a long time. Search takes text and a location bias. Route is a POST with an origin and destination, and returns a polyline, an ETA and a map version so the phone can check the drawn roads match. And phones send anonymous batched probes, with no account id and a session id that rotates. For data, tiles are blobs in object storage. The road graph is a compact binary file in memory on each routing node, with edges that carry length, class and a typical-speed profile. Live speeds are about 8 bytes per edge in a fast store.”

Step 4Draw the high-level designabout 8 min

🤔
Pause. Try it yourself first
Draw one path for what the user sees (tiles), one for a route query, and one for the data that flows back from phones. Where does the CDN sit? What is built in advance, and what is live?
Google Maps: high-level design
📱Phonedraws vector tiles
→↓tiles
🌍CDN97% of tile requests
→↓miss
🪣Tile storeobject storage, versioned
Build pipeline (batch)
🗺️Map dataroads, places, imagery
🧱Tile buildervector tiles per zoom
🧮Graph builderroad graph + shortcuts
Query services
🔎Search serviceplaces, geocoding
🧭Routing servicegraph in memory per region
⏱️ETA serviceroute + live speeds
Traffic pipeline (stream)
📍Probe intakeanonymous batches
📨StreamKafka-like log
🧷Map matchingsnap GPS to roads
📊Speed aggregatorper edge per minute
Navigation
🔔Reroute servicepush changes
🗃️Live speed storeedge id → speed
Top: the map is built in batch and served by a CDN. Middle: routing runs on a preprocessed in-memory graph. Bottom: phone pings become live speeds that routing reads.
ComponentWhat it does
Build pipelineCleans and merges map data in batch, builds the versioned tile pyramid, and builds the road graph and its shortcuts. A new map is a new version, never an edit in place.
Tile store and CDNImmutable tiles in object storage, served through a CDN with long cache lives. The CDN absorbs about 97% of requests.
Search serviceTurns text into places with an inverted index and a spatial filter, and a point into an address (reverse geocoding).
Routing serviceHolds a region of the road graph in memory and answers route queries with preprocessed shortcuts. Stateless, so we run many copies.
ETA serviceAdds up edge times along a route, using live speeds where they exist and typical speeds where they do not.
Probe intake and streamAccepts anonymous batches from phones and writes them to a durable log, so a slow consumer never loses data.
Map matching and speed aggregatorSnaps noisy GPS points to road edges, then computes a robust speed per edge per minute and writes it to the live speed store.
Reroute serviceWatches live speeds and incidents on the routes of active navigators and tells a phone when a much better route exists.
Write path (follow one request)
  1. A phone sends a batch of probes: time, position, speed and heading, with a rotating session id and no account.
  2. Probe intake validates and drops bad points, then appends the batch to a partitioned log, keyed by a map cell.
  3. Map matching reads the log and snaps each point to the most likely road edge, using the previous points to resolve ambiguity.
  4. The speed aggregator groups matched points by edge and minute, drops outliers, and keeps the median.
  5. An edge is published only if enough different sessions contributed (a minimum count). The speed goes to the live speed store.
  6. Routing nodes read the new speeds, and the reroute service checks whether any active route got much slower.
Read path (follow one request)
  1. The phone asks for tiles by version, zoom, x and y, and draws the vector data itself.
  2. The CDN answers almost every tile. On a miss it fetches from the tile store and keeps the tile.
  3. The user searches for a place. The search service returns candidates, biased towards the map centre.
  4. The phone sends origin and destination to the routing service in its region.
  5. Routing runs a query on the preprocessed graph with current edge costs, and returns up to three routes with a polyline and steps.
  6. The ETA service adds edge times along each route, using live speeds blended with typical ones.
  7. While navigating the phone follows the route locally, and the reroute service pushes a new route only when it is needed.
🎤
Say it out loud
“Here is the picture. A build pipeline turns map data into a versioned tile pyramid in object storage, and into a road graph with shortcuts. The phone gets tiles from a CDN that serves about 97% of requests. Search turns text into a place. A routing service holds a region of the graph in memory and answers a query in milliseconds. Behind it, phones send anonymous probes to a stream, map matching snaps them to roads, and an aggregator writes a speed per road per minute that routing and ETA read. A reroute service tells a phone only when its route got much worse.”

Step 5Deep dive into the hard partsabout 16 min

🧠The pattern for every deep dive
Problem → options → pick one → say why → say what it costs. Interviewers score the reasoning more than the choice.
5.1

Map tiles: a pyramid of small, cacheable pieces

The problem: The map must look sharp at every zoom, load in a blink, and be served to 100 million people a day. The planet cannot be one image, and storing every zoom level densely is impossible.

OptionHow it worksGoodBad
One big pre-rendered image per zoomRender the world at each zoom and send the part in view.Simple to think about.Enormous files, no caching of parts, and it cannot be updated locally.
Raster tiles (small pictures)Cut each zoom into 256 by 256 pixel PNG or JPEG tiles, addressed by z, x, y.Easy for any client. Cacheable.Larger (20 to 50 KB), fixed style, blurry when scaled, and a style change means rebuilding everything.
Vector tiles (the data, drawn on the phone)Each tile holds roads, water and labels as shapes. The phone draws them in the chosen style.Small (about 10 KB), sharp at any scale, rotation and styling for free, and smooth zoom between levels.The phone does the drawing, so older devices need care. A font and style pipeline.
Render on demand for everythingDraw a tile when it is first asked for, then cache it.Stores nothing that nobody looks at.A cold miss is slow, and a launch day with no warm cache would overwhelm the renderers.
Pick
Vector tiles on a versioned pyramid: build zoom 0 to 14 in full, build zoom 15 and deeper only where there is data, and serve everything through a CDN

Zoom level z has 4^z tiles. Zoom 0 is one tile for the world, zoom 10 is about a million, zoom 14 is 268 million and zoom 18 is 68.7 billion. The whole pyramid to zoom 18 is 91.6 billion tiles, so we do not store it all: the ocean and the desert are empty at deep zooms. The low zooms (0 to 14, 358 million tiles) are built in full, and zooms 15 to 18 only where there are roads and buildings, about 3% of tiles, so about 3.1 billion tiles in total, around 31 TB per version at 10 KB each.

A tile is addressed by version/z/x/y. The version is part of the path, so a tile can be cached for a very long time, and a new map is simply a new path. The CDN serves 97% of requests, and the rest go to the tile store. A phone loads about 15 tiles for a screen. It asks for the neighbours it will need next, so panning feels instant.

ZoomTiles at this zoomOne tile is aboutWhat you see
0140,000 km wideThe whole world
101,048,57639 km wideA city and its region
14268,435,4562.4 km wideA neighbourhood
1868,719,476,736153 m wide (at the equator)A few streets
214,398,046,511,10419 m wideA building (only where needed)
From a place to a tile (web-mercator tiling, simplified)
n = 2^z
x = floor( (lon + 180) / 360 * n )
y = floor( (1 - ln(tan(lat) + 1/cos(lat)) / pi) / 2 * n )

London (51.5074, -0.1278):  z10 -> tile (511, 340)   z14 -> tile (8186, 5448)
parent of (z, x, y)  =  (z-1, x/2, y/2)      children = (z+1, 2x..2x+1, 2y..2y+1)
💡Updating the map
A road changes: rebuild only the tiles that contain it (and its parents at lower zooms), publish them under a new version, and let the old ones expire. A diff of changed tiles is tiny compared with the whole planet.
🎤
Say it out loud
“Zoom level z has 4 to the z tiles, so the pyramid to zoom 18 is 91 billion. I store about 3 billion: the low zooms in full, the high zooms only where there are roads. Tiles are vector, about 10 kilobytes, drawn on the phone, so they are sharp at any scale and cheap to send. The path includes a version, so a CDN can cache a tile for a long time and a map update is just a new path. A CDN with 97% hit ratio takes 520,000 requests a second at peak down to about 15,000 at the origin.”
5.2

Shortest path at continental scale

The problem: A route is a shortest-path problem on a graph with 500 million nodes. Dijkstra’s algorithm explores a growing circle around the start, and for a long trip that circle swallows most of a continent. We need an answer in milliseconds, for 5,000 queries a second.

OptionHow it worksGoodBad
DijkstraGrow a circle of nodes around the start in order of distance until the target is reached.Simple and always correct. Reads live costs directly.Looks at tens of millions of nodes for a long trip: about 5 seconds each, so about 28,000 cores at peak.
A* and bidirectional searchA* adds a guess of the distance left. Bidirectional search runs from both ends and meets in the middle.Fewer nodes (often a few times fewer). Still no preprocessing, so live costs just work.Still thousands of times too slow for a continent. The guess is weak on roads, where the fastest route is rarely straight.
Contraction hierarchies (preprocessing)Rank the nodes by importance. Remove the least important first, adding a shortcut edge where its removal would lengthen a shortest path. A query searches only upward in importance from both ends.A query looks at a few thousand nodes, so milliseconds. About 1,000 times fewer cores.Preprocessing takes time and memory (about 24 GB more here). A change in costs makes the shortcuts stale.
Partition the graph into cells (customizable route planning)Cut the map into nested regions, precompute only the structure (not the costs), and compute costs for border-to-border links quickly. A query searches the local cell in detail and the rest through the border links.A cost change is a fast re-customisation (seconds), not a full rebuild. Live traffic fits.A query is a little slower than the best hierarchy. More moving parts.
Pick
A preprocessed hierarchy for the structure, with a fast re-customisation of the costs when traffic changes

The key idea is shortcuts. Most long trips use the highway network: the same few important roads. If we precompute that a stretch of important roads costs, say, 40 minutes from junction X to junction Y, a query can jump over it instead of exploring every side street. A contraction hierarchy does this systematically, and a query only ever climbs up the hierarchy from the start and from the end until the two climbs meet. Instead of looking at 100 million nodes, it looks at a few thousand. Our estimate: about 5 ms per query instead of about 5 s, so about 28 cores instead of about 28,000.

The cost is that shortcuts store costs. When an accident makes one highway segment 40 times slower, every shortcut that passes over it is now wrong. The fix is to separate structure (which shortcuts exist, built rarely, in hours) from costs (recomputed often, in seconds). Methods such as customizable route planning are built around that split. Try it in the playground: with stale shortcuts the search finds a route fast but it is not the best one.

MethodLooks at (long trip)PreprocessingHandles live traffic?
Dijkstratens of millions of nodesnoneYes, directly
A* / bidirectionala few times fewernoneYes, directly
Contraction hierarchya few thousandhours, plus 24 GBOnly after a rebuild
Partitioned cells, re-customiseda few thousand to tens of thousandsstructure once, costs in secondsYes, after a fast re-customise
📝The shortcut in one picture
Removing a side-street junction is safe if the shortest path through it is also the shortest path some other way. If not, we add a shortcut that stands in for it. After many such removals, only the important roads remain, and shortcuts connect them.
⚠️What the playground shows
Plain Dijkstra, A* and two-ended search always find the true best route on today’s roads. The shortcut search is the fastest, but when the shortcuts were built before an accident it can return a slower route. Re-customising fixes it.
🎤
Say it out loud
“Dijkstra on 500 million nodes looks at tens of millions for a long trip, about five seconds, and at peak that is about 28,000 cores. A* and searching from both ends help a few times, not a thousand. The real answer is preprocessing: a contraction hierarchy ranks junctions by importance and adds shortcuts, so a query climbs up from both ends and looks at a few thousand nodes, about five milliseconds. The cost is that shortcuts store costs and go stale when traffic changes, so I separate the structure, built rarely, from the costs, which I recompute in seconds.”
5.3

Live traffic, map matching and ETA

The problem: A route is only as good as the speeds under it. Phones give us noisy points, not road speeds, and we must turn them into a number per road segment per minute, protect privacy, and still produce an ETA that is right.

OptionHow it worksGoodBad
Static speed limitsTime = length ÷ speed limit.No data pipeline.Wrong in every city at rush hour. ETAs are far too optimistic.
Typical speeds by hour of weekA table per road: its normal speed for each of the 168 hours of the week.Captures rush hour and weekends, and it is cheap and always available.Blind to today’s accident or event.
Live speeds from phone probesSnap pings to roads, take the median speed per segment per minute.Reflects what is happening now.Needs enough phones on a road. Noisy. Empty on quiet roads.
Blend: live when there is enough, typical otherwise, with prediction for the near futureUse live speed above a minimum sample count, fade back to typical as the reading ages, and project a few minutes ahead.Good coverage, sharp where it matters, and honest when data is thin.More logic, and a model to tune and measure.
Pick
The blend, with a minimum sample count before any live speed is published

Every road segment gets a speed for the next minutes from three sources: the live median (if at least a minimum number of different phones contributed), the typical speed for that road at that hour of the week, and a short projection. As a live reading gets old, the answer slides back toward typical, so a road with no recent data is never treated as empty or as frozen.

The ETA is the sum of edge times along the route, plus a delay at junctions and traffic lights. For a long trip, speeds an hour away are predicted, not live, so the ETA service uses typical speeds for the far part and live speeds for the near part. We measure ETA error as predicted versus actual trip time and tune against it.

StepWhat happensWhy
Anonymise on the phoneA random session id that changes every few minutes. No account id.A long trace identifies a person (it ends at their home).
Trim trip endsDrop the first and last stretch of each trip.Starts and ends are the most revealing.
Map matchingChoose the most likely sequence of road edges for the points (a hidden-Markov-model idea: near the point, plausible to drive between the points).A GPS point is up to tens of metres off, and two roads can be 20 m apart.
AggregateMedian speed per edge per minute, outliers dropped, count of different sessions.A robust number that one slow car cannot move.
Publish if k is metOnly publish an edge if at least k different sessions contributed.A speed from one phone is that phone’s location.
Blend with typicalFade from live to typical as the reading ages.Quiet roads must still have an answer.
💡A late probe
A phone loses signal in a tunnel and sends its points two minutes late. Aggregation uses event time with a short allowed lateness, and a very late point is dropped. A stream engine handles this for us.
🎤
Say it out loud
“Static speed limits are wrong at rush hour. So every road gets three things: a typical speed for each hour of the week, a live median speed from phones if enough different phones contributed, and a short projection. As a live reading ages it fades back to typical. Phones are anonymised on the device, trip ends are trimmed, GPS points are snapped to roads with map matching, and a speed is published only above a minimum number of sessions. ETA is the sum of edge times plus junction delays, and I measure predicted against actual trip time.”
5.4

Search: from words to a place

The problem: A user types “springfield” or “coffee near me” or a half address. We must turn text into a place, rank it well, and also turn a point on the map into an address.

OptionHow it worksGoodBad
A database LIKE queryWHERE name LIKE '%text%'.Trivial.A full scan, no typo handling, no ranking by distance.
Text index onlyAn inverted index of words and normalised addresses, ranked by text match.Fast and ranks by relevance.“Springfield” returns every Springfield in the world, in random order.
Text index plus a spatial filter and popularityFind matches by text, filter or boost by distance from the map centre and the user, and weight by how often people choose a place.Sensible answers: the Springfield near you first.More signals to tune. Needs a place popularity feed.
Reverse geocoding with a spatial indexPoint-in-polygon on an R-tree or a cell index to find the street, district and city for a point.Fast, exact for areas.Needs good polygons. Boundaries change.
Pick
An inverted index with spatial cells, ranked by text, distance and popularity, and a cell index for reverse geocoding

Place search is an inverted index (see Inverted Index) where each posting also carries a cell id (see S2 and H3). A query is parsed and normalised (“St” and “Street”, accents, order of address parts). Candidates are found by text, then ranked by a blend of text match, distance from the map centre, and popularity. That is why “springfield” returns the one nearest to the user’s map view first.

Reverse geocoding works the other way: find the cell of the point, then check which stored polygons (district, city, postcode) and which nearest road contain it. An R-tree makes the polygon check fast (see R-Trees). Autocomplete uses the same ideas with a prefix structure (see Design Search Autocomplete).

🎤
Say it out loud
“A LIKE query scans everything, and a text-only index returns every Springfield in the world. So I use an inverted index where each place also carries a spatial cell, and rank by text match, distance from the map centre and popularity. The nearby Springfield wins. Reverse geocoding is the opposite: find the cell, then check which polygons and nearest road contain the point, using an R-tree. Autocomplete reuses the same index with prefixes.”
5.5

Navigation, rerouting and rolling out a new map

The problem: A million people are driving at once. Each needs to be told when to turn, and some need a new route, without the server doing work for every GPS point. And a map update must not make the drawn road disagree with the route.

OptionHow it worksGoodBad
Server follows every driverThe phone streams position and the server decides the next instruction.Simple client, always up to date.About 417,000 messages a second at peak that need a stateful answer, and it breaks in a tunnel.
Phone follows the route locallyThe server sends the route and its steps. The phone matches its position to the route and speaks the next turn.Works offline for a while, no per-GPS server cost.The phone must be told when something changes.
Phone follows locally, server pushes changesThe server keeps a light record of each active route and sends an event when an incident or a traffic change makes a much better route.Quiet when nothing changes, and it still reacts to traffic.Needs a way to find active routes affected by a change.
Poll for a new route every minuteThe phone asks again at a fixed interval.Simple.Wasteful, and still late when something happens.
Pick
The phone follows the route locally and sends a reroute request only if it leaves the route. The server pushes a change when a much better route exists

The route is a list of road edges and steps, so the phone can tell where it is on it without help. It asks for a new route only if it is off the route for more than a few seconds. On the server, an index from edge to active routes lets us find the few routes that include an edge whose speed just changed. We recompute only those, and push a new route only if it saves more than a threshold (for example 2 minutes or 10%), so people are not nagged.

For a new map version, a route carries the mapVersion it was computed on. Tiles are fetched for the same version, so the line is always drawn on the roads it was built from. We roll out by region, keep the old version live until active routes finish, and only then retire it.

🎤
Say it out loud
“The phone follows the route locally, because the route is just a list of road edges and steps, so there is no server work per GPS point. The phone asks for a new route only if it leaves the route. On the server I keep an index from edge to active routes, so when a speed changes I recompute only the affected routes, and push a new route only if it saves a meaningful amount. For map updates, every route carries the map version it was built on, and tiles come from the same version, so the drawn roads always match.”
VisualizerFour ways to find a route, and why shortcuts go stalePick a trip and a search. Watch how many nodes each one looks at. Then add an accident and switch to “With shortcuts”: it is fastest but wrong until you re-customise.
How do we search?
Which trip?
Live traffic
AB
━ highway (enter at the ringed ramps)╍ slow street⋯ closed street━ accident━ route found● looked at
Nodes looked at
96
of 96
Route time today
12.0 min
the true best
Best possible
12.0 min
plain Dijkstra
Shortcuts added
n/a
this search builds none
Dijkstra grows a circle of "settled" nodes around the start until it reaches the end: 96 nodes for a 12.0 min route. It reads today's road costs, so it is always right. The cost is that it looks in every direction.
The four searches on the same trip
SearchNodes looked atRoute time todayBest?
Dijkstra9612.0 minyes
A* (aim at the target)5312.0 minyes
Search from both ends4512.0 minyes
With shortcuts2412.0 minyes

A simplified model with fixed numbers and no random values: 96 junctions, a local street takes 60 s, a highway hop 20 s, a slow street 150 s, and an accident makes one segment 40 times slower. The shortcuts are a real (small) contraction hierarchy: nodes are removed one by one and replaced by links that keep the distances. A real map has hundreds of millions of nodes, where looking at a few thousand instead of a hundred million is what makes a route take milliseconds.

Step 6Scale, bottlenecks and failuresabout 6 min

🤔
Pause. Try it yourself first
Run the day. What if the CDN loses half its cache? What if a routing node dies? What if the traffic feed stops? What if the map is updated in the middle of someone’s trip?

What breaks first, and the fix

BottleneckFix
CDN miss storm after a new map version (every tile is a miss)Pre-warm the most visited tiles in each region before switching, roll out by region, and use an origin shield so many edge misses become one origin request.
Origin tile store under a cold cacheCache in front of object storage, request coalescing, and a long cache life on versioned paths.
Routing CPU at the morning peak (5,560 queries a second)Preprocessed hierarchy, many stateless copies of each region, and a short cache of very popular origin and destination pairs.
A very long route crosses several regionsA coordinator breaks it at the border nodes, queries each region, and joins the results using precomputed border-to-border costs.
Probe stream spikes (417,000 a second at peak)Partition the log by map cell, scale map matching with the partitions, and drop the lowest-value points under overload.
Hot places in search (a stadium after a match)Cache popular queries for a few seconds and spread the shards by cell so one event is not one shard.
Reroute thundering herd when a main road closesRate-limit reroutes per edge and add jitter to pushes, so a million phones do not all recompute in the same second.

What if a part fails?

FailureHow the design copes
A routing node diesStateless and replicated per region. The load balancer retries on another copy, and a new one loads the graph file from storage.
The live traffic feed stopsFall back to typical speeds by hour of week. ETAs get a little less accurate but never fail. Alert on feed freshness.
Map matching is behindThe stream is durable, so it catches up. Late speeds are published when ready, and routing keeps using the last good value until then.
The CDN has an outage in one regionFail over to another CDN or to the origin with a rate limit, and serve lower zoom tiles first.
A bad map build (a missing bridge)Validate every build against the previous one (a large change in road count or a broken connectivity check blocks release). Keep the previous version live and roll back by version.
Region-wide outage of routingRoute queries go to a neighbouring region, which loads the missing region’s graph. Slower, but it answers.
What to monitor
  • •Tile hit ratio at the CDN and origin load, per region
  • •Route latency (p50, p99) and queries per second per region
  • •ETA error: predicted versus actual trip time, by trip length
  • •Traffic freshness: the age of the speed on the busiest 1,000 edges
  • •Probe lag in the stream and the share of edges with live data
  • •Reroute rate and the fraction that actually saved time
Security and abuse
  • •Anonymise probes on the phone, rotate session ids, drop trip starts and ends
  • •Publish an edge speed only when at least k different sessions contributed
  • •Never store a long trace tied to an account in the traffic system
  • •Rate-limit search and route per key to stop scraping of the map
  • •Validate map data and incident reports, since a fake closure could steer cars

Step 7Wrap upabout 3 min

Maps is four services over one map. Vector tiles in a versioned pyramid, served by a CDN, draw it. A search index with spatial cells finds places. Routing runs on an in-memory road graph preprocessed with shortcuts, so a query takes milliseconds, and costs are re-customised when traffic changes. Phone probes are anonymised, snapped to roads and aggregated into live speeds, which feed routing and the ETA.

Trade-offs you made

DecisionWhat we gainWhat it costs
Vector tiles instead of rasterSmall, sharp at any scale, easy to restyleThe phone draws them, and there is a style and font pipeline
Dense low zooms, sparse high zooms31 TB per version instead of trillions of tilesSome on-demand work for a place with no pre-built deep tile
Preprocessed shortcutsAbout 1,000 times less CPU per routeHours of preprocessing, 24 GB more memory, and stale costs after a change
Separate structure from costsLive traffic without a full rebuildA more complex routing stack
k-anonymity for published speedsPrivacy for individual driversNo live data on quiet roads, so we fall back to typical speeds
Phone follows the route locallyNo server work per GPS point and tolerance to dead zonesThe server must push changes, and the phone needs more logic
If we had more time, we would…
  • •Walking, cycling and transit, each with its own graph and cost function
  • •Offline maps: download regions and route on the phone
  • •Predict traffic further ahead, using events and weather
  • •Multiple route objectives (shortest, fewest turns, avoid tolls)
  • •Incident reports from users, with verification
🎤
Say it out loud
“To wrap up. Vector tiles in a versioned pyramid, served from a CDN, draw the map. A spatial text index finds places. Routing runs on a preprocessed in-memory graph, so a long query is milliseconds instead of seconds, and I separate structure from costs so live traffic does not force a rebuild. Phones send anonymous probes that are map-matched and aggregated into live speeds, published only above a minimum count. The trade-off is preprocessing time and complexity for query speed. Next I would add other travel modes and offline maps.”

Q&ACross-questions (26)

💡How to practise
Cover the answer. Say yours out loud in 30 to 60 seconds. Then open the model answer, the follow-up, and the weak answer to see what to avoid. Use Open all at the top for a quick read.
Warm-upProbingCurveballWarm-up = basics. Probing = tests depth. Curveball = changes the problem.

Tiles and the map you see

Show that you can size the traffic and that you know why tiles are small, versioned and cached.

Routing

The core of the question. Be able to say why Dijkstra fails and what you do instead, in plain words.

Traffic, ETA and privacy

Show you can turn noisy phone data into a trustworthy number, and protect people while doing it.

Search, scale and operations

Place search, rolling out changes safely, and what you would not build in 45 minutes.

What ifIf the interviewer changes the problem

A change in requirements is a test of whether you understand why your design looks the way it does.

New requirementWhat changes in the design
Add walking and cycling routesSeparate graph profiles with their own cost functions (sidewalks, steps, bike paths) and their own preprocessing. Speeds are almost constant, so live traffic matters little.
Add public transportA time-dependent graph with timetables: edges that exist only at certain times, transfers with waiting. A different algorithm family, with the schedule data as a new input feed.
Offline navigationDownload tiles, a compact graph and a place index per region. Route on the phone with typical speeds. Needs versioning and a download manager.
Predict traffic one hour aheadUse history by hour of week, events and weather to forecast edge speeds, and use predicted speeds for the later parts of a long route.
Truck and delivery routing with many stopsA vehicle profile with size and weight limits, and a multi-stop optimisation (a travelling-salesman style problem) on top of fast point-to-point queries.
Add business search and reviewsA separate place store with a large text corpus, ranking signals and a moderation pipeline. It reuses the spatial index.
Crowd-sourced incident reportsA verification step (several independent reports, or a speed drop to confirm), a short life for each report, and abuse protection against fake closures.

ScoreHow answers are judged

AreaWeakGoodGreat
ScopingTreats Maps as one thing. Starts drawing boxes.Names tiles, search, routing and traffic, and picks the focus.Also settles vehicles, offline, freshness and privacy, and states what is out.
EstimationNo numbers, or only a user count.Tile requests per second, graph size, route queries.Derives the pyramid size, the dense-versus-sparse storage, the CDN hit-ratio effect on the origin, and the Dijkstra versus preprocessed core counts.
TilesOne big image, or storing every zoom densely.Tile pyramid with z/x/y, and a CDN.Vector tiles, versioned paths, sparse high zooms, overzoom and safe updates.
Routing depth“Use Dijkstra” or “use A*”.Knows that Dijkstra is too slow and that preprocessing helps.Explains contraction or partition methods in plain words, the stale-cost problem, and the structure-versus-cost split.
Traffic and ETASpeed limits, or “ask the phones”.Probes, aggregation per segment, a typical-speed fallback.Map matching, minimum sample counts, privacy by design, blending and measuring ETA error.
Trade-offs and operabilityDoes not mention failure or cost.Handles CDN and routing failures.Map-version consistency, reroute herds, build validation, canary regions and a phased plan.

AvoidCommon mistakes on this question

MistakeDo this instead
Serving the map as one large image per zoomUse a pyramid of small tiles addressed by z, x, y, and vector tiles drawn on the phone.
Saying “Dijkstra” and stoppingGive the numbers (seconds per query, thousands of cores), then preprocess the graph so queries take milliseconds.
Precomputing shortcuts and forgetting live trafficSeparate structure from costs, and recompute costs quickly when speeds change.
Using the speed limit for the ETABlend live speeds, typical speeds by hour of week and a projection, and measure ETA error.
Streaming every GPS point to the server for navigationLet the phone follow the route locally and push only changes that matter.
Storing identifiable location tracesAnonymise on the device, trim trip ends, and publish only aggregates above a minimum count.
Editing tiles in place on a map updatePublish a new version path, keep the old one for active trips, and check route and tile versions match.

Revise60-second revision sheet

  • ✔Four systems: tiles, search, routing, traffic, sharing one map.
  • ✔Tiles: 4^z per zoom, 91.6 billion to zoom 18, store about 3.1 billion (low zooms full, high zooms sparse), vector, about 10 KB, versioned paths, CDN at 97%.
  • ✔Tile traffic: 15 billion requests a day, 174,000 a second, 520,000 at peak, 150 TB a day of egress.
  • ✔Graph: 500M nodes, 1B edges, about 32 GB, so it fits in memory per region.
  • ✔Dijkstra: about 5 s on a long trip, about 28,000 cores at peak. A* and two-ended search help only a few times.
  • ✔Fix: preprocess with shortcuts (contraction hierarchies): a few thousand nodes, about 5 ms, about 28 cores.
  • ✔Staleness: shortcuts store costs. Separate structure from costs and re-customise in seconds.
  • ✔Traffic: anonymous probes, map matching, median per edge per minute, minimum sessions, blend with typical speed by hour of week.
  • ✔Navigation: the phone follows the route locally. The server pushes a change only if it saves a clear amount.
  • ✔One line: “Cut the world into cached tiles, preprocess the roads so a route is milliseconds, and keep the costs live.”

Read these topics next

Design Ride Sharing (Uber/Lyft)→

Uses this routing and ETA service to rank drivers and price trips.

S2 and H3→

Cells that index places and group probes by area.

Geohash→

A simple text code for a cell, the idea behind spatial keys.

R-Trees→

Fast point-in-polygon for reverse geocoding.

CDN→

Serves 97% of tile requests.

Heap and Priority Queue→

The structure inside Dijkstra’s algorithm.

Streaming Engines→

Windowing and late data for the speed aggregator.

Design Search Autocomplete→

The type-ahead layer on top of place search.

← Previous
Design a Search Engine
Next →
Design a Collaborative Editor (Google Docs)