Lesson 232 of 296
Back-of-envelope estimation
What you will learn
- Why we estimate
- Useful numbers to remember
- Calculating requests per second, storage and bandwidth
- Worked examples
- Latency numbers every developer should know
On this page
Why estimate?
Estimates tell you which problems you actually have. 50 requests per second fits on one small server with one database; 500,000 requests per second needs caching, many servers and probably sharding. Interviewers want to see you reason with numbers, not get them exactly right. Round freely and say your assumptions.
Numbers to remember
| Fact | Value |
|---|---|
| Seconds in a day | 86,400 (round to 100,000 = 10^5) |
| Seconds in a month | about 2.6 million |
| Requests per day → per second | Divide by 10^5: 1 million a day is about 10 per second (exactly 11.6) |
| Peak traffic | Assume 2 to 3 times the average (more for events) |
| 1 KB, 1 MB, 1 GB, 1 TB, 1 PB | 10^3, 10^6, 10^9, 10^12, 10^15 bytes (decimal approximation) |
| A character of text | about 1 byte (ASCII) |
| A typical small JSON record | 0.5 to 1 KB |
| A photo (compressed) | about 200 KB to 2 MB |
Rough single-machine capacity (depends hugely on the work done; use only as a starting point):
- A typical stateless web server: hundreds to a few thousand requests per second.
- A well-indexed PostgreSQL instance on good hardware: thousands to tens of thousands of simple queries per second.
- Redis: around 100,000 simple operations per second per instance.
Method
- Daily active users (DAU) × actions per user per day = actions per day.
- Actions per day ÷ 100,000 ≈ average per second; × 2 or 3 for peak.
- Storage = new records per day × record size × days kept (× replication factor, often 3).
- Bandwidth = requests per second × response size.
Worked example: URL shortener
Assumptions: 100 million new links a month; read/write ratio 100:1; each record about 500 bytes; keep links for 5 years.
| Quantity | Calculation | Result |
|---|---|---|
| Writes per second | 100,000,000 ÷ (30 × 86,400) | about 39 per second (call it 40) |
| Reads per second | 40 × 100 | about 4,000 per second (peak around 10,000) |
| Links over 5 years | 100 million × 12 × 5 | 6 billion |
| Storage | 6 × 10^9 × 500 bytes | 3 TB (before replication) |
| Short code length | Base62 with 7 characters: 62^7 | about 3.5 trillion codes: far more than 6 billion |
Conclusion: writes are small; reads dominate and are perfect for caching; 3 TB fits in one large database but sharding or a key-value store is reasonable for growth.
Worked example: photo sharing app
Assumptions: 10 million DAU; each views 50 photos and uploads 0.2 photos a day; average photo 500 KB (after compression); keep forever.
| Quantity | Calculation | Result |
|---|---|---|
| Uploads per day | 10 million × 0.2 | 2 million |
| Upload rate | 2,000,000 ÷ 86,400 | about 23 per second |
| Photo views per second | 10 million × 50 ÷ 86,400 | about 5,800 per second (peak about 15,000) |
| New storage per day | 2 million × 500 KB | 1 TB per day, about 365 TB per year |
| Outgoing bandwidth | 5,800 × 500 KB | about 2.9 GB per second |
Conclusion: photos must live in object storage (S3, Lesson 254), served through a CDN (Lesson 234); the database stores only metadata.
Latency numbers
Approximate, but the orders of magnitude are what matter:
| Operation | Rough time |
|---|---|
| Read from CPU cache / main memory | nanoseconds to about 100 nanoseconds |
| Read 1 MB sequentially from memory | a few microseconds to tens of microseconds |
| Random read from an SSD | about 100 microseconds |
| Round trip within one data centre | about 0.5 milliseconds |
| Redis GET over the network | under 1 millisecond |
| Indexed database query | 1 to 10 milliseconds |
| Round trip London to New York | about 70 to 80 milliseconds |
| Round trip London to Sydney | about 250 milliseconds |
Lessons: memory is far faster than disk; disk is far faster than crossing the world; so cache hot data in memory, put content near users (CDN), and avoid many sequential network round trips (N+1, Lesson 221).
How to say it in an interview
"I estimate from daily active users and actions per user, dividing by about 100,000 seconds a day for average requests per second and multiplying by two or three for peak; a million requests a day is roughly ten per second. Storage is records per day times size times retention, times the replication factor. For a URL shortener at 100 million new links a month that is about 40 writes and 4,000 reads per second and 3 TB over five years, so reads and caching dominate. I keep latency orders of magnitude in mind: memory in nanoseconds, a data-centre round trip in half a millisecond, a transatlantic round trip in tens of milliseconds."
Key words
| Word | Meaning |
|---|---|
| Back-of-envelope estimate | A quick rough calculation |
| DAU | Daily active users |
| RPS / QPS | Requests / queries per second |
| Peak factor | How much busier the busiest time is than average |
| Replication factor | How many copies of data are stored |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.