Numbers that decide
easy 35 minAn estimate is worth doing when its answer changes what you draw.
Video lesson · Chapter 1 of 5
Twenty million views and one decision
Four sums, one minute each
1:25Reel coming soon
Theory
Read or listen first. About 1 min.
What it is
An estimate is a quick calculation with rounded numbers that is good enough to make a decision. In design it is often called back-of-the-envelope arithmetic.
The aim is the right order of magnitude. Knowing whether you face a thousand or a million requests a second matters. The third digit does not.
Why it exists
Parts are added to a design because something is too big or too fast for what you have. Only a number can tell you that.
It works the other way too. A number often shows that one machine is enough, which saves everyone work.
A short history
1945
Enrico Fermi estimates the strength of the first atomic test by dropping scraps of paper, a famous example of useful rough reckoning.
1984
Jon Bentley writes about back-of-the-envelope calculation for programmers in Communications of the ACM.
About 2009
Jeff Dean's talks at Google spread a table of latency numbers every engineer should know.
2018
Google's SRE Workbook includes a chapter on designing with real quantities.
Words to know
- Order of magnitude
- A power of ten.
- QPS
- Queries, or requests, per second.
- Peak
- The busiest moment; we use three times the average.
- Throughput
- How much work per second.
- Latency
- How long one piece of work takes.
How it works
Step through the idea, or press Play.
Ask. Which decision is waiting for a number?
Understand it
Start here
One van or a lorry?
Moving house, you do not weigh every spoon. You count the boxes, because the count decides what to rent. For one lamp you count nothing. Estimation in an interview is the same: find the sum that decides, and leave the others.
When
Calculate, or say no
Is this sum worth a minute?
Which sum decides what
| Sum | Decides | Skip when |
|---|---|---|
| Peak reads a second | Cache, replicas, edge | A few hundred a second |
| Peak writes a second | One database, batching, queue, split | A few hundred a second |
| Storage over the years | One database or partitions, object storage, deletion | Clearly under 1 TB |
| Open connections | Number of gateways, memory | Nothing is pushed |
| Bytes out a second | CDN, image sizes | Responses are tiny |
| Size of the hot set | Cache memory | You have no cache |
Sum 1
Per day to per second, then peak
The only conversion you need
Recipe pages
Three times is for an ordinary day with a busy evening. When people arrive because a clock says so, count the people instead.
The 9:00 rush on library seats
Sum 2
Storage over time
Items a day, times size, times 365, times years, times copies. Do text and media separately, because they live in different places.
Recipe photos for five years
Sum 3
Connections and work in progress
Work in progress
Live connections for the bus tracker
Sum 4
One machine or many
Machines
Reading the result
Planning lines (rules of thumb)
| Load on one relational database | Suggests | Why it is only a hint |
|---|---|---|
| Under about 10,000 simple reads a second | Enough as it is | A heavy query can use a whole core |
| Over about 10,000 simple reads a second | Cache or replicas | Well-tuned machines go further |
| Over about 10,000 small writes a second | Batch, queue or split | Depends on disks, indexes and durability |
| Over about 30 TB | Partition the data | Backups and restores become slow first |
Head maths
Shortcuts worth knowing
Million a day
About 10 a second (11.6).
Billion a day
About 10,000 a second (11,600).
One a second
About 100,000 a day (86,400), 30 million a year (31.5).
Thousands
KB × thousand = MB, × million = GB, × billion = TB.
Bits and bytes
Divide by 8. A 10 Gb/s link moves about 1.25 GB a second.
A year
Use 400 days instead of 365. It is 10% high, a safe side for storage.
Doing it aloud
- 1
Round first
86,400 becomes 100,000. 365 becomes 400. 487 KB becomes 500 KB.
- 2
Split off the zeros
20 million is 2 and seven zeros. Subtract five zeros for 100,000: 2 and two zeros, 200.
- 3
Keep the unit
Say "200 reads a second", never "200".
- 4
Sense check
One million users cannot make a billion clicks a day unless each clicks 1,000 times.
- 5
End with so
"So one database is enough."
Sizes
Latency and throughput, by order of magnitude
These are rules of thumb. Hardware and settings move them by two to ten times. Use them to see which part of a request is slow, then measure.
Latency
| Action | Order of magnitude | Basis |
|---|---|---|
| Read from memory | 100 ns | Rule of thumb |
| Small read from a local SSD | 100 µs | Rule of thumb |
| Round trip inside one zone | under 1 ms | Rule of thumb |
| Redis lookup over the network | about 1 ms | Rule of thumb, mostly network |
| Cloud disk (AWS gp3) | single-digit ms | AWS documentation |
| Indexed database lookup | 1 to 5 ms | Rule of thumb |
| Round trip between regions | 10 to 250 ms by distance | Microsoft publishes a table for Azure |
| First byte from S3, small object | 100 to 200 ms | AWS documentation |
Throughput and limits
| Thing | Order of magnitude | Basis |
|---|---|---|
| One application server | hundreds to thousands of requests/s | Rule of thumb, depends on the work |
| One relational database, simple lookups | 10,000/s to plan with | Rule of thumb |
| One Redis server, simple commands | 100,000/s | Redis docs show a benchmark near 180,000 |
| AWS gp3 disk | 3,000 operations/s included, up to 80,000 | AWS documentation |
| PostgreSQL connections | 100 by default | PostgreSQL documentation |
| Network card at 10 Gb/s | 1.25 GB/s | Arithmetic |
Worked example 1
School bus tracker, word for word
Three sums, three decisions
Interviewer
2,000 buses, 100,000 parents. Do we need anything special?
You
Three sums will tell. Writes: 2,000 buses, one position every 5 seconds, is 400 a second. So one database could take the writes.
You
Reads: 100,000 parents polling every 10 seconds is 10,000 a second, all at 7:45. I will not use the daily average, because they come together. So I keep the newest position in a cache.
You
Storage: 400 a second for 4 hours is 5.8 million rows a day. At 100 bytes that is about 0.6 GB a day, 115 GB in a 200-day school year. So history stays in one database.
Interviewer
And bandwidth?
You
A position is about 100 bytes, so 10,000 a second is 1 MB a second before headers. Nothing depends on it. I will skip it.
Check the storage
Worked example 2
Recipe photos: the number that forces a CDN
600 recipe pages a second at peak, four photos of 500 KB on each.
Bytes out
A number that decides
- "10 Gb/s of photos, so a CDN."
- "91 GB of text, so one database."
- "5,000 a second at 9:00, so a cache."
- "115 GB a year, so no new store."
A number that decorates
- "That is 1,728,000,000 a month."
- "Headers are 412 bytes..."
- "We need 17.36 servers."
- "Big. So it must scale."
import mathdef machines(peak, capacity, use=0.7, spare=1): return math.ceil(peak / (capacity * use)) + sparereads = 1_000_000 * 20 / 100_000print("recipe reads/s:", reads, "peak:", reads * 3)print("photo bytes/s at peak:", reads * 3 * 4 * 500_000 / 1e9, "GB")print("bus writes/s:", 2_000 / 5, "poll reads/s:", 100_000 / 10)print("machines for 3,500/s at 1,000 each:", machines(3500, 1000))Summary
The whole topic in one minute.
Do a sum when its answer changes the design, use round numbers and end with the decision.
Per day divided by 100,000 gives per second, times three for the peak. If nothing hangs on a number, skip it.
- No decision, no sum.
- Divide a day by 100,000; three times for an ordinary peak.
- A clock-driven rush: count people, not days.
- Round hard, keep units, end with "so".
- Limits are rules of thumb until measured.