Back-of-the-envelope calculations
easy 25 minA back-of-the-envelope calculation is a quick, rounded sum that tells you whether a design is feasible.
Video lesson · Chapter 1 of 5
Start from the quantity to decide
Four steps, one estimate
1:20Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
A back-of-the-envelope calculation (often shortened to BOTE) is a rough sum done with rounded numbers, small enough to fit on the back of an envelope. It answers one kind of question: is this roughly possible, and roughly how much do I need?
It is an estimate, so it is meant to be slightly wrong. What matters is the order of magnitude: the number of zeros. Whether a service gets ten or ten thousand requests a second changes the design. Whether it gets 11,574 or 12,000 does not.
Why it exists
A design can fail before anyone writes code, because the load does not fit the machine, the disk or the network. A one-minute sum finds that out for free.
It also stops you from building too much. Many systems that sound large fit on one database once you do the division. And because every assumption is said out loud, other people can correct the input instead of arguing about the result.
A short history
1945
At the Trinity test Enrico Fermi drops scraps of paper as the blast passes and estimates its strength from how far they move.
1961
John Little publishes a proof that the average number of items in a system is the arrival rate times the average time each stays. Many capacity sums rest on it.
1984
Jon Bentley's Programming Pearls column in Communications of the ACM is titled "The Back of the Envelope" and shows programmers how to use such sums.
2018
Google's Site Reliability Workbook publishes a chapter on non-abstract large system design: designs that carry real quantities and are revised when the numbers do not fit.
Words to know
- BOTE
- Back of the envelope: quick and rounded.
- Order of magnitude
- A power of ten. 400 and 700 share one; 400 and 4,000 do not.
- DAU
- Daily active users: people who use the service on a given day.
- QPS
- Queries, or requests, per second.
- Retention
- How long data is kept.
- Headroom
- Capacity kept free, so that a bump or a failed machine does no harm.
- Sanity check
- Comparing a result with something you know to see whether it can be true.
How it works
Step through the idea, or press Play.
Clarify and assume. Ask what is known, then say the rest as assumptions
Understand it
Start here
The pizza party
Twenty friends are coming. You do not know exactly how hungry each one is, and you do not need to. A few seconds of rounded arithmetic tells you how many pizzas to get.
Nobody counted exact appetites. The estimate only had to be good enough to place the order.
The idea
Precision or speed
Compare two ways of doing one multiplication. The exact one takes a calculator. The rough one takes a second.
Exact and rough
Why bother
In interviews
It shows that you think about scale, are practical, check your design and find bottlenecks early.
Sanity checks at work
Is this bill, this log volume or this graph even possible?
Cost and capacity
Roughly how many machines and how many terabytes, before anything is ordered.
Architecture choices
One database or many, with or without a cache: a number decides.
Which estimates are worth a minute at all, and which to refuse, is the subject of Numbers that decide. This page is about how to do one well.
The method
CAFE: clarify, assume, figure, evaluate
One estimate from start to finish
- 1
Clarify the requirements
Ask what is being estimated and what limits exist. "How many users? What is the read to write ratio? How long do we keep the data?"
- 2
Assume, explicitly
Fill the gaps with reasonable values and say them, so they can be corrected. "Let us assume 100 million daily users with 10 requests each."
- 3
Figure
Calculate step by step with rounded numbers and units. 100 million × 10 is 1 billion a day; divided by 100,000 that is 10,000 a second.
- 4
Evaluate
Is the order of magnitude believable, and what does it decide? "About 10,000 a second, 30,000 at peak: one server cannot, so several behind a balancer."
When a question looks too big, split it into parts you can count. How many bricks does a toy castle need? Nobody knows, but it has 4 walls of about 100 bricks.
Split, then multiply
Head maths
Round before you multiply
Numbers to round
| Exact | In your head | What | Error |
|---|---|---|---|
| 86,400 | 100,000 | seconds in a day | rates come out 14% low |
| 2,592,000 | 2.5 million | seconds in 30 days | rates 4% high |
| 31,536,000 | 30 million | seconds in a year | rates 5% high |
| 1,073,741,824 | 1 billion | bytes in a gibibyte (GiB) | 7% low |
| 1,000,000,000 | 1 billion | bytes in a gigabyte (GB) | exact |
| 365 | 400 | days in a year | storage 10% high |
Is my estimate good enough?
The sums
Five sums and where each one lands
Each number belongs to a part
1. Traffic
2. Storage
3. Bandwidth
4. Machines
5. Cache
import mathDAY = 86_400dau, per_user = 10_000_000, 50avg = dau * per_user / DAYpeak = avg * 3print(f"traffic: {avg:,.0f}/s, peak {peak:,.0f}/s")print(f"storage: {10_000_000 * 500_000 * 365 / 1e15:.2f} PB a year")print(f"bandwidth: {100_000 * 5 / 1000:,.0f} Gb/s")print(f"machines: {math.ceil(50_000 / (1_000 * 0.7)) + 1}")print(f"cache: {1_000_000_000 * 0.20 * 1_000 / 1e9:,.0f} GB")Busy hours
Average, peak, plan
From a daily total to a capacity
Two ideas are easy to mix up. The peak factor describes the users. The 70% describes your machines. Use each once. How a peak is found is in QPS.
Practice 1
A timeline service
Given: 500 million daily users, 10 timeline views each, 100 posts per view, about 1 KB per post, and a server that can do 10,000 such reads a second.
Worked aloud
Interviewer
Requests a second, bandwidth and servers, please.
You
500 million times 10 is 5 billion views a day. Divided by 100,000 that is 50,000 a second; exactly it is about 58,000. At three times, roughly 175,000. So this is a fleet, not a machine.
You
One view is 100 posts of 1 KB, so 100 KB. 58,000 times 100 KB is 5.8 GB a second, about 46 Gb/s on average and 140 at peak. So text alone is many network cards; I would compress it and send fewer posts first.
You
Servers: 175,000 over 10,000 times 0.7 is 25, plus one spare is 26. So about 26, if the 10,000 survives a load test. It looks generous for 100 posts a view.
Interviewer
Some would say 12.
You
That is 58,000 over 10,000, doubled. It uses the average, and a peak of three times would overload it.
Practice 2
A URL shortener
100 million new links a month, 100 reads per write, 500 bytes, 5 years
| Sum | Working | Result | So |
|---|---|---|---|
| Writes | 100M / 2.5M s | about 40/s (38.6) | any database |
| Reads | 40 × 100 | 4,000/s, 12,000 at peak | just past one database's planning line: add a cache |
| Links | 100M × 12 × 5 | 6 billion | codes of 6 letters or more |
| Storage | 6B × 500 B | 3 TB, or 9 TB with 3 copies | no need to split the data yet |
Practice 3
A video service
Given: 1 million viewers at once at peak, 5 Mb/s each, 1,000 new videos a day of 1 GB, kept forever.
| Sum | Working | Result | So |
|---|---|---|---|
| Bytes out | 1M × 5 Mb/s | 5 Tb/s | 500 cards of 10 Gb/s: serve from a content network |
| Storage | 1,000 × 1 GB × 365 | 365 TB a year | object storage, with a rule for rarely watched videos |
| Bytes in | 1,000 GB / 86,400 | 11.6 MB/s, about 93 Mb/s | uploads are not the problem |
Doing it well
Habits and slips
Five habits
| Habit | Why | Sounds like |
|---|---|---|
| State assumptions | Others can correct the input | "Let us assume 100M daily users, 20 requests each." |
| Round hard | Saves time, keeps the zeros right | "86,400 is about 100,000." |
| Show the steps | A slip is easy to find | "500M × 10 is 5B; over 100,000 is 50,000." |
| Sanity check | Catches a lost factor of 1,000 | "50,000 a second is a lot, but 500 million people is too." |
| Use the peak | Averages hide the evening | "10,000 average, 30,000 peak, so capacity for 43,000." |
Do
- Think out loud
- Say 1.2 million
- Say the unit: per second, GB, Gb/s
- Use the peak, three times average
- Base guesses on something, and say what
- Stop at the order of magnitude
Avoid
- Calculating in silence
- Saying 1,234,567
- Bare numbers without a unit
- Only the average
- Numbers out of thin air
- Two decimals on a guess
Sanity check in three questions
Summary
The whole topic in one minute.
Clarify what is asked, assume and say the inputs aloud, figure with rounded numbers, then evaluate: does the answer make sense, and what does it decide?
Five sums cover most designs: traffic, storage, bandwidth, machines and cache. A day is 86,400 seconds (divide by 100,000 in your head), an ordinary peak is three times the average, and a machine is planned at about 70% of what it can do. Being off by two rarely matters; being off by ten does.
- Clarify, assume, figure, evaluate.
- Round first, keep units, show the steps.
- Traffic, storage, bandwidth, machines, cache.
- Peak is three times average; plan machines at 70% plus one spare.
- Off by two is fine, off by ten is another design.