Skip to content
Tutorials Center
My learning

Topics

Lesson 61 of 65 ยท Projects

Project: A Capacity Planner

Build a capacity planning calculator in Python: traffic, bandwidth, storage and server counts from a few assumptions, with growth, replication, peaks and a what-if table.

Every design review starts with numbers: how many requests, how much data, how many machines? Getting these roughly right, quickly, is a core skill. In this project you will build a small capacity planner. You feed it a handful of assumptions (users, actions per user, object sizes, retention) and it prints requests per second, bandwidth, storage over several years, cache size and the number of servers. Then you run what-if scenarios.

The point is not precision. A planner is correct if it is right within a factor of two and makes your assumptions explicit so others can challenge them.

Rules of thumb to build in

  • A day has 86,400 seconds, close enough to 100,000 for mental math. A month is about 2.5 million seconds; a year is about 31.5 million.
  • Peak traffic is typically 2 to 5 times the average. Plan for the peak, not the average.
  • Read:write ratios vary widely: social feeds are 100:1, chat is near 1:1, logging is almost all writes.
  • A single modern web server handles roughly 1,000 to 10,000 simple requests per second; a database node roughly 1,000 to 10,000 queries per second depending on the query.
  • Replication multiplies storage by the number of copies (usually 3).
  • Reserve headroom: run servers at 50 to 70 percent of capacity so a failure does not overload the rest.

Step 1: traffic and bandwidth

Python From users to requests per second

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.

Ten million users doing twenty actions each is 200 million requests a day, about 2,300 per second on average and 7,000 at peak. The bandwidth line shows why large responses (images, video) dominate network cost much more than request counts.

Step 2: storage over time

Python Storage with replication and growth

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 three multipliers do most of the work: replicas (3), overhead for indexes and free space (1.2), and yearly growth (1.4 per year compounds to about 5.4 times in five years). Forgetting any of them gives an estimate that is too small.

Step 3: cache and servers

A cache pays off when a small fraction of the data serves most of the requests. The classic guideline is the 80/20 rule: caching the hot 20 percent of daily data absorbs about 80 percent of reads.

Python Cache size and number of servers

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.

With an 80 percent cache hit rate, the database sees only a fifth of the read load, which is the number that decides how many database replicas you pay for. Raising the hit rate to 95 percent cuts that load by another factor of four; it is often the cheapest scaling move available.

Step 4: a what-if table

Put the pieces together in one function and compare scenarios. This turns the planner into a conversation tool: "what happens if traffic doubles, or video is added?"

Python What-if scenarios

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.

Notice which numbers jump. Doubling users doubles most lines. Adding video barely changes request rates but multiplies bandwidth and storage by about ten. A better cache barely changes anything except database load, which falls sharply. Each scenario tells you which part of the architecture to worry about.

Ideas to extend it

  1. Add a cost estimate: price per server, per TB stored and per TB of egress, then show monthly cost per scenario.
  2. Model multi-region: split traffic by region and add cross-region replication bandwidth.
  3. Add queue sizing: given a burst of N messages and a worker rate, how long is the backlog?
  4. Add latency budgets: sum network, cache, database and rendering time against a 300 ms target.
  5. Print your assumptions list at the end; hidden assumptions are the main source of bad estimates.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should you plan for peak traffic rather than average?

    Overload happens at the peak, so capacity must cover it with headroom.
  2. 2. Which multipliers commonly inflate raw storage estimates?

    Three copies, extra space for indexes and free space, and yearly growth add up quickly.
  3. 3. A cache raises the hit rate from 80 to 95 percent. What happens to database read load?

    Misses fall from 20 percent to 5 percent, a four times reduction.
  4. 4. Why add one spare server to the computed number?

    N+1 provisioning keeps the system within capacity after a single failure.

Summary

  • Convert users and actions into requests per second, then plan for 2 to 5 times that at peak.
  • Bandwidth and storage come from response and item sizes, multiplied by replicas, overhead and growth.
  • Cache hit rate decides how much load reaches the database.
  • Provision with headroom and one spare, and keep assumptions explicit.
  • A what-if table shows which component each change stresses.

Next: The System Design Interview Framework