Back-of-the-envelope estimates · System Design
How many servers does an app with a million users need?
Course contentsWhy you need it
Every system design starts with sizes. One database or fifty? Is the data a few gigabytes or a few hundred terabytes? You can't measure a system that doesn't exist yet, but a quick estimate usually gets the order of magnitude right, and that's enough to rule out designs that would never work. Interviews ask for it too.
The intuition
Work from what you know to what you need, one multiplication at a time:
- requests per day = daily users × requests per user
- average per second = requests per day / 86,400 (the seconds in a day)
- peak per second = average × a peak factor. Traffic isn't flat; use a factor measured from similar traffic if you have one, or pick one and write it down
- servers = peak / what one server handles, rounded up. "What one server handles" comes from a load test, never from a guess
- one spare so you survive a server failing (often written N + 1)
Storage works the same way: items per day × size × days kept × copies.
Keep the numbers round. 86,400 is close to 100,000, so a million requests a day is roughly 10 a second. The point is to be about right, quickly, and to show your assumptions so someone can correct them.
Definition
QPS
Queries (requests) per second: the usual unit of load.
Peak factor
How much busier the busiest time is than the average.
N + 1
Running one more server than the load needs, so one failure doesn't overload the rest.
Examples
From users to servers
Try it yourselfA million daily users, 20 requests each, peak factor 3, and a load test said one server handles 200 per second.
import math
daily = 1_000_000 * 20
average = daily / 86_400
peak = average * 3
servers = math.ceil(peak / 200) + 1
print(round(average), round(peak), servers)231 694 5
- L320 million requests a day. Underscores just make big numbers readable.
- L4About 231 per second on average.
- L5About 694 per second at the busiest time.
- L6694 / 200 = 3.47 → 4 servers, plus 1 spare.
5
Storage for photos
Try it yourselfTwo million photos a day, 2 MB each, kept for a year, stored 3 times.
photos_per_day = 2_000_000
mb_each = 2
days = 365
copies = 3
tb = photos_per_day * mb_each * days * copies / 1_000_000
print(tb, "TB")4380.0 TB
- L5MB → TB is a division by a million (in decimal units).
- L6Thousands of terabytes: one database server won't do; this needs object storage.
Common mistakes
Designing for the average
Traffic has peaks. A system sized for the average falls over every evening.
Guessing a server's capacity
"One server does 10,000 per second" depends entirely on the work per request. Load-test your own service.
Forgetting copies and growth
Backups, replicas and next year's growth often multiply storage several times over.
Quick quiz
1. What does this print?
per_day = 8_640_000
print(per_day / 86_400)Show the answer
Answer: A
8,640,000 / 86,400 = 100 per second.
2. Why add one server beyond what the peak needs?
Show the answer
Answer: A
N + 1: losing any one server still leaves enough capacity.
Practice
3 exercises in three steps: predict what a program prints, change a program to meet a new requirement, then write one from scratch. Your code runs in the browser and is checked the moment you submit.
- PredictRound numbers
Type exactly what this prints.
- ModifyCount every copy
storage_tbforgets that each photo is storedcopiestimes. Fix it. - WriteHow many servers?
Write
servers_needed(daily_users, per_user, peak_factor, per_server):- peak per second = daily_users × per_user / 86,400 × peak_factor
- servers for the load = peak / per_server, rounded up, but at least 1
- return that plus 1 spare
servers_needed(1_000_000, 20, 3, 200) # 5
Practise this lesson
Open the interactive lesson to edit and run these examples and solve the exercises with instant feedback. Free to start, no sign-up.
Terms in this lesson
| Term | Chinese | Definition |
|---|---|---|
| QPS | 每秒请求数 | Requests per second. |
| Peak factor | 峰值系数 | How much busier the peak is than the average. |
| N + 1 | N + 1 冗余 | One spare server beyond what the load needs. |