Skip to the content

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

FactValue
Seconds in a day86,400 (round to 100,000 = 10^5)
Seconds in a monthabout 2.6 million
Requests per day → per secondDivide by 10^5: 1 million a day is about 10 per second (exactly 11.6)
Peak trafficAssume 2 to 3 times the average (more for events)
1 KB, 1 MB, 1 GB, 1 TB, 1 PB10^3, 10^6, 10^9, 10^12, 10^15 bytes (decimal approximation)
A character of textabout 1 byte (ASCII)
A typical small JSON record0.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

  1. Daily active users (DAU) × actions per user per day = actions per day.
  2. Actions per day ÷ 100,000 ≈ average per second; × 2 or 3 for peak.
  3. Storage = new records per day × record size × days kept (× replication factor, often 3).
  4. 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.

QuantityCalculationResult
Writes per second100,000,000 ÷ (30 × 86,400)about 39 per second (call it 40)
Reads per second40 × 100about 4,000 per second (peak around 10,000)
Links over 5 years100 million × 12 × 56 billion
Storage6 × 10^9 × 500 bytes3 TB (before replication)
Short code lengthBase62 with 7 characters: 62^7about 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.

QuantityCalculationResult
Uploads per day10 million × 0.22 million
Upload rate2,000,000 ÷ 86,400about 23 per second
Photo views per second10 million × 50 ÷ 86,400about 5,800 per second (peak about 15,000)
New storage per day2 million × 500 KB1 TB per day, about 365 TB per year
Outgoing bandwidth5,800 × 500 KBabout 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:

OperationRough time
Read from CPU cache / main memorynanoseconds to about 100 nanoseconds
Read 1 MB sequentially from memorya few microseconds to tens of microseconds
Random read from an SSDabout 100 microseconds
Round trip within one data centreabout 0.5 milliseconds
Redis GET over the networkunder 1 millisecond
Indexed database query1 to 10 milliseconds
Round trip London to New Yorkabout 70 to 80 milliseconds
Round trip London to Sydneyabout 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

WordMeaning
Back-of-envelope estimateA quick rough calculation
DAUDaily active users
RPS / QPSRequests / queries per second
Peak factorHow much busier the busiest time is than average
Replication factorHow many copies of data are stored

Now prove it

This lesson is complete when you pass the quiz and all three practice levels.