System Design · Lesson 03

Napkin Math: Back-of-the-Envelope Estimation

Before I size a service, I do the math on a napkin. No spreadsheet, no capacity planning tool. Just users, requests, storage, and machines, one multiplication at a time. This lesson sizes one photo service end to end, from one million daily users to eight servers. The numbers are a worked example. The method is the part that transfers to every launch you will ever size.

Difficulty: Beginner · Know this first: Lesson 01, Lesson 02

Run it as:

When it breaks, I check

One thing to remember

Where a day's requests go

Requests are not all the same kind, and the mix is where the money hides. The bar below breaks one day of traffic into reads, photo uploads, and small writes. The numbers are a worked example for this lesson's scenario, not a measurement from a live system. Notice the smallest slice. Photo uploads are one percent of the requests and nearly all of the storage. Step through the lesson or switch the scenario and watch the mix move.

Try the numbers yourself

The worked example above uses my numbers. Move the sliders and run your numbers through the same chain. Nothing here is a guess dressed up as a tool. It is the same four multiplications from the steps, and you can watch every answer move when one input moves.

Fixed assumptions: 90/10 read/write split, one write in ten is a photo, 2 MB photo, 1 KB small write, 200 KB read response, 500 req/sec per server, +2 spares.

Total requests/day

100M

Average QPS

about 1,000

Peak QPS

about 3,000

Storage/day

2 TB

about 60 TB/month, about 730 TB/year

Bandwidth out

18 TB/day

about 1.7 Gbps average, about 5 Gbps at peak

Servers needed

8

6 for peak load + 2 spare

How this is calculated

  • total requests/day = daily active users × requests per user per day
  • average QPS = total requests/day divided by 100,000 (a day rounded to 100,000 seconds; exact division by 86,400 gives about 1,150 at the defaults, the simulator shows the rounded napkin number, about 1,000)
  • peak QPS = average QPS × peak factor
  • reads/day = total requests/day × 90 percent; writes/day = total × 10 percent
  • photo uploads/day = writes/day divided by 10 (one write in ten is a photo)
  • storage/day = photo uploads/day × 2 MB (small writes add about 9 GB/day at the defaults, shown as negligible)
  • bandwidth out/day = reads/day × 200 KB; average Gbps = that total spread over 86,400 seconds, times 8 bits per byte; peak Gbps = average Gbps × peak factor
  • bandwidth in/day = photo uploads/day × 2 MB
  • servers for load = peak QPS divided by 500, rounded up; total servers = servers for load + 2 spares

Check yourself

Three questions. No score is saved anywhere, this is just you against the material.

Go deeper

The rounding is a choice, not a mistake

I round 86,400 seconds to 100,000 on purpose. It buys me speed and it costs me about 15 percent. That trade is fine when I am comparing options or checking whether a plan is sane. It is not fine when the margin is thin. If my estimate says I need 6 servers and I can only afford 7, the rounding error matters, and I redo the step with 86,400. The rule I use: round while you are exploring, use the real number when you are about to spend money or sign a launch date.

The four assumptions that break first

Every bad estimate I have seen broke on one of these four, and the estimate itself was fine. The user count was wrong because launch beat the forecast, or the forecast was a hope. The requests per user were wrong because a new feature added background calls nobody counted. The average object size was wrong because users upload originals and the estimate assumed compressed thumbnails. The peak factor was wrong because a launch landed on a holiday evening or a sports final. I catch each one the same way: I measure it from the running system every week and I compare it with the number I wrote down. The assumption that moves the most is the one I watch.

What changes at 10x and 100x

At 10x the math still works. The shape of the answers changes. Storage stops being a disk order and becomes a retention policy with tiers: hot for this month, cold for the rest, delete dates written down before launch. Bandwidth stops being a pipe order and becomes a CDN decision. Servers stop being a fixed count and become autoscaling with a load test at real peak shape, not at average. At 100x, napkin math stops being the plan. It becomes the first page. What replaces it is measured per endpoint request rates from the logs, a load test that replays real traffic shape, a capacity model per tier (app, cache, database, storage), a storage growth forecast with retention in it, and a cost model the finance team has seen. The napkin still opens the conversation. It no longer closes it.

The whole lesson as a script

I keep a version of this chain in a file, because an estimate I can re-run is an estimate I can defend. Same numbers as the worked example. Change the three inputs at the top and the answers follow.

# napkin.py — the whole lesson in a few lines
dau = 1_000_000          # daily active users
req_per_user = 100       # requests per user per day
peak_factor = 3          # evening peak vs daily average

total = dau * req_per_user
avg_qps = total // 100_000        # 86,400 seconds, rounded to 100,000
peak_qps = avg_qps * peak_factor
reads = total * 9 // 10
uploads = total // 100            # one write in ten is a photo
storage_tb_day = uploads * 2 // 1_000_000  # 2 MB each
servers = -(-peak_qps // 500) + 2          # round up, then 2 spares

print(f"{total:,} requests/day, {avg_qps:,} avg QPS, {peak_qps:,} peak QPS")
print(f"{storage_tb_day} TB/day storage, {servers} servers")

One time it broke

What broke

I sized storage for a photo service on a 2 MB average photo. That number came from my own phone, from a compressed photo I had just taken. The real average after launch was about 6 MB. The app uploaded originals on wifi, and the thumbnail pipeline kept the original as well as the thumbnail. Storage grew at 6 TB a day instead of 2. Nobody noticed for five weeks because the dashboard showed request counts, and the upload count matched the estimate exactly.

Timeline

  • Week 0: the estimate was signed off. 2 MB average written down, 90 day retention, disks bought for one year.
  • Week 3: upload count matched the estimate. Nobody checked average object size, because the count looked right.
  • Week 5, Friday: disk usage crossed 85 percent. The alert fired. The on-call assumed the retention job was behind and left it for Monday.
  • Saturday, 2 AM: the retention job ran and freed almost nothing, because the originals were the retention job's input, not its target.
  • Saturday, 3 AM: uploads started failing when the volume hit 100 percent. Users saw failed uploads on a Saturday morning.
  • Saturday morning: I capped uploads to compressed sizes, raised the alarm threshold, and bought emergency capacity.
  • Monday: the estimate was redone with a measured 6 MB average. The one year disk plan became a four month plan.

What changed after

Three rules, and I still use all three. First, average object size is a measured number from the bucket, checked every week, never a guess from my phone. Second, storage alarms fire at 70 percent, not 85, and they page a human. Third, the retention policy is written before launch, with the numbers in it, and the disk order follows the retention math, not the other way round.

If you remember nothing else

Try it yourself: size this one

Size the storage for a group chat app. 10 million daily users. Each user sends 20 messages a day. One message in 50 carries a photo, average 1 MB. Messages are kept for one year. How much storage do you need, and what do you ask before you trust the answer?

Clarifying questions to ask first

Is 20 messages per user the average or the heavy user? Do photos stay at full size or get compressed on upload? Is a group photo stored once per group or once per recipient? Is retention one year from send, or one year from last read? Are deleted messages really deleted, or just hidden?

Rough sizing

Total messages are 10 million users times 20, which is 200 million a day. Photos are 200 million divided by 50, which is 4 million a day. Storage is 4 million times 1 MB, which is 4 TB a day. Text is tiny next to that, so I call it negligible. One year is 4 TB times 365, about 1.5 PB. Call it 1.5 PB before replication.

Trade-offs to name

Replication doubles or triples that number, so say whether your answer is raw or replicated. Storing one copy per group instead of one per recipient changes it by a lot. Compression changes the photo average, and the photo average is the whole answer. Retention is a product decision, not an engineering one, and it moves the total more than any other input.

Next in this series
Lesson 04 — Vertical vs Horizontal Scaling
Coming next