SteelReed

Search

Search posts, questions…

7. System Design

Back-of-the-envelope estimation: numbers to know and how to calculate fast

What estimation is for in system design, the numbers to memorise (seconds per day, data type sizes, the availability nines, latencies), grouping powers of ten, Little's Law, the rule of 72, and the URL shortener redone step by step with the places where it's easy to overestimate, then using the numbers to decide on servers, caching and sharding.

18 Nov 20269 min readMid

–

Estimation turns "a big system" into "100 writes and 10K reads per second, 50 TB over 4 years". This post collects the numbers worth memorising, mental-math tricks, and redoes the URL shortener to show which decision each number leads to. Read the system design interview process first.

1. The problem

A team sizes a URL shortener for 10K read QPS and picks 2 instances and one database. The campaign peak is 30K QPS. On the first night the connection pool drains and p99 hits 8 seconds; they had sized for the average.

2. Key idea

Shopping for a wedding, you don't count grains of rice, but you must know whether it's 300 or 3,000 guests: a restaurant or a marquee. Estimation doesn't give the exact number; it gives the right order of magnitude for expensive decisions.

Numbers to memorize Value for mental math
Seconds in a day / a year 10⁵ / 3 × 10⁷
1 million / 1 billion events per day ~12 / ~12K per second
int / long, timestamp / UUID 4 / 8 / 16 bytes
99.9% / 99.99% / 99.999% availability ~8.8 hours / ~52 minutes / ~5 minutes down per year
K, M, G, T, P 10³, 10⁶, 10⁹, 10¹², 10¹⁵ (M × K = G)

2.1 Quick-math tricks

  • Convert to per second first, then derive storage and bandwidth.
  • Multiply by the peak factor: rush hour 2–3×, flash sales 10–100×.
  • Missing data? Assume and say it: "assume each record is 1 KB".
  • Little's Law L = λ × W: 2,000 queries/s × 5 ms = 10 in flight; latency at 50 ms means 100 connections.

2.2 From numbers to decisions

Number (URL shortener) Decision
30K read QPS at peak a 90% Redis hit rate leaves ~3K QPS; one primary + 1–2 replicas
300 write TPS one primary database is plenty; no sharding needed for writes
~50 TB after 4 years (3 replicas included) the real reason to split data
30K × 20 ms = 600 concurrent requests 100 per instance → 6, plus headroom → 7–8 instances

Overestimate what's hard to change (shard keys, code length); estimate tightly what's easy to add (stateless instances, cache nodes).

3. In Java

JAVA
long writesPerDay   = 10_000_000L;
long secondsPerDay  = 100_000L;                          // rounded from 86,400
long writeQps       = writesPerDay / secondsPerDay;      // 100
long readQpsPeak    = writeQps * 100 * 3;                // read:write 100:1, peak x3 = 30,000
long recordBytes    = 1_100;                             // 1 KB URL + code + user_id + 3 timestamps
long storageBytes   = recordBytes * writesPerDay * 365 * 4 * 3;  // 4 years, 3 replicas ≈ 48 TB
double latencySec   = 0.020;
double inFlight     = readQpsPeak * latencySec;          // Little's Law: 600 concurrent requests
long instances      = (long) Math.ceil(inFlight / 100) + 1;     // 100 per instance + 1 spare = 7
double codes        = Math.pow(62, 7);                   // 3.5 × 10¹²: 7 base62 chars is plenty

Other languages: the math is identical; what matters is units in the variable names.

Latencies worth memorizing
Operation Order of magnitude
L1 cache read ~1 ns
RAM read ~100 ns
Random 4 KB read from NVMe SSD ~10–100 µs
Round trip within a datacenter ~0.5 ms
Simple indexed PostgreSQL query ~1 ms
Round trip Hanoi – Singapore ~30–50 ms

CPU-bound work: threads ≈ cores. I/O-bound work: threads ≈ cores × (1 + wait time / compute time), which is Little's Law applied to one CPU.

4. Working with AI

Give the AI: building the estimation table from your assumptions, checking power-of-ten arithmetic, unit conversions.

Check in the AI's estimate:

  • Every number has a unit; no mixing KB with MB, bits with bytes.
  • There's a peak factor, not just averages.
  • Assumptions are explicit (record size, read:write ratio, retention).
  • Each number leads to a concrete decision.

5. Exercises

Exercise 1: Driver locations

500K drivers online at peak, each sending a location every 4 seconds (lat, lng, timestamp, id). Compute write QPS, inbound bandwidth, and storage for 30 days of history. The AI suggests "write straight into PostgreSQL". What do you think?

Solution to Exercise 1
  • Write QPS: 5 × 10⁵ ÷ 4 = 125K/s at peak.
  • One record: 4 fields × 8 B = 32 B; the actual packet ~200 B.
  • Inbound bandwidth: 125K × 200 B = 25 MB/s.
  • 30 days: average ~1/3 of peak → ~40K/s × 10⁵ × 30 × 32 B ≈ 3.5–4 TB, before indexes and replicas.

125K writes/s far exceeds one PostgreSQL. Split it: current location in Redis (GEO), overwritten; history through Kafka, batch-written to an analytics store. The transactional database only receives business events like "picked up".

Exercise 2: Connection pool size

1,500 requests/s at peak, 2 queries per request, p50 = 4 ms, p99 = 40 ms, 6 instances. How big is each instance's pool?

Solution to Exercise 2
  • λ = 1,500 × 2 = 3,000 queries/s across the cluster.
  • At p50: 3,000 × 0.004 = 12 busy connections; at p99: 3,000 × 0.04 = 120.
  • Across 6 instances: 2 to 20 each. Choose 10–15, with a connection-acquire timeout of a few hundred ms to fail fast.
  • Database side: 6 × 15 = 90, close to PostgreSQL's default max_connections of 100; more instances need PgBouncer.

Summary

  • 1 day ≈ 10⁵ seconds; 1 million/day ≈ 12/second.
  • Always apply a peak factor; never design for the average.
  • Little's Law gives connections, threads, instances.
  • Write units next to every number and state assumptions.
  • Overestimate what's hard to change, estimate tightly what's easy to add.

Read more: Designing a URL shortener.

Practice interview questions on this topic

All System Design questions →All AI & LLM questions →

Loading comments…
Next on the roadmapDesign principles: CAP, PACELC, scalability, performance and availability