Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 65 ยท Thinking in Systems

Capacity Estimation and Back-of-the-Envelope Math

Estimate requests per second, storage, bandwidth and server counts with powers of two, latency numbers and a reusable Python estimator.

Before choosing a database or a number of servers, you need to know roughly how big the problem is. Is it 10 requests per second or 100,000? Is the data 5 GB or 5 PB? The answer changes everything, and getting it within a factor of two or three is usually enough. This skill is called capacity estimation, or back-of-the-envelope math.

The goal is not precision. It is to find the order of magnitude and to expose which resource (CPU, memory, disk, network) will hurt first. A rough estimate made in five minutes beats an exact one that arrives after the design is chosen.

Numbers worth memorizing

Estimation is much easier when a few constants live in your head.

Powers of two and ten

Power Approx. value Name
2^10 1 thousand (1,024) 1 KB
2^20 1 million 1 MB
2^30 1 billion 1 GB
2^40 1 trillion 1 TB
2^50 1 quadrillion 1 PB

Time

  • A day has about 86,400 seconds; round it to 100,000 for quick math.
  • A month is about 2.5 million seconds; a year about 31 million.
  • So 1 million requests per day is about 12 requests per second (1,000,000 / 86,400).

Latency numbers (approximate, order of magnitude)

Operation Time
Read from CPU cache ~1 ns
Read from RAM ~100 ns
Read 1 MB sequentially from RAM ~10 to 50 microseconds
SSD random read ~100 microseconds
Round trip inside one data center ~0.5 ms
Read 1 MB sequentially from SSD ~0.2 to 1 ms
Disk seek (spinning disk) ~5 to 10 ms
Round trip across a continent ~50 to 100 ms
Round trip between continents ~100 to 200 ms

Memory is thousands of times faster than disk, and the network between continents is slower than almost anything local. That is why caches and CDNs exist.

The estimation recipe

Estimate in five steps

  1. Users
Total and daily active users.
  1. Actions
Requests per user per day.
  1. Rates
Average and peak per second.
  1. Storage
Bytes per item times items.

Then bandwidth and servers.

1 / 2
  1. Users: total users, and daily active users (DAU). Say 100 million total, 20 million DAU.
  2. Actions per user per day: for each feature, how often does a user read or write? A user might view 20 pages and post 0.1 times.
  3. Requests per second (RPS): total requests per day divided by 86,400. Then multiply by a peak factor (often 2 to 5) to get peak RPS.
  4. Storage: bytes per record times records per day times retention (also include replicas: usually 3 copies).
  5. Bandwidth: bytes per request times RPS, for ingress and egress separately.
  6. Servers: peak RPS divided by what one server can handle (measure or assume), plus headroom.

A worked example: a photo-sharing service

Assume 20 million daily active users. Each views 30 photos and uploads 0.2 photos a day. An average photo is 2 MB after compression; metadata per photo is 1 KB.

  • Reads: 20M x 30 = 600M views/day, about 7,000 RPS average, say 20,000 RPS at peak.
  • Writes: 20M x 0.2 = 4M uploads/day, about 46 RPS average. The read-to-write ratio is 150:1, so this is a heavily read-oriented system (caches and a CDN will matter).
  • Storage per day: 4M x 2 MB = 8 TB of photos per day, about 2.9 PB a year, before replicas. Metadata is only 4 GB a day, tiny by comparison.
  • Outbound bandwidth: 7,000 views/s x 2 MB = 14 GB/s, about 112 Gbit/s on average. No single server or link handles that; this must come from a CDN.

Notice how the estimate tells you the design: photos need object storage and a CDN; metadata fits in a replicated database; uploads are low-rate and can use ordinary servers.

Turning math into code

A short script keeps the arithmetic honest and lets you change assumptions. The estimator below prints the same quantities as the worked example.

Python Photo service capacity estimator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Change dau, peak_factor or photo_bytes and watch which line explodes. If you halve the photo size with better compression, the egress and storage halve too, so a small engineering change can save millions.

From RPS to number of servers

Suppose one application server handles about 500 requests per second with acceptable latency (measure this with a load test; never guess in production). With a peak of 20,000 RPS you need 40 servers at 100% utilization. Nobody runs at 100%: keep headroom (target 50 to 70% utilization) so spikes and a failed server do not cause an outage.

Python How many servers do I need?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The spare server is the N+1 rule: if one machine dies the rest still carry the peak. In multi-zone designs you may keep N+2 or enough to survive a whole zone going offline.

Memory and cache sizing

A very useful trick is the 80/20 rule: roughly 20% of the items get 80% of the reads. If you can cache the hot 20%, most requests never hit the database. For 4M new photo records a day with 1 KB of metadata, caching the last week of metadata for 28M items needs about 28 GB, which fits comfortably in a few cache servers. Estimates like this turn "should we add a cache?" into "yes, and it needs about 30 GB".

Common mistakes

  • False precision. Writing 6,944.44 RPS suggests an accuracy you do not have. Say "about 7,000".
  • Forgetting peaks. Traffic is not flat; evening or event peaks decide your capacity.
  • Forgetting replication, indexes and overhead. Real storage is two to four times the raw data.
  • Mixing bits and bytes. Network speeds are quoted in bits per second; storage in bytes (divide Gbit by 8).
  • Ignoring growth. Estimate today, next year and three years out.

Next, scalability describes how to add the capacity your estimate says you need.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Roughly how many requests per second is 1 million requests per day?

    1,000,000 divided by 86,400 seconds is about 11.6, so roughly 12 per second.
  2. 2. Why do we multiply average RPS by a peak factor?

    A system sized for the average fails at the evening or event peak.
  3. 3. What does the N+1 rule add to a server count?

    Spare capacity keeps the system within its limits during a single failure.
  4. 4. A service shows 14 GB/s of outbound image traffic. What does this suggest?

    No single origin handles that bandwidth, so cacheable media must be served from edge locations.
  5. 5. Which is the best way to report an estimate?

    One significant digit communicates the right level of confidence.

Summary

  • Capacity estimation finds the order of magnitude of requests, storage, bandwidth and servers.
  • Memorize powers of two, 86,400 seconds per day, and the rough latency ladder.
  • Follow the recipe: users, actions, RPS, peak, storage, bandwidth, servers.
  • Keep headroom and an N+1 spare; count replicas and overhead.
  • The numbers point to the design: they reveal whether you need a CDN, a cache or sharding.

Next: Scalability: Vertical and Horizontal