From 1 user to 1 million

Every part of a big system exists because something broke without it. Grow an app from one server to a million users: each time it breaks, you pick the fix and watch what happens.

5 steps · about 6 minutes · free, no sign-up

Step 1: 1,000 users

Your app runs on one machine: the code and the database together.

1,000 users arrive. The app and the database fight over the same CPU and memory.

Pages now take 8 seconds to load and the machine is at 100% CPU. What do you do first?

  • Buy a bigger machine (Helps for a while): It works for a while: a bigger machine is the quickest fix. But machines only come so big, and if this one dies, the whole app dies with it.
  • Move the database to its own server (Right fix): The app and the database stop fighting. Each gets a whole machine, and from now on you can grow each one separately. Separate the tiers: The app (the code that handles requests) and the data (the database) live on different machines. Almost every system starts its growth with this split.
  • Add a CDN (Not this one): A CDN keeps copies of files like images close to users. It doesn’t help a CPU that is busy running your code and your database.

Step 2: 10,000 users

10,000 users. The database copes, but one app server can’t keep up, and every restart takes the site down.

The app server is at 100% CPU and requests are timing out. What do you do?

  • Give the database more memory (Not this one): The database was only 40% busy. The bottleneck is the app server, so the site is just as slow.
  • Add more app servers behind a load balancer (Right fix): Requests are spread over three servers, and if one crashes, the load balancer stops sending users to it. Need more capacity? Add another server. Load balancer + horizontal scaling: A load balancer is one address that spreads requests across many servers and skips servers that stop answering. Adding more servers like this is horizontal scaling; buying a bigger one is vertical scaling.
  • Buy an even bigger app server (Helps for a while): Better for now, but you are back to one machine: one crash or one deploy and the whole site is down. And the next size up costs a lot more for a little more power.

Step 3: 100,000 users

100,000 users. The app servers are fine, but every page asks the database the same questions.

The database is overloaded with 9,000 reads a second, and 90% of them are the same popular pages (the home feed, top products). What do you add?

  • Restart the servers (Not this one): Restarting clears nothing. The same 9,000 reads a second come straight back.
  • Add read copies of the database (Helps for a while): It works, but you are paying for whole databases to answer the same question over and over. For data that is read again and again, there is a much cheaper fix. Replicas come in handy later.
  • Put a cache in front of the database (Right fix): The cache answers 90% of reads from memory in under a millisecond. The database only sees the misses and the writes. Cache: A cache (like Redis) keeps popular answers in fast memory, so most requests never reach the database. The trade-off: cached data can be a little out of date, so each item expires after a while (its TTL).

Step 4: 300,000 users

300,000 users read lots of different things now, so more reads miss the cache and land on the one database.

The database is red again. Reads outnumber writes 10 to 1. What do you add?

  • Add read replicas (Right fix): Writes go to the main database, which copies every change to the replicas. Reads are spread across the copies. Read replicas: Copies of the database that only answer reads. All writes go to the main one (the primary), which streams changes to the replicas. Replicas can be a moment behind, so read your own fresh writes from the primary.
  • Delete old data (Not this one): Smaller tables help a little, but the problem is the number of reads, not the size of the data. And users want their old posts.
  • Buy a bigger database server (Helps for a while): Fine for a while, but it is still one machine doing every read and every write, and the biggest database servers get very expensive.

Step 5: 1,000,000 users

A million users all over the world. Pictures and videos are slow far from your servers, and sending them keeps your servers busy.

Users in Australia wait 4 seconds for every picture, and your servers spend most of their time sending the same files. What do you add?

  • Add more app servers (Helps for a while): Your servers cope, but users far away still wait. The problem is distance, not capacity: every picture still crosses the world.
  • Put a CDN in front of images and files (Right fix): Files are served from a CDN server near each user, in milliseconds. Your own servers only do the real work. CDN (content delivery network): Servers in many cities that keep copies of your files (images, video, scripts) close to users. The first user in a city fetches it from you; everyone after gets the nearby copy.
  • Compress the database (Not this one): Pictures don’t live in the database, and the database isn’t the slow part. Users still wait.

What you built

  • Load balancer: One address in front of many app servers. Spreads requests and skips servers that fail.
  • App servers: Many identical servers (horizontal scaling). Keep no user data on them, so any server can answer any request.
  • Cache: Answers repeated reads from memory, so the database only sees misses and writes.
  • Main database: The single source of truth: every write goes here.
  • Read replica: Copies of the database that share the reads. May lag slightly behind the main one.
  • CDN: Serves images and files from near each user, so distance stops being the problem.
ProblemFixTrade-off
App and data on one machineSeparate the tiersMore machines to run
One app server is fullLoad balancer + more serversServers must not keep user data locally
Same reads over and overCacheData can be slightly stale
Too many different readsRead replicasReplicas lag a little
Users far away, heavy filesCDNCached files need a way to refresh

Frequently asked questions

What should I add first when an app gets slow?

Find the part that is overloaded first. Usually the order is: split the app and the database, add app servers behind a load balancer, add a cache, then read replicas and a CDN.

What is the difference between vertical and horizontal scaling?

Vertical scaling means a bigger machine; it is simple but has a ceiling and is still one point of failure. Horizontal scaling means more machines behind a load balancer; it can keep growing and survives a machine dying.

When should I use a cache instead of read replicas?

Use a cache when the same data is read again and again; it is far cheaper per read. Use read replicas when reads are varied, so a cache would miss often, or when you need full database queries.

What comes after a million users?

Splitting the data across databases (sharding), moving slow work to background queues, and running in more than one region. They follow the same idea: find what breaks, fix that part.

← All visual lessons

Try AI Flowchart free →