Skip to main content

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โ€‹

UnitExactApproximationExample
1 KB1,000 bytes10^3Short email
1 MB1,000,000 bytes10^6High-res photo
1 GB1,000,000,000 bytes10^91 hour HD video
1 TB10^12 bytes1000 GB1 million books
1 PB10^15 bytes1000 TBGoogle search index

Time Unitsโ€‹

UnitSecondsApproximationUse Case
1 day86,400~10^5 (100K)Daily active users
1 month2,592,000~2.5MMonthly billing
1 year31,536,000~30MAnnual storage
Interview Tip

Key approximation: 1 day โ‰ˆ 10^5 seconds. This simplifies almost every calculation.

Latency Numbersโ€‹

OperationLatencySimplified
RAM access100 ns~100 ns
SSD read (sequential)1 ยตs~1 ยตs
Network within datacenter0.5 ms~1 ms
HDD seek10 ms~10 ms
Network round trip (same continent)50 ms~50 ms
Intercontinental network150 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