Lesson 2 of 15 Foundations

Back-of-the-Envelope Estimation

Estimate QPS, storage, bandwidth and server counts in minutes. Powers of two, latency numbers and a worked URL shortener example in Python.

30-40 min beginner 0/15 lessons done
Course contents Lesson 2 of 15 · 0 done
On this page (8 sections)
  1. What you will learn
  2. Numbers to keep in your head
  3. The method
  4. Worked example: URL shortener
  5. Tips
  6. Key takeaways
  7. Exercises
  8. Quiz

What you will learn

  • The handful of numbers worth memorising.
  • How to go from “daily users” to requests per second, storage and bandwidth.
  • How to turn those into rough server and shard counts.
  • A tiny Python calculator you can adapt.

Numbers to keep in your head

Time. A day has 86,400 seconds; round it to 100,000 (10^5) for mental maths. So 1 million requests a day is about 12 per second, and 1 billion a day is about 12,000 per second.

Sizes.

PowerApprox.Name
2^101 thousandKB
2^201 millionMB
2^301 billionGB
2^401 trillionTB
2^501 quadrillionPB

Latency, roughly (orders of magnitude are what matter):

OperationTime
Read from memory (RAM)~100 ns
Read 1 MB sequentially from RAM~10–50 µs
SSD random read~100 µs
Round trip inside one data centre~0.5 ms
Read 1 MB sequentially from SSD~1 ms
HDD seek~5–10 ms
Round trip between continents~100–150 ms

Lessons from the table: memory is about 1,000x faster than SSD for random access, and crossing an ocean costs more than almost anything you do inside a data centre. That’s why caches and CDNs exist.

What one machine can do (very roughly): a well-tuned web server handles thousands of simple requests per second; a single relational database handles thousands to tens of thousands of simple queries per second; a single Redis instance handles around 100k operations per second.

The method

  1. Start from users. Daily active users (DAU) × actions per user per day = requests per day.
  2. Per second. Divide by 10^5. Multiply by 2–5 for the peak.
  3. Read/write split. Most consumer products are read-heavy (10:1 to 100:1 or more).
  4. Storage. New records per day × bytes per record × retention days. Add replication (×3 is common).
  5. Bandwidth. Requests per second × bytes per response.
  6. Servers. Peak QPS ÷ QPS per server, plus headroom.

Worked example: URL shortener

Assume 100 million new links a day, 100 reads (redirects) per write, 500 bytes per record, kept for 5 years.

"""Back-of-the-envelope estimates for a URL shortener."""

SECONDS_PER_DAY = 86_400


def estimate(new_urls_per_day: int, read_write_ratio: int, bytes_per_record: int, years: int) -> dict:
    writes_per_sec = new_urls_per_day / SECONDS_PER_DAY
    reads_per_sec = writes_per_sec * read_write_ratio
    total_records = new_urls_per_day * 365 * years
    storage_bytes = total_records * bytes_per_record
    return {
        "writes/s (avg)": round(writes_per_sec),
        "reads/s (avg)": round(reads_per_sec),
        "reads/s (peak, x3)": round(reads_per_sec * 3),
        "records": total_records,
        "storage (TB)": round(storage_bytes / 1e12, 2),
    }


if __name__ == "__main__":
    # 100 million new short links a day, 100 reads per write, ~500 bytes each, kept 5 years
    for name, value in estimate(100_000_000, 100, 500, 5).items():
        print(f"{name:>20}: {value:,}")
      writes/s (avg): 1,157
       reads/s (avg): 115,741
  reads/s (peak, x3): 347,222
             records: 182,500,000,000
        storage (TB): 91.25

What these numbers tell us:

  • ~350k reads/s at peak is far beyond one database. We need a cache in front (a hot link is read millions of times) and many app servers behind a load balancer.
  • ~1.2k writes/s is modest. Generating unique codes is a design question, not a throughput problem.
  • ~91 TB (before replication) won’t fit on one machine. We’ll need to shard the data, which lesson 6 covers.
  • 182 billion codes fit in 7 base62 characters (62^7 ≈ 3.5 trillion), which shapes the code format in the URL shortener case study.

Tips

  • Round aggressively and say so. “About 1,000 writes per second” is better than 1,157.31.
  • Write the numbers down where you can see them; refer back when you choose components.
  • Sanity-check against known systems. If your estimate says a chat app needs a million servers, re-check your units.

Key takeaways

  • 1 day ≈ 10^5 seconds; 1M/day ≈ 12/s.
  • Memory ≈ 100 ns, SSD ≈ 100 µs, same-DC round trip ≈ 0.5 ms, cross-continent ≈ 100+ ms.
  • Go users → requests/day → QPS (avg and peak) → storage → bandwidth → servers.
  • Estimates exist to drive decisions: caching, sharding, number of machines.

Exercises

  1. Estimate peak QPS and 5-year storage for a photo-sharing app with 50M DAU, 2 uploads per user per day (2 MB each) and 30 views per user per day.
  2. Adapt estimate.py to include bandwidth (bytes per response) and replication factor.
  3. A chat app has 20M DAU sending 40 messages a day of 100 bytes each. How much message storage does a year need, with 3 replicas?

Quiz

  1. Roughly how many requests per second is 500 million requests per day?
  2. Which is faster: reading 1 MB sequentially from SSD, or one round trip from India to the US?
  3. Why do we multiply average QPS by a peak factor?
Show answers
  1. About 5,000–6,000 per second (500M ÷ 86,400 ≈ 5,800).
  2. Reading 1 MB from SSD (~1 ms) is far faster than an intercontinental round trip (~150+ ms).
  3. Traffic isn’t flat: daily peaks and events can be several times the average, and the system must survive the peak.

Finished this lesson?

Mark it complete to track your progress (saved in this browser).