01. Foundations / Lesson 3 of 3
Napkin Math
Estimate traffic, storage and servers before you design anything.
- 10 min
- Beginner
- 10 steps
- Peak QPS—
- Storage per year—
- App servers—
- Request
- Response
- Write
- Cache hit
Step 1 of 10: Design starts with rough numbers
Read every step as text
Step 1: Design starts with rough numbers
You are asked to design a photo-sharing app for 10 million people a day. How many servers? How many disks? Will one database do? You cannot choose a design until you know the size of the job.
Napkin math means a quick estimate with round numbers, good enough to tell 10 servers from 1,000. It takes five minutes and saves months of building the wrong thing.
You want the right order of magnitude (10, 100, 1,000), not the exact digit.
Step 2: Know the cost of each operation
Some numbers are worth remembering, as round orders of magnitude. A memory read takes about 100 nanoseconds. A random read from an SSD takes about 100 microseconds, 1,000 times slower.
A round trip inside one data centre is about 0.5 ms, a hard-disk seek about 10 ms, and a round trip across an ocean about 100 ms. These figures vary by hardware, but the gaps between them hold.
Memory beats SSD, SSD beats a network call, and a network call beats an ocean. Design to touch the faster ones more.
Step 3: Turn daily users into requests per second
Each of 10 million users reads the feed 20 times a day: 200 million reads. A day has 86,400 seconds (call it ~10^5), so the average is
200M / 86,400 ≈ 2,315reads a second.Writes are rarer: 1 million photos a day is about 12 uploads a second. Reads outnumber writes about 200 to 1.
Trick: 1 million requests a day is about 12 a second. Memorise that and scale from it.
Step 4: Traffic is not flat: design for the peak
People are not evenly spread over 24 hours. Most use the app in a few busy evening hours. A common rule is a peak of 2 to 3 times the average. We take 3.
Peak reads are 2,315 × 3 = 6,944 a second, and peak uploads about 35 a second. We must size for 6,944, because a system built for the average falls over every evening.
Events (a sale, a live match) can spike 10 times or more. Pick the factor for your product and say it out loud.
Step 5: How much data do we keep?
A photo, after compression, is about 300 KB. 1 million photos a day is
1M × 300 KB = 300 GBa day. Text and metadata (a few KB per post) add only about 1 GB, so we ignore them.Over a year that is 300 GB × 365 ≈ 110 TB. We keep 3 copies for safety, so the disks must hold about 329 TB.
Photos and video dominate storage. Count them first; the rest is usually small by comparison.
Step 6: How much data flows out each second?
Say each feed read sends 200 KB (a handful of small images and some text). At the peak, 6,944 reads a second × 200 KB is 1.39 GB a second.
Network speeds are quoted in bits, so multiply by 8: about 11.1 Gbit/s going out. That is more than one 10 Gbit/s link, a sign to serve images from a CDN near users instead of from our own servers.
Bytes versus bits is a classic slip: 1 GB/s is 8 Gbit/s.
Step 7: The 80/20 rule: cache the hot part
A small share of the content gets most of the reads. Assume the hot 20% of each day's photos gets about 80% of the views. That is
20% × 300 GB = 60 GB: it fits in memory on two cache servers with 64 GB each.With an 80% hit rate, the database sees only the other 20%: 6,944 × 0.2 ≈ 1,389 reads a second at the peak, which one good database can serve.
Caching a small slice cuts load a lot. This is the same hit-rate effect you meet in the Caching lesson.
Step 8: How many app servers?
Suppose one app server handles 400 requests a second. We do not run it flat out: at 70% busy it takes 280, which leaves room for bursts and slow moments.
Peak 6,944 / 280 = 24.8, so 25 servers. Add one spare so a single failure does not push the rest over: 26 servers.
Always round up and add a spare. Capacity at 100% means queues and slow p99.
Step 9: Check the answer a second way
Cross-check by another route. Reads: 1 million a day is about 12 a second, so 200 million is about 2,400 a second, close to our 2,315. Storage: 1 million photos at about a third of a megabyte is about 300 GB. Both agree.
Does the size feel right? 26 servers for 10 million daily users, and a few hundred terabytes, is a mid-sized service. If we had got 26,000 servers or 0.3 servers, we would look for a mistake in a power of ten.
The common errors: a missing x1,000 (KB vs MB), bits versus bytes, and forgetting the peak factor.
Step 10: Napkin math in one picture
From 10 million daily users we got 2,315 reads a second on average, 6,944 at the peak, about 110 TB of photos a year, a 60 GB cache and 26 app servers.
The recipe: write down assumptions, use round numbers, convert per day to per second, multiply by a peak factor, count storage and bandwidth, divide by what one machine can do, then check the result a second way.