Lesson 2 of 38Building blocks
Back-of-the-Envelope Estimation
Turn users into QPS, storage, and bandwidth numbers in minutes, and know the latency of memory, disk, and network.
"Will one Postgres server handle this?" is a question you answer with arithmetic, not opinions. Back-of-the-envelope estimation means rough, fast math (right within a factor of two or so) that tells you which design is even worth considering. Interviewers expect it in the first five minutes, and good engineers do it before every big build.
Powers of two and big round numbers
Computers count in powers of two, people count in powers of ten. For estimates you treat them as the same: 2^10 = 1,024, which is close enough to a thousand.
| Power | Exact value | Approx | Unit |
|---|---|---|---|
| 2^10 | 1,024 | a thousand | 1 KB |
| 2^20 | 1,048,576 | a million | 1 MB |
| 2^30 | about 1.07 billion | a billion | 1 GB |
| 2^40 | about 1.1 trillion | a trillion | 1 TB |
| 2^50 | about 1.13 quadrillion | a thousand trillion | 1 PB |
A few sizes worth memorising: a character in ASCII is 1 byte, a UUID is 16 bytes (36 as text), a bigint or timestamp is 8 bytes, a short text row with metadata is about 1 KB, a compressed phone photo is about 200 KB to 2 MB, and a minute of 1080p video is about 50 to 100 MB.
Latency numbers every engineer should know
These are the costs of the basic things a computer does. The exact values change with hardware, but the ratios are what you need: each line is roughly 10 to 1,000 times slower than the one above.
| Operation | Rough time | In "human" terms if L1 = 1 second |
|---|---|---|
| L1 CPU cache reference | 1 ns | 1 second |
| L2 cache reference | 4 ns | 4 seconds |
| Main memory (RAM) reference | 100 ns | under 2 minutes |
| Read 1 MB sequentially from RAM | 10 µs | about 3 hours |
| Random 4 KB read from an NVMe SSD | 20 to 100 µs | 6 to 28 hours |
| Round trip inside one data center | 0.5 ms | about 6 days |
| Read 1 MB sequentially from SSD | 0.2 to 1 ms | 2 to 12 days |
| Hard disk seek | 10 ms | about 4 months |
| Round trip US East to US West | 60 to 70 ms | about 2 years |
| Round trip US to Europe | 80 to 100 ms | about 3 years |
| Round trip US to Australia | 150 to 200 ms | about 5 to 6 years |
(1 ms = 1,000 µs = 1,000,000 ns.)
Three lessons fall out of this table. Memory is about 1,000 times faster than an SSD read, which is why caches exist. The network inside a data center is fast enough that a cache on another machine still beats a local disk. And the speed of light is a hard limit: no amount of engineering makes New York to Sydney faster than about 160 ms, which is why CDNs put copies of data near users.
Anything in memory is effectively free next to the network. An in-process cache answers in well under a microsecond.
Order these from fastest to slowest.
- Tap the steps below in the right order.
Where the time goes in one request
Latency adds up along the path a request takes. Step through a typical API call from a user in Europe to servers in the US.
Crossing the Atlantic and back costs about 90 ms. A new HTTPS connection needs extra round trips for the TCP and TLS handshakes, so the first request can cost 200+ ms.
From daily users to QPS
Interviewers give you users; you turn them into requests per second. A day has 86,400 seconds, which you can round to 100,000 for quick math (it makes the answer about 15% low, which is fine).
The handy rule: 1 million requests per day ≈ 12 QPS.
- Start with DAU (daily active users).
- Multiply by actions per user per day to get requests per day.
- Divide by 86,400 to get average QPS.
- Multiply by a peak factor (2 to 3 for most apps, more for event-driven spikes like ticket sales) to get peak QPS.
- Split reads from writes. Most consumer apps are read-heavy, often 10:1 to 100:1.
10 million users each post twice a day. What is the average write QPS (integer division)?
print(10_000_000 * 2 // 86_400)
Storage and bandwidth
Storage per year = writes per day × bytes per write × 365. Then multiply by how many years you keep data and by the number of copies (databases usually keep 3 replicas).
Bandwidth = QPS × bytes per response. Ingress is data coming in (uploads); egress is data going out (downloads), and egress is what cloud providers charge for.
A worked example
A text-and-photo social app with 20 million DAU. Each user loads their feed 20 times a day and posts 0.5 times a day. A post's text and metadata is about 1 KB, and 10% of posts include a 300 KB photo.
| Quantity | Math | Result |
|---|---|---|
| Writes per day | 20M × 0.5 | 10 million |
| Average write QPS | 10M ÷ 86,400 | about 116 |
| Reads per day | 20M × 20 | 400 million |
| Average read QPS | 400M ÷ 86,400 | about 4,600 |
| Peak read QPS (3x) | 4,600 × 3 | about 14,000 |
| Text storage per year | 10M × 1 KB × 365 | about 3.65 TB |
| Photo storage per year | 1M × 300 KB × 365 | about 110 TB |
| Feed egress (20 posts × 1 KB) | 4,600 × 20 KB | about 92 MB/s |
What the numbers tell you: writes are tiny, so one database primary is enough for posts. Reads are 40 times larger, so caching and read replicas matter. Photos are 30 times bigger than everything else, so they belong in object storage behind a CDN, never in the database.
Run the calculator, then change the inputs to match your own idea.
Press Run (⌘ Enter) to see what happens.- DAU
- Daily active users. The starting point for most traffic estimates.
- QPS
- Queries (requests) per second. 1 million requests a day is about 12 QPS.
- peak factor
- How much busier the busiest moment is than the average, usually 2 to 3x.
- read:write ratio
- How many reads happen per write. Read-heavy systems (10:1 or more) benefit most from caches and replicas.
- egress
- Data leaving your servers to users. Usually the bandwidth you pay for.
- latency ladder
- Cache ≈ 1 ns, RAM ≈ 100 ns, SSD ≈ 100 µs, same data center ≈ 0.5 ms, cross-continent ≈ 100+ ms.