Skip to content

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.

15 min read0/4 questions

"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.

PowerExact valueApproxUnit
2^101,024a thousand1 KB
2^201,048,576a million1 MB
2^30about 1.07 billiona billion1 GB
2^40about 1.1 trilliona trillion1 TB
2^50about 1.13 quadrilliona thousand trillion1 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.

OperationRough timeIn "human" terms if L1 = 1 second
L1 CPU cache reference1 ns1 second
L2 cache reference4 ns4 seconds
Main memory (RAM) reference100 nsunder 2 minutes
Read 1 MB sequentially from RAM10 µsabout 3 hours
Random 4 KB read from an NVMe SSD20 to 100 µs6 to 28 hours
Round trip inside one data center0.5 msabout 6 days
Read 1 MB sequentially from SSD0.2 to 1 ms2 to 12 days
Hard disk seek10 msabout 4 months
Round trip US East to US West60 to 70 msabout 2 years
Round trip US to Europe80 to 100 msabout 3 years
Round trip US to Australia150 to 200 msabout 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.

The latency ladder
  1. CPU cache (L1/L2)1 to 4 ns
  2. RAM~100 ns
  3. NVMe SSD random read~20 to 100 µs
  4. Network, same data center~0.5 ms
  5. Spinning disk seek~10 ms
  6. Network, across continents~80 to 200 ms

Anything in memory is effectively free next to the network. An in-process cache answers in well under a microsecond.

1/3
Put it in order5 steps

Order these from fastest to slowest.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

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.

Latency budget of one request
User in ParisUser in ParisLoad balancer: us-east-1Load balancerus-east-1App serverApp serverRedisRedisPostgresPostgres~90 ms RTT~0.5 ms~1 ms~5 ms

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.

1/5
Quick check
A page in Sydney makes 5 API calls one after another to servers in Virginia (about 200 ms round trip each). Roughly how long does the user wait on the network?
Need a nudge? A hint rules out a wrong answer.

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.

  1. Start with DAU (daily active users).
  2. Multiply by actions per user per day to get requests per day.
  3. Divide by 86,400 to get average QPS.
  4. Multiply by a peak factor (2 to 3 for most apps, more for event-driven spikes like ticket sales) to get peak QPS.
  5. Split reads from writes. Most consumer apps are read-heavy, often 10:1 to 100:1.
Predict the outputPython

10 million users each post twice a day. What is the average write QPS (integer division)?

print(10_000_000 * 2 // 86_400)
Need a nudge? Hints walk you through it.

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.

QuantityMathResult
Writes per day20M × 0.510 million
Average write QPS10M ÷ 86,400about 116
Reads per day20M × 20400 million
Average read QPS400M ÷ 86,400about 4,600
Peak read QPS (3x)4,600 × 3about 14,000
Text storage per year10M × 1 KB × 365about 3.65 TB
Photo storage per year1M × 300 KB × 365about 110 TB
Feed egress (20 posts × 1 KB)4,600 × 20 KBabout 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.

Pythonestimate.py
SECONDS_PER_DAY = 86_400 def human(n_bytes: float) -> str: for unit in ["B", "KB", "MB", "GB", "TB", "PB"]: if n_bytes < 1000: return f"{n_bytes:.1f} {unit}" n_bytes /= 1000 return f"{n_bytes:.1f} EB" def estimate(dau, reads_per_user, writes_per_user, bytes_per_write, peak=3, years=5, copies=3): writes_day = dau * writes_per_user reads_day = dau * reads_per_user write_qps = writes_day / SECONDS_PER_DAY read_qps = reads_day / SECONDS_PER_DAY per_year = writes_day * bytes_per_write * 365 print(f"read:write ratio {reads_day / writes_day:.0f}:1") print(f"avg write QPS {write_qps:,.0f} peak {write_qps * peak:,.0f}") print(f"avg read QPS {read_qps:,.0f} peak {read_qps * peak:,.0f}") print(f"storage per year {human(per_year)}") print(f"{years} years x {copies} copies {human(per_year * years * copies)}") estimate(dau=20_000_000, reads_per_user=20, writes_per_user=0.5, bytes_per_write=1_000)
Output
Press Run (⌘ Enter) to see what happens.
Quick check
A chat app stores 5 billion messages a day at about 100 bytes each. Roughly how much new storage per year, before replication?
Need a nudge? A hint rules out a wrong answer.
Key terms
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.