Back-of-the-envelope maths
- Lesson 3 of 40
- 10 min
- Beginner
- 9 steps
Before choosing technology, work out the scale. A few rough sums tell you whether you need one server or a hundred, and how many terabytes.
- Daily users
- 10M
- Average
- 2,300 req/s
- Peak
- 7,000 req/s
- Servers
- 10
- Storage / year
- 730 TB
- request
- response
- waiting in queue
Step 1 of 9
Problem
Is one server enough?
You are asked to design a photo-sharing app. Before choosing any technology you need the scale: are we talking about one server or a hundred?
You do not need exact numbers, only the right order of magnitude. A few sums that fit on a napkin get you there in minutes.
Step 2 of 9
Technique
From daily users to requests per second
Start with what you know: how many users there are and how much they do. 10M users × 20 requests = 200M requests a day.
A day has 86,400 seconds; round it to 100,000. On a napkin speed matters, not decimals: 200M ÷ 100,000 ≈ 2,000, and the exact sum gives about 2,300 req/s.
What changed
- Average load ≈ 2,300 req/s
Step 3 of 9
Concept
Size for the peak, not the average
Traffic is not flat: people use the app in the evening and it spikes with any event. A typical peak is 2 to 3 times the daily average.
At 3× that is about 7,000 req/s, and a single server is clearly overwhelmed.
What changed
- Peak ≈ 3 × average ≈ 7,000 req/s
- One server: overwhelmed
Step 4 of 9
Solution
How many servers?
A load test says one server handles about 1,000 req/s. The peak is 7,000, so we need 7, plus headroom for bursts and for when one goes down.
Call it 10. Notice the starting figure is a measurement, not a guess.
What changed
- Web tier: 10 servers
- Each one at ~70% at peak
Step 5 of 9
Technique
How much storage?
Photos are what weighs most: 1M uploads × 2 MB = 2 TB a day, about 730 TB a year.
Data is usually stored three times so a dead disk loses nothing, so plan for about 2 PB in the first year. That rules out «a single database» straight away.
What changed
- Storage tier
- 2 TB/day → ~730 TB/year
- × 3 copies → ~2 PB
Step 6 of 9
Technique
How much bandwidth?
Uploading is the small part: 2 TB a day is about 20 MB/s in. Viewing is the big one: if each user views 100 photos a day as 200 KB thumbnails, that is 200 TB a day.
200 TB ÷ 100,000 s ≈ 2 GB/s, about 16 Gbit/s on average and more at peak. That is a job for a CDN, not for ten web servers.
What changed
- The CDN serves the images
- Egress ≈ 16 Gbit/s on average
Step 7 of 9
Technique
Does it fit in memory?
Feeds keep reading photo metadata and profiles. Does the hot part fit in a cache? Profiles: 10M × 2 KB = 20 GB. Today's new photos: 1M × 1 KB = 1 GB.
About 21 GB: it fits in the memory of a single cache server (plus a second one in case it fails). Nothing exotic needed.
What changed
- Cache ≈ 21 GB in RAM
Step 8 of 9
Concept
Numbers worth knowing
A handful of numbers lets you estimate almost anything. Learn the order of magnitude, not the decimals:
Read from memory: ~100 ns · Read from an SSD: ~100 µs · Round trip within a data centre: ~0.5 ms · Round trip across an ocean: 75–150 ms · Seconds in a day: ~100,000.
Step 9 of 9
Summary
Summary
Users × actions ÷ 100,000 s = average requests per second.
Multiply by 2–3 for the peak and size for that.
Servers = peak ÷ measured capacity of one, plus headroom.
Storage = items a day × size × 365 × copies.
Also estimate outgoing bytes and memory: they often decide the design.
← → step · R replay · Space pause
You will learn
- Go from daily users to requests per second (covered)
- Size for the peak, not the average (covered)
- Work out servers from a measurement (covered)
- Estimate storage, bandwidth and memory (covered)
- Reference numbers for estimating (covered)