calculate

Back-of-Envelope
Math

In an interview, you don't need a calculator. You need approximations. Is this system handling 100 RPS or 100,000 RPS? The design changes completely.

Powers of Two (The Cheatsheet)

Data Volumes

PowerApproxName
2^101 Thousand1 KB
2^201 Million1 MB
2^301 Billion1 GB
2^401 Trillion1 TB
2^501 Quadrillion1 PB

"If you need to store 1 MB per user for 1 Million users..."

1 MB × 1 M = 1 TB

(2^20 × 2^20 = 2^40)

Standard Numbers

Seconds in a Day

86,400

Round to ~100,000 (10^5) for easy math.

Char Size

2 Bytes

UTF-16 (Java/JS) often uses 2 bytes. ASCII is 1.

UUID Size

16 Bytes

Standard 128-bit identifier.

Long / Int64

8 Bytes

Standard ID size in databases.

Latencies

  • RAM: ~100ns
  • SSD: ~100µs
  • Region Roundtrip: ~150ms

Estimating QPS

Start with DAU (Daily Active Users).

Assumption
10 Million DAU
Usage
5 req / user
Total Daily Requests
50 Million req / day
arrow_downward

Divide by seconds in a day (~10^5)

50,000,000 / 100,000 = 500 QPS

Don't forget Peak QPS

Traffic isn't flat. Usually multiply average by 2x - 5x for peak.

Estimating Storage

The Formula

(Size per entry) × (Entries per day) × (Retention days)

Example: Chat app storing messages for 5 years.

  • Message: 100 Bytes
  • Volume: 50M msgs/day
  • Time: 5 Years (~2000 days)
50M × 100 B = 5 GB / day
5 GB × 2000 days = 10 TB Total

Estimating Bandwidth

Ingress (Incoming)

Uploads, Write requests.

QPS × Request Size

Egress (Outgoing)

Downloads, Read responses. Usually much higher.

QPS × Response Size

Practice: Twitter Feed

Interview Mode

Assumptions

  • • 200M DAU
  • • 5 reads / user / day
  • • 1 write / user / day (tweet)
  • • Tweet size: 1KB (text + metadata)
  • • Media: 1MB (avg)
  • • 10% of tweets have media

Write QPS

200M / 10^5 = 2,000 QPS

Read QPS

1B / 10^5 = 10,000 QPS

Media Storage (Day)

200M tweets × 10% × 1MB
= 20M × 1MB = 20 TB / day