Estimating by powers of ten
Why round at all
Section titled “Why round at all”Most design decisions do not need the exact figure. They need to know whether the load is 100 requests per second or 100,000, and whether the data fits on one disk or needs a hundred. An estimate that is right to within a factor of two or three answers that, and it takes a minute.
Jon Bentley opens his column on the subject with a story of a proposal for a large computer-based mail system. A short calculation showed that, under generous assumptions, the system could work only if a minute had 120 seconds in it. The design was sent back to the drawing board. He says that such calculations are usually trivial, and that the hard part is remembering to do them early.
Back-of-envelope estimation is that kind of calculation. It rounds each number to a power of ten, multiplies, and reads the order of magnitude of the result.
The rule: nearest on a logarithmic scale
Section titled “The rule: nearest on a logarithmic scale”A power of ten is 10^k: 1,000, 10,000, 100,000. The nearest one to a number is the nearest by ratio, not by difference. Between 1,000 and 10,000 the dividing line is not 5,500 but 10^3.5, which is about 3,162. So 3,000 rounds down to 1,000, and 4,000 rounds up to 10,000.
The worst error of the rule is that dividing line itself: a number just above it is rounded up by a factor of 10^0.5, which is about 3.16, and one just below it is rounded down by the same. The sorting exercise below tests the rule.
Challenge
Which power of ten?
Back-of-envelope mode rounds a number to the nearest power of ten, measured on a logarithmic scale, so the dividing line between 1,000 and 10,000 is not 5,000 but about 3,200. Put each number under the power of ten it rounds to.
Sorting needs JavaScript.
Categories
- About 1,000
- From about 320 to about 3,200.
- About 10,000
- From about 3,200 to about 32,000.
- About 100,000
- From about 32,000 to about 320,000.
- About 1,000,000
- From about 320,000 to about 3,200,000.
Check your answers at least once before looking at the answers.
A few constants are worth carrying so that the arithmetic stays in the head.
| Quantity | Exact | To carry |
|---|---|---|
| Seconds in a day | 86,400 | About 10^5, which makes averages about 14% low |
| Seconds in a 30-day month | 2,592,000 | About 2.6 million |
| Seconds in a 365-day year | 31,536,000 | About 3 × 10^7 |
| A million requests a day | 11.6 a second | About 12 a second |
| A link of 1 Gbit/s | 10^9 bits ÷ 8 bits per byte | 125 MB per second |
Try it: what rounding costs
Section titled “Try it: what rounding costs”Take a product with 30 million daily users making 30 requests each, and a peak 3 times the average. The calculator starts on it, with exact arithmetic: 900 million requests a day, an average of 10,417 per second, and a peak of 31,250.
Now switch on Back-of-envelope mode: round to powers of ten. The calculator rounds 30 million users to 10 million, 30 requests to 10, and the day to 100,000 seconds. The day’s total becomes 100 million, and the average becomes 1,000 requests per second: a factor of ten too low. In this mode the calculator shows every magnitude as a power of ten, so its peak reads “about 1K”, although the figure it uses inside is 3,000.
Traffic calculator
Your numbers
How many different people use the product on a typical day: daily active users, not registered accounts.
Count the requests that reach the system, not the screens the user sees: opening one page can send ten requests.
How many times busier the busiest moment is than the average. It depends on the product and on time zones, so take it from your own traffic when you can. The starting 3 is only a round number for illustration.
Changing the numbers needs JavaScript. The result is for the starting numbers.
Result
Peak requests per second31.3K
On average: 10.4K requests per second.
How it is calculated
Each step shows its formula, the numbers that go in, and the figure that comes out.
Requests per day
D = U × q
Every user makes the same number of requests, so the day's total is the number of users times the requests each one makes.
- U daily active users
- 30M
- q requests per user per day
- 30
D requests per day900M
Average requests per second
A = D ÷ d
Spread over the whole day. A day has 86 400 seconds; in back-of-envelope mode it is taken as 100 000.
- D requests per day
- 900M
- d seconds in a day
- 86.4K
A average requests per second10.4K
Peak requests per second
P = A × f
A system is sized for its peak, not for its average.
- A average requests per second
- 10.4K
- f peak-to-average ratio
- 3
P peak requests per second31.3K
| Requests per day | Average per second |
|---|---|
| 1M | 11.6 |
| 10M | 116 |
| 100M | 1.16K |
| 900M · your traffic | 10.4K |
| 1B | 11.6K |
| 10B | 116K |
Model notes
Assumptions
- Every user makes the same number of requests. Real users do not: a few heavy users, bots and automatic retries add requests, so measure the spread if it matters.
- The peak is the average times the ratio you enter. Real peaks depend on the product, the time of day and the time zones of the users, and a single event can exceed any ratio, so take it from your own traffic.
Simplifications
- A day has 86 400 seconds. In back-of-envelope mode it is taken as 10^5 seconds, the nearest power of ten, so the averages come out about 14% lower than the exact ones.
- In back-of-envelope mode, the counts and sizes you enter are rounded to the nearest power of ten before anything is calculated. The result is an order of magnitude, not a figure to buy against.
Parameter values are illustrative. They are not benchmarks of any real product.
Three roundings went the same way. 30 million became 10 million, which is a factor of 3 too low. 30 requests became 10, another factor of 3. And the day became 100,000 seconds, which lowers the average by 14%, a factor of 1.16. Together 3 × 3 × 1.16 is 10.4, which is the gap between 10,417 and 1,000. The calculator warns of it: each rounded number can be off by a factor of about 3, and the errors multiply.
The Fermi problem article gives the reason such estimates are usually better than that. It says that they work because overestimates and underestimates tend to cancel. That helps when the errors point in different directions. Rounding both 30s down does not: the same rule pushed both the same way.
The remedy is to keep one significant digit instead of rounding to a power of ten. Then 30 million users are 3 × 10^7 and 30 requests are 3 × 10^1. The product is 9 × 10^8 requests a day, and over 10^5 seconds that is 9,000 per second. That is 14% below the exact figure, all of it from the day’s constant, instead of a factor of ten.
A second route to the same number
Section titled “A second route to the same number”An estimate is only as good as its inputs, so check it a second way. Bentley says it is important to double-check all calculations, especially quick ones.
For the shop, whose peak is 1,852 requests per second, count the people instead. Suppose 50,000 of the million users are on the site at the busiest moment, and each sends one request every 25 seconds. That is 50,000 ÷ 25 = 2,000 requests per second. It is the arithmetic of Little’s Law used backwards (Little’s Law), and it lands 8% above the first route. Two routes built from different assumptions that agree to within a factor of two are a good sign. Two that differ by a factor of ten mean one of them has a mistake in a unit or in an assumption.
What a safety factor is for
Section titled “What a safety factor is for”An estimate leaves things out, so add a margin for them, and say what it is. Bentley quotes Vic Vyssotsky on this: to derate performance by a factor of two, four or six, and to be conservative on size and cost by a factor of two or four, to compensate for ignorance.
The earlier lessons already used small margins of this kind. The shop’s 60% utilisation target is a factor of 1 ÷ 0.6 = 1.7 on instances, and the 70% fill target is a factor of 1.4 on disk. They are choices. State them, so that the next person can change them.
What happens if every number is rounded to a power of ten?
Section titled “What happens if every number is rounded to a power of ten?”Use the product above. Each instance carries 240 requests per second at its target, as in the first lesson. The exact peak of 31,250 needs 31,250 ÷ 240 = 130.2, which is 131 instances. The rounded peak of 3,000 needs 3,000 ÷ 240 = 12.5, which is 13.
The fleet built from the rounded figure serves at most 13 × 400 = 5,200 requests per second. The real peak is 31,250, which is 601% of that: six times what the fleet can serve, and a queue that grows for as long as the peak lasts. The rounding that was meant to save effort produced a fleet of about a tenth of the size it needed.
- A back-of-envelope estimate rounds each number to a power of ten, multiplies, and reads the order of magnitude. Most decisions need no more than a factor of two or three.
- The nearest power of ten is the nearest by ratio: the dividing line between 1,000 and 10,000 is about 3,162, and a rounding can be off by up to 3.16 times.
- Carry a few constants: a day is about 10^5 seconds, a 30-day month is about 2.6 million and a year is about 3 × 10^7. A million requests a day is about 12 a second, and 1 Gbit/s is 125 MB per second.
- Rounding every number can compound: 30 million users and 30 requests give 10,417 requests per second, and the rounded estimate gives 1,000, a factor of 10.4 too low. Keeping one significant digit gives 9,000.
- Check by a second route: 50,000 users online, each sending a request every 25 seconds, make 2,000 per second against 1,852.
- Add a stated safety factor. A fleet sized for 3,000 instead of 31,250 would run at 601% of its capacity.
Next: cost estimation, and how the quantities become a bill.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.