Lesson 03 of 5 · Requirements and numbers
Estimation and capacity math
Estimate load, storage, bandwidth and fleet size from first principles; use Little's law to turn throughput into concurrency; see why queueing makes latency explode above 80% utilisation; understand tail latency under fan-out; and split a latency budget across a request path. Includes a runnable estimation model with real output.
Forces
Estimation is how an architect decides which problems are real. A design for 300 requests per second and a design for 300,000 are different systems; the second needs partitioning, caching and probably asynchronous ingestion that the first would be over-engineered with. Get the order of magnitude wrong and you either build something that falls over at launch or spend a year on scale you never needed.
The goal is not precision. It is to be right within a factor of two to three, to know which input dominates the answer, and to show your working so others can challenge the inputs rather than the conclusion.
First principles
Numbers worth knowing
Approximate, and they drift with hardware, but the ratios are what matter:
| Operation | Order of magnitude |
|---|---|
| Main memory reference | ~100 ns |
| Read 1 MB sequentially from memory | ~10 µs (tens of GB/s) |
| Random read from NVMe SSD | ~20-100 µs |
| Read 1 MB sequentially from NVMe | ~100-300 µs |
| Round trip within an availability zone | ~0.1-0.5 ms |
| Round trip between zones in a region | ~0.5-2 ms |
| Round trip across a continent | ~30-70 ms |
| Round trip between continents | ~100-250 ms |
| Light in fibre | ~200 km per ms (one way) |
Two consequences you will use constantly. First, a synchronous cross-region call costs more than thousands of local operations, so the topology dominates latency, not the code. Second, the speed of light sets a floor: London to Sydney is about 17,000 km, so even a perfect fibre path is over 80 ms one way.
From users to requests per second
Work in this order, and write each step down:
- Users or tenants × active share = daily active users.
- DAU × actions per user per day = requests per day.
- Requests per day ÷ 86,400 = average requests per second.
- Average × peak factor = peak rps. B2B products concentrate traffic in business hours, often 3-5× the daily average; consumer products have evening peaks; batch and month-end jobs create spikes far above both.
Design for the peak, and state the peak factor as an assumption someone can challenge.
Little's law
For any stable system, L = λ × W: the average number of items in the system equals the arrival rate times the average time each spends there. It holds regardless of distribution, which is why it's so useful. At 11,000 rps with 120 ms in the service, about 1,300 requests are in flight at any moment. That number sizes your thread pools, connection pools and pod count.
Little's law also works backwards: if a database allows 200 connections and each query holds one for 20 ms, the database can serve at most 200 ÷ 0.020 = 10,000 queries per second through that pool, whatever the CPU says.
Utilisation and queueing
A resource with service time S and utilisation ρ (busy fraction) does not slow down linearly. For the simplest queue model (M/M/1: random arrivals, random service times, one server), the mean response time is W = S / (1 − ρ). At 50% busy, requests take twice the service time; at 90%, ten times; at 99%, a hundred times. Real systems with multiple servers behave better than M/M/1, but the curve has the same shape: a knee somewhere around 70-85%, after which small load increases cause large latency increases.
This is why capacity targets are set at 60-75% utilisation, not 95%. The headroom is not waste; it is what keeps latency flat.
Tail latency and fan-out
When one request fans out to many backends and waits for all of them, the slowest one decides. If each backend has a 1% chance of being slow, a request that calls 100 of them sees at least one slow call with probability 1 − 0.99¹⁰⁰ ≈ 63%. Dean and Barroso's "The Tail at Scale" (2013) made this the central problem of large services. Mitigations: hedged requests (send a second copy after the p95 time), tied requests, partial results, and reducing fan-out in the design.
Latency budgets
Start from the user-facing target and subtract. For a 300 ms p99 page:
Budget p99 300 ms (measured at the edge)
TLS + edge + WAF ............. 20 ms
API gateway + auth ........... 15 ms
Application logic ............ 40 ms
Authorisation decision ....... 10 ms
Database (2 queries) ......... 60 ms
Downstream call (one) ........ 80 ms
Serialisation + network ...... 25 ms
Reserve (unknowns, GC) ....... 50 ms
Percentiles don't add up linearly (the p99 of a sum is less than the sum of p99s when components are independent), so a budget built from component p99s is conservative. That is acceptable; it is a planning tool. The value is that every team now has a number, and a downstream call that needs 200 ms is visibly a design problem, not a tuning problem.
Design space
| Lever | Effect | Cost |
|---|---|---|
| Run hotter (higher utilisation) | Fewer machines | Latency rises sharply past the knee; less headroom for failure |
| Add headroom per zone (N+1, N+2) | Survives a zone or instance loss at peak | 33-50% more capacity with three zones |
| Reduce work per request (caching, precomputation) | Lower S, so lower W at the same ρ | Consistency and invalidation complexity |
| Move work off the request path (queues) | Request latency independent of processing time | Eventual results; queue sizing; backpressure |
| Reduce fan-out | Better tail latency | Data duplication or denormalisation |
| Hedged requests | Better tail at small extra load | 2-5% extra backend load; requires idempotent reads |
Zone headroom. With three zones and the requirement to survive the loss of one at peak, each zone must carry half the peak, so total capacity is 1.5× peak. Two zones need 2×. This one line explains a large share of cloud bills.
Failure modes
- Designing for the average. The system works at 11:00 and falls over at 09:00 on Monday.
- Ignoring the shape of the peak. A product launch, a big customer onboarding, a retry storm after an outage: all far above the normal peak.
- Forgetting the multipliers. Replication factor, indexes, backups, retention, logging volume, and the 1.5× zone headroom are each larger than the original estimate's error.
- Planning to 95% utilisation. Latency degrades long before the CPU is full.
- Pool exhaustion. A slow dependency raises W, Little's law raises L, and the connection pool runs out even though throughput didn't change.
Published case: Pokémon GO launch, July 2016
Google's Customer Reliability Engineering team wrote that Pokémon GO's traffic on launch reached about 50 times the target the developers had planned for, and about 10 times their worst-case estimate. The game ran on Google Kubernetes Engine, and the teams kept it up by scaling the cluster and the load-balancing layer in place, including moving to a newer load balancer during the launch. The lesson for estimation: state a planning peak, a worst case and the mechanism you will use if reality exceeds both. "We'll scale" is only a plan if the scaling path has been exercised.
Lab: a capacity model you can rerun
The model below estimates an audit-event service for a B2B SaaS product. Save it as estimate.py, run it with Python 3, then change one input at a time and watch which output moves.
#!/usr/bin/env python3
"""Back-of-envelope capacity model for an audit-event service. Change the inputs, rerun."""
tenants = 40_000
users_per_tenant = 250
daily_active = 0.20 # share of users active on a given day
req_per_user_day = 120
peak_factor = 4.0 # peak hour vs daily average
event_bytes = 1_200 # one audit event, serialized
replicas = 3
retention_days = 400
latency_s = 0.120 # mean time a request spends in the service
conc_per_pod = 64 # concurrent requests one pod handles at its limit
target_util = 0.70 # run pods at 70% of their limit
dau = tenants * users_per_tenant * daily_active
req_day = dau * req_per_user_day
avg_rps = req_day / 86_400
peak_rps = avg_rps * peak_factor
print(f"daily active users {dau:>14,.0f}")
print(f"requests per day {req_day:>14,.0f}")
print(f"average rps {avg_rps:>14,.0f}")
print(f"peak rps {peak_rps:>14,.0f}")
raw_day = req_day * event_bytes
stored = raw_day * replicas * retention_days
print(f"raw ingest per day {raw_day/1e9:>14,.1f} GB")
print(f"ingest bandwidth peak {peak_rps*event_bytes*8/1e6:>14,.1f} Mbit/s")
print(f"stored (x{replicas}, {retention_days} d) {stored/1e12:>14,.1f} TB")
inflight = peak_rps * latency_s # Little's law: L = lambda * W
pods = inflight / (conc_per_pod * target_util)
print(f"in-flight at peak (L) {inflight:>14,.0f}")
print(f"pods needed at 70% {pods:>14,.1f} -> round up, then add N+1 per zone")
print("\nM/M/1 queueing: mean response time = S / (1 - rho), S = 10 ms service time")
S = 0.010
for rho in (0.50, 0.70, 0.80, 0.90, 0.95, 0.99):
print(f" utilisation {rho:4.0%} response {S/(1-rho)*1000:7.1f} ms ({1/(1-rho):5.1f}x service time)")
Output from a real run (Python 3, macOS):
daily active users 2,000,000
requests per day 240,000,000
average rps 2,778
peak rps 11,111
raw ingest per day 288.0 GB
ingest bandwidth peak 106.7 Mbit/s
stored (x3, 400 d) 345.6 TB
in-flight at peak (L) 1,333
pods needed at 70% 29.8 -> round up, then add N+1 per zone
M/M/1 queueing: mean response time = S / (1 - rho), S = 10 ms service time
utilisation 50% response 20.0 ms ( 2.0x service time)
utilisation 70% response 33.3 ms ( 3.3x service time)
utilisation 80% response 50.0 ms ( 5.0x service time)
utilisation 90% response 100.0 ms ( 10.0x service time)
utilisation 95% response 200.0 ms ( 20.0x service time)
utilisation 99% response 1000.0 ms (100.0x service time)
What to read from it:
- Storage dominates. 288 GB per day becomes about 346 TB with three replicas and 400 days' retention. Compression, tiering to object storage after 30 days, or a shorter retention for low tiers each change the bill more than any compute decision.
- The fleet is small. About 30 pods at peak, before N+1 per zone. With three zones and survive-one-zone, plan 1.5× that: about 45.
- Bandwidth is modest. About 107 Mbit/s of ingest at peak is not a network problem, but replication triples it, and cross-zone replication is billed in most clouds.
- The queueing table is the argument for headroom. Going from 70% to 90% utilisation triples the mean response time.
Exercises:
- Change
peak_factorto 20 (a Monday-morning access-review campaign). What changes, and which part of the design would you change first? - Halve
event_bytes(a compact binary format) and halveretention_daysfor half the tenants. What is the new storage figure? - Double
latency_sbecause a downstream call got slow. Use Little's law to explain what happens to connection pools.
Architect's lens
From the ten questions, estimation answers scale and feeds cost and failure. In every design you present: state the inputs, the peak factor and the multipliers; show L = λW for the critical pool; state the utilisation target and the zone headroom. The numbers don't have to be right; they have to be visible.
Design review
Brief. A notification service sends email, SMS and push messages for 40,000 tenants. Average 15 million notifications per day, 70% in a 2-hour window after 08:00 local time across four time zones. Each notification is rendered from a template, checked against user preferences, and handed to one of three external providers whose p99 is 800 ms. Delivery receipts arrive asynchronously, up to 3 per notification, and must be kept 180 days.
Produce: peak rate with your peak factor; in-flight concurrency per provider; worker count at your utilisation target; storage for receipts; the latency budget for the synchronous "send" API; and where you put queues.
| Level | What the answer shows |
|---|---|
| Senior | Correct rates, storage and worker counts with stated assumptions |
| Staff | Little's law applied to the slow providers; sending moved off the request path; per-provider concurrency limits and backpressure |
| Principal | Peaks from tenant time zones and campaigns modelled; cost per tenant per million notifications; provider failure and failover capacity; what would be measured in the first month to replace the assumptions |
Self-check
A service handles 5,000 rps with a mean of 40 ms in the service. How many requests are in flight?
L = λW = 5,000 × 0.040 = 200.
Why run at 70% rather than 90% utilisation?
Queueing: response time grows as S/(1−ρ). At 90% the mean is about three times the 70% figure, and the tail is worse. Headroom also absorbs the loss of a zone or instance.
A request fans out to 50 shards, each slow 2% of the time. What fraction of requests hit at least one slow shard?
1 − 0.98⁵⁰ ≈ 64%.
References
- Little, "A Proof for the Queuing Formula L = λW", Operations Research, 1961
- Dean and Barroso, "The Tail at Scale", Communications of the ACM, February 2013
- Harchol-Balter, Performance Modeling and Design of Computer Systems, chapters 1-6
- Gregg, Systems Performance, 2nd edition, chapter 2 (methodologies, USE method)
- Google Cloud blog, "Bringing Pokémon GO to life on Google Cloud", September 2016
- Kleppmann, Designing Data-Intensive Applications, chapter 1 (describing load and performance)
Related on this site
- Sizing & capacity math in Cluster Design
- Sizing a cell in Multi-tenant SaaS
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.