Back-of-Envelope Calculations
TL;DR (30-second summary)โ
In interviews, you'll be asked: "How many servers do we need?" or "How much storage?" Back-of-envelope math helps you estimate quickly without perfect accuracy. Key skill: Round aggressively (1M โ 10^6, 1 day โ 10^5 seconds).
Core formula: Capacity Needed = Traffic ร Resource Per Request
Power of 2 & 10 (Memorize These)โ
Data Volumeโ
| Unit | Exact | Approximation | Example |
|---|---|---|---|
| 1 KB | 1,000 bytes | 10^3 | Short email |
| 1 MB | 1,000,000 bytes | 10^6 | High-res photo |
| 1 GB | 1,000,000,000 bytes | 10^9 | 1 hour HD video |
| 1 TB | 10^12 bytes | 1000 GB | 1 million books |
| 1 PB | 10^15 bytes | 1000 TB | Google search index |
Time Unitsโ
| Unit | Seconds | Approximation | Use Case |
|---|---|---|---|
| 1 day | 86,400 | ~10^5 (100K) | Daily active users |
| 1 month | 2,592,000 | ~2.5M | Monthly billing |
| 1 year | 31,536,000 | ~30M | Annual storage |
Interview Tip
Key approximation: 1 day โ 10^5 seconds. This simplifies almost every calculation.
Latency Numbersโ
| Operation | Latency | Simplified |
|---|---|---|
| RAM access | 100 ns | ~100 ns |
| SSD read (sequential) | 1 ยตs | ~1 ยตs |
| Network within datacenter | 0.5 ms | ~1 ms |
| HDD seek | 10 ms | ~10 ms |
| Network round trip (same continent) | 50 ms | ~50 ms |
| Intercontinental network | 150 ms | ~150 ms |
Estimation Frameworkโ
Step 1: Clarify Scaleโ
- How many users? (DAU - Daily Active Users)
- How many requests per user per day?
- Read-to-write ratio?
Step 2: Estimate QPSโ
Total requests/day = 100M ร 10 = 1 billion requests
Seconds/day โ 10^5 (100K)
Average QPS = 1B / 100K = 10,000 QPS
Peak QPS = 10K ร 3 = 30,000 QPS
Step 3: Calculate Storageโ
Writes/day = 100M users ร 1 post/day = 100M posts
Post size = ~1 KB
Daily storage = 100M ร 1 KB = 100 GB/day
5-year storage = 100 GB ร 365 ร 5 = 183 TB
Step 4: Estimate Bandwidthโ
Read payload = 10 KB (post + user data)
Egress (read) = 9K QPS ร 10 KB = 90 MB/s
Step 5: Determine Serversโ
Peak read QPS = 9K ร 3 = 27K
Servers needed = 27K / 5K = ~6 servers
Add redundancy (N+1): 7 servers
Quick Reference Cardโ
Time conversions:
- 1 day โ 10^5 seconds (100K)
- 1 month โ 2.5M seconds
- 1 year โ 30M seconds
Data sizes:
- Text: ~100 bytes | Tweet: ~1 KB
- Photo: ~200 KB | High-res: ~2 MB
Typical QPS per server:
- Simple API: ~10K QPS
- Database: ~1K QPS
- Complex: ~100 QPS