Web apps · Foundations · Popular queries answered from cache
Google Search system design, running live
The same popular queries come in again and again, so most answers can be reused. A load balancer feeds six web servers, the cache answers nine queries in ten, and misses fall through to Postgres. A real search engine needs an index; this is the design you start from before you need one.
A teaching design of a system like Google, not Google'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.
How it works
- 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 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.
Questions people ask
How does Google Search 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 Search 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 Search 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 Search 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.