Hard · Mobility and logistics
Maps and routing
You run a maps app with places, routes and live traffic. Map pictures never change much, but route lookups, place search and traffic from moving phones do. Soon a whole new continent will start using it. Keep maps fast everywhere without paying to serve the same picture twice. Practise this hard system design problem for free with a Google or GitHub account.
The brief
You run a maps app with places, routes and live traffic. Map pictures never change much, but route lookups, place search and traffic from moving phones do. Soon a whole new continent will start using it. Keep maps fast everywhere without paying to serve the same picture twice.
Think of a maps app like Google Maps.
Users, scale and requirements
- Who uses it
- 20 million people a month (approx.)
- Audience in plain numbers
- 20,000,000 people per month
- Normal peak
- ≈ 12,000 requests per second
- Request mix
- Read: 65%; Search: 13%; Location ping: 20%; Write: 2%
- Speed for 99 of 100 requests
- Read: ≈ 350 ms; Search: ≈ 500 ms; Write: ≈ 350 ms
- Successful requests
- 99.9%
- Data safety
- At most 1 minute of writes may be lost.
- Monthly budget
- ≈ $41,000
- Data at rest
- ≈ 90 TB
- Where users are
- North America: 50%; Europe: 35%; Asia Pacific: 15%
- Home region
- North America
- Waiting deadlines
- Read: 900 seconds; Search: 900 seconds; Location ping: 900 seconds; Write: 3,600 seconds
≈ marks an approximation, just as in the game. Waiting deadlines measure the age of queued work and are separate from interactive response time.
- Reads are map tiles (about 85 percent) and route or place-card lookups (about 15 percent). A tile is about 4 KB here (approx.).
- Map imagery for the world is on the order of 80 TB at several zoom levels (approx.).
- All numbers are rough approximations.
Questions that shape the design
How fresh must map pictures be?
Map tiles change maybe once a day. A tile can be kept for hours or longer.
How fresh must traffic be?
About a minute. Phones on the road send speed pings, and the app uses the latest average per road.
Can a route be reused for another person?
Popular routes can. Many people ask for the same commute, so route answers are worth keeping for a few minutes.
Where do users live?
Half in North America and a third in Europe today. After the new-continent launch, a big share will be in Asia Pacific.
The traffic day
Traffic following users around the world. The clock covers 00:00 to 24:00 in the home region. Events add pressure on top of that normal traffic.
08:00 · Overseas launch
A launch brings users who are far from your servers.
Affected share: 40%.
13:00 · Viral spike
A post blows up. Traffic climbs to several times normal within minutes.
Traffic for Read, Search reaches 4 times the scheduled load; rises over 600 seconds, holds for 3,600 seconds and eases over 3,600 seconds. Other request types keep their scheduled load.
17:00 · Cache stampede
The cache empties (restart, purge, mass expiry) and every request rushes to the database at once.
Recovery window: ≈ 300 seconds.
What a strong design has to handle
- Most requests ask for a picture that was the same yesterday. Where is the cheapest place to keep a copy near the user?
- Separate reusable map tiles from versioned routes and fresh traffic.
- A one-day tile keep time makes the CDN bill small and means a fixed map error can take up to a day to disappear, unless you purge it.
- Collapsing misses protects the origin when the cache empties, and makes the first few viewers of each tile wait together.
Make a prediction, run a full traffic day, then compare the result. The in-game editorial opens after a finished day and includes measured reference designs.
Concepts to practise
Related problems
- Easy
News site
You run a news site. Millions read the same few stories, and when something big happens almost everyone opens the same page in the same minute. Editors publish all day, and readers expect fresh headlines.
- Medium
Music streaming
People search for songs, build playlists and press play. The audio is the heavy part, and a hit song is played by millions at once. Playback must not stutter, even when part of your system fails.
- Medium
Short-video feed
People swipe through an endless feed of clips of 10 to 30 seconds. The next clip must already be on the phone before the swipe. One clip can suddenly get millions of views, and every view is a signal that picks what to show next.
- Easy
Status page
When a big service has a problem, millions of people open its status page to see what is happening. The page must stay up exactly when everything else is down, and it must not share a home with the thing it reports on. A few staff update it by hand.