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.
See it run
Four steps, five sums, and how far an input may move before the decision changes.
Operations
Clarify to evaluate
One estimate in the four CAFE steps, with a decision at the end.
Step 1 of 5
Clarify
| Step | Said aloud | On paper |
|---|---|---|
| Clarify | Daily users? How many views? | reads per second |
| Assume | ||
| Figure | ||
| Peak | ||
| Evaluate |
What is asked: reads a second. Ask for daily users and views per user.
Step 1: Clarify
DAY = 86_400def peak(users, per_user, factor=3): daily = users * per_user return daily / DAY * factordef machines(peak, capacity=1_000): return ceil(peak / (capacity * 0.7)) + 1- When
- One minute
- You leave with
- Machines to plan
Say the assumption before the arithmetic. If it is wrong, someone can stop you early.
In the real world
The same back-of-the-envelope calculations doing real jobs. Pick one and step through it.
Someone presents 10 billion clicks a day from 1 million users.
Step 1 of 4
The claim
| Check | Working | Verdict |
|---|---|---|
| The claim | 1M users, 10B clicks a day | ? |
| Per person | ||
| Per second | ||
| So |
It sounds impressive, and nobody objects.
Step 1: The claim
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Storing the reads
criticalMultiplying all requests by the record size counts every view as new data. Only writes add bytes.
Wrongstored = daily_requests * size * 365Rightstored = daily_writes * size * 365Rounding machines down
majorround(2.4) is 2, which cannot carry 2.4 machines of work. Round up, then add a spare.
Wrongservers = round(peak / capacity)Rightservers = ceil(peak / (capacity * 0.7)) + 1Bits and bytes mixed
majorNetworks are sold in bits a second, files are measured in bytes. The slip is a factor of eight.
Wronggbps = rate * bytes_each / 1e9Rightgbps = rate * bytes_each * 8 / 1e9Planning for the average
criticalAverage load never overloads anything on paper. The evening does.
Wrongplan(daily / 86_400)Rightplan(daily / 86_400 * 3)
Interview tips
How to explain it
- A rough sum that decides something.
- Right number of zeros, not right digits.
- Assumptions said aloud.
Memory trick: CAFE
- C: clarify what is asked.
- A: assume, and say it.
- F: figure with round numbers.
- E: evaluate: true? so what?
Numbers to know
- 86,400 s a day, about 100,000.
- 1M a day is 12 a second, 1B is 12,000.
- Peak is three times average.
Stop when
- Half and double give the same decision.
- Nobody waits for the number.
- Only a measurement can answer it.