Playground

Real-time · Foundations · Cached place lookups over Postgres

Google Maps system design, running live

Most map requests ask for places and routes that plenty of other people asked for earlier that day. Six web servers behind a load balancer answer nine in ten from the cache, and Postgres with one replica holds the rest. Live traffic and route planning are left out.

A teaching design of a system like Google Maps, not Google Maps's real architecture. Traffic, capacity and cost are simulator estimates. Model and assumptions.

Traffic
3,000 req/sMedium scale
AWS bill
$1,000/mo
p99
66 ms
Components
4

3,000 requests a second, 5% of them writes. That's a busy SaaS product or a mid-sized shop at its daily peak.

Google Maps architecture on AWS at 3,000 requests a second
Google Maps architecture on AWS at 3,000 requests a second. Scroll the diagram to see every component. The small text under a box is its traffic, instance count or shard count.

How it works

  1. A request reaches the load balancer, which picks a healthy web server. A server that fails its health check stops getting traffic.
  2. The web server asks the cache first. Nine reads in ten are answered there in a couple of milliseconds.
  3. Cache misses and every write go to Postgres. Writes land on the primary; the replica serves reads and is ready for a failover.
  4. At 3,000 requests a second the six servers run at about half their capacity. That spare half is what absorbs a launch or a bad deploy.

What each part does

Visitors
3,000 requests a second, 95% reads. Change it and watch the rest of the design react.
Web servers
Six m7g.large servers. The simulator gives each about 1,000 requests a second, so they sit near 50% busy.
Cache
One cache.r7g.large node. At a 90% hit ratio it turns 2,850 reads a second into about 285 database reads.
Database
Postgres on db.r7g.large: a primary for writes and one read replica.

What breaks first

The web servers. They hit their limit at about 1.9x the preset (5,700 req/s), while the database is still only half busy.

Past that point requests queue inside each server until it runs out of room, crashes and restarts, and the restarts push more load onto the survivors. At 4x almost every request fails. The fix is more servers, or autoscaling that adds them before the queue builds rather than after.

The simulator checks this every build: it runs the design at 3,000 req/s, then ramps traffic to 4x (12,000 req/s) and records which part fails first. In the playground, press Break it to watch the same thing happen.

Trade-offs

What it gets right

  • Easy to run, debug and hire for. Every framework tutorial ends up here.
  • One cache node removes most of the database load for about the price of one web server.

What it costs you

  • The web fleet is fixed. Traffic that doubles in a few minutes outruns it before anyone adds servers.
  • One primary takes every write, so a write-heavy product eventually needs sharding or a different store.
  • Drop the hit ratio to 50% and the database sees five times the reads. The cache is quietly holding the design up.

In the real world

  • Most Rails, Django and Laravel apps run like this for years: a load balancer, a few app servers, Redis or Memcached, and Postgres or MySQL.
  • Stack Overflow is the well-known example of serving a huge site from a small, carefully tuned set of web servers, SQL Server and Redis.

In the interview

  • Start here even for a big 'design X' question, then say which number forces each change.
  • Do the cache arithmetic out loud: at a 90% hit ratio one read in ten reaches the database. Say what that comes to for the traffic you were given.
  • When failure comes up, mention health checks and keeping one spare server so losing one doesn't overload the rest.

Run it yourself

The playground opens this design with 3,000 requests a second already flowing. Press Break it, or change one part yourself, and watch which number goes first.

Read the walkthrough: Design a Maps ETA and Routing Service

Questions people ask

How does Google Maps work at the system design level?

A request reaches the load balancer, which picks a healthy web server. A server that fails its health check stops getting traffic. The web server asks the cache first. Nine reads in ten are answered there in a couple of milliseconds. Cache misses and every write go to Postgres. Writes land on the primary; the replica serves reads and is ready for a failover. At 3,000 requests a second the six servers run at about half their capacity. That spare half is what absorbs a launch or a bad deploy.

What breaks first in a Google Maps design?

The web servers. They hit their limit at about 1.9x the preset (5,700 req/s), while the database is still only half busy. Past that point requests queue inside each server until it runs out of room, crashes and restarts, and the restarts push more load onto the survivors. At 4x almost every request fails. The fix is more servers, or autoscaling that adds them before the queue builds rather than after.

What are the trade-offs of this Google Maps architecture?

Easy to run, debug and hire for. Every framework tutorial ends up here. One cache node removes most of the database load for about the price of one web server. The web fleet is fixed. Traffic that doubles in a few minutes outruns it before anyone adds servers. One primary takes every write, so a write-heavy product eventually needs sharding or a different store. Drop the hit ratio to 50% and the database sees five times the reads. The cache is quietly holding the design up.

What do interviewers look for in a Google Maps system design answer?

Start here even for a big 'design X' question, then say which number forces each change. Do the cache arithmetic out loud: at a 90% hit ratio one read in ten reaches the database. Say what that comes to for the traffic you were given. When failure comes up, mention health checks and keeping one spare server so losing one doesn't overload the rest.

One system design problem a week

A real scenario, its constraints, and where the obvious design breaks.

One email a week. Unsubscribe any time. Privacy

Now break one yourself.

The first challenge takes about two minutes. No signup.