BLUEPRINT · The Solution Architect's Codex
Ch 14 · Performance & Capacity Planning
Chapter 14 · Latency budgets, queues, and the laws that bound them

Performance & Capacity Planning — the architecture of speed

Performance is not a virtue and capacity is not a wish — both are physical consequences of how requests, queues, and resources interact. The competent architect treats them with the same rigour as security or correctness: vocabulary first, queueing theory next, then budgets, models, and load tests that turn opinions into numbers. This chapter assembles the laws (Little, Amdahl, Gunther), the methods (RED, USE, open- vs closed-loop testing), and the workflow that converts a workload forecast into a defensible capacity plan.

14.1 · The performance vocabulary

Most performance arguments are vocabulary arguments. Pin down the words before the numbers.

TermDefinitionUnit
LatencyTime for one request to traverse a path, end-to-endms
Response timeLatency observed at the client = service time + queue time + networkms
Service time ($S$)Time the server actually works on a requestms
Queue time ($W_q$)Time the request waits before being servedms
Throughput ($X$ or $\lambda$)Completed requests per secondreq/s
Concurrency ($L$ or $N$)Requests in flight at one instantrequests
Utilisation ($U$)Fraction of time a resource is busy, $U = \lambda S$0–1
SaturationExtra work queued because the resource is fullqueue depth
GoodputThroughput of useful work (excluding retries, errors)req/s
Headroom1 − utilisation at peak, the safety margin%
Architect's note
"Latency" without a percentile is meaningless. State p50/p95/p99/p99.9 — the long tail is where users live.

14.2 · Queueing theory essentials

Every queue you cannot avoid is one you must size. The two laws every architect must internalise:

Little's Law (John D. C. Little, MIT, 1961) holds for any stable system in steady state:

$L = \lambda W$

where $L$ is mean concurrency, $\lambda$ is arrival rate, and $W$ is mean time in system. It lets you derive any of the three from the other two — useful for thread-pool sizing, queue sizing, and connection pools.

The Utilisation Law: $U = \lambda S$ (arrival × service time). For an M/M/1 queue (Poisson arrivals, exponential service, one server), the mean response time is:

$R = \dfrac{S}{1 - U}$

The denominator $(1 - U)$ produces the infamous hockey-stick. At $U = 0.5$, $R = 2S$. At $U = 0.8$, $R = 5S$. At $U = 0.95$, $R = 20S$. This is why production targets sit at 60–70 % utilisation, not 95 %.

Response time vs utilisation (M/M/1)

0 U → 1.0 R safe zone limit ≈ 0.7

Variants worth knowing: M/M/c (c servers — pooled), M/G/1 (general service distribution — the Pollaczek–Khinchine formula adds variance: $W_q = \dfrac{\rho^2(1+C_v^2)}{2\lambda(1-\rho)}$), and G/G/1 (Kingman's approximation). Variance hurts as much as average load.

14.3 · The Universal Scalability Law

Neil J. Gunther (Performance Dynamics Co., 1993, refined 2007) extended Amdahl with a coherence term to model the real ceiling of horizontally-scaled systems:

$C(N) = \dfrac{N}{1 + \alpha(N-1) + \beta N(N-1)}$

where $N$ is the number of parallel units, $\alpha$ is the contention coefficient (serial fraction — locks, single-writer paths), and $\beta$ is the coherence coefficient (cost of inter-node synchronisation — cache lines, distributed consensus). The $\beta N(N-1)$ term is quadratic: at some $N^*$ throughput actually decreases. This is "retrograde scalability" — adding nodes makes the system slower.

Pattern$\alpha$$\beta$Outcome
Embarrassingly parallel≈ 0≈ 0Linear
Shared-nothing web tierlow≈ 0Near-linear, slow saturation
Read-replica DBmediumlowSub-linear, knee around 8–16 nodes
Distributed lock / consensusmediumhighRetrograde beyond 5–7 nodes

14.4 · Amdahl's Law

Gene Amdahl (IBM, 1967) gave the speedup ceiling from parallelising a fraction $p$ of the work across $N$ processors: $\text{Speedup}(N) = \dfrac{1}{(1 - p) + p/N}$. As $N \to \infty$, speedup is bounded by $1/(1-p)$. If 10 % is inherently serial, no amount of hardware exceeds 10×. The architectural lesson: find and shrink the serial fraction before buying iron.

14.5 · Latency budgets

A latency budget decomposes a target SLO into spendable slices per hop. Build one early; it forces conversations with every owner on the path. Sample for a 200 ms p95 page render:

HopBudgetNotes
DNS lookup10 msCacheable; pin TTL
TCP + TLS handshake30 msUse TLS 1.3 0-RTT, session resumption
Edge / CDN routing15 msPOP nearest user (Cloudflare, Fastly, CloudFront)
Backbone network (CDN → origin)25 msSame region; private peering
API gateway / WAF10 msAllow no synchronous external calls here
Application logic40 msSum of synchronous work
Cache lookup5 msRedis / Memcached, same AZ
Database (read)25 msIndexed, ≤ 3 round-trips
Serialisation + payload10 msPrefer Brotli/gzip, HTTP/2 or 3
Browser render (FCP)30 msCritical CSS inlined, lazy non-critical
Total200 msCross-check with synthetic + RUM

14.6 · Performance NFRs done right

Cross-reference Ch 05. A performance NFR worthy of an architecture has all five clauses: metric · percentile · workload · window · compliance.

// Bad
checkout must be fast

// Good
SLI      : checkout-api end-to-end response time
SLO      : p95 ≤ 600 ms and p99 ≤ 1200 ms
Workload : 4 000 RPS sustained, 8 000 RPS peak for 10 min
Window   : 28-day rolling
Compliance: 99.0 % of 1-min buckets must meet both thresholds

Percentile cheat-sheet: p50 (typical user), p95 (worst tail you advertise), p99 (the loudest 1 % — usually your top customers), p99.9 (queue spikes, GC pauses), p99.99 (chaos territory). Each extra nine roughly doubles cost.

14.7 · Capacity planning workflow

Workload model
peak RPS, mix, growth
→
Resource model
service demand per request
→
Forecast
12–24 months
→
Safety margin
30–40% headroom
→
Procure / autoscale
  1. Workload model — request types, mix, distribution (Poisson? bursty?), seasonality, growth rate.
  2. Resource model — CPU-ms, memory MB, IOPS, network bytes per request by type. Derive from profiling.
  3. Forecast — multiply by demand forecast; add a confidence interval. Re-do quarterly.
  4. Safety margin — keep peak utilisation ≤ 70 % per §14.2; absorb variance and failure of one AZ.
  5. Provision — reserved/committed for baseline, on-demand or spot for burst, scale-to-zero off-peak.

14.8 · Sizing approaches

ApproachWhenAccuracy
Back-of-envelope (Jeff Dean numbers)Greenfield, no system to measure± order of magnitude
Vendor calculators (AWS Pricing Calculator, Azure TCO, GCP Estimator)Cost framing of a sized design± 30 % on cost
Reference benchmarks (TPC-C/H/DS, YCSB)Comparing enginesApples-to-apples for the workload tested
Load testingPre-launch, post-change± 10 % if model is faithful
Observed production headroomRunning systemsBest — use rolling 28-day p95 of utilisation

14.9 · Load testing strategies

Closed-loop (think-time per virtual user, requests gated by responses) models users. Open-loop (Poisson arrivals independent of response time) models traffic. Closed-loop hides queue build-up because slow responses self-throttle the test; open-loop reveals it. Public APIs and event-driven systems should be tested open-loop (Gil Tene's "coordinated omission" critique).

Test typeGoalDuration
SmokePipeline + harness sanity2–5 min
LoadConfirm SLO at expected peak30–60 min
StressFind the breaking pointUntil failure
Soak / enduranceMemory leaks, queue drift, log-disk fill8–72 h
SpikeBurst from baseline to N× in seconds10–30 min
Breakpoint / capacityWhere the knee isRamp continuously

Tooling: k6 (Grafana Labs, 2017) Gatling (2012) Apache JMeter (1998) Locust (Python) Vegeta (Go, open-loop) Tsung wrk2 (Gil Tene) NBomber (.NET).

14.10 · APM & profiling

Two complementary lenses for production:

  • RED method (Tom Wilkie, Weaveworks, 2016) — Rate, Errors, Duration. Per-service request view.
  • USE method (Brendan Gregg, Netflix, 2012) — Utilisation, Saturation, Errors. Per-resource view.
  • Four Golden Signals (Google SRE Book, 2016) — Latency, Traffic, Errors, Saturation. RED + saturation.

APM vendors: Datadog, New Relic, Dynatrace, AppDynamics (Cisco), Honeycomb, Lightstep (ServiceNow), Elastic APM. Continuous profiling (always-on, sample-based CPU/heap/lock profiles): Pyroscope (Grafana), Parca (Polar Signals), Google Cloud Profiler, AWS CodeGuru Profiler. The flame graph (Brendan Gregg, 2011) is the canonical visualisation.

14.11 · Caching hierarchies

Browser cache
→
CDN edge
→
API gateway
→
App-local (Caffeine, EhCache)
→
Distributed (Redis, Memcached, Hazelcast)
→
Database

Each layer trades freshness for latency. Pick the highest layer that meets the freshness need; cache invalidation is the second-hardest problem in CS (Phil Karlton).

EvictionBest forWorst for
LRU (Least Recently Used)Working-set workloadsScan-heavy traffic poisons it
LFU (Least Frequently Used)Power-law popularitySlow to adapt to shifts
TTL (time-based)Freshness SLAs, regulatoryThundering herd at expiry
ARC / W-TinyLFUMixed (Caffeine's default)Slightly more memory overhead
Watch for
Cache stampede on expiry — use request coalescing, probabilistic early expiration (Vattani et al., 2015), or a soft-TTL with background refresh.

14.12 · Common performance anti-patterns

  • N+1 queries — one query for the list, N for each child. Fix with joins, batch loaders (Facebook DataLoader), or projections.
  • Premature optimisation (Knuth, 1974) — micro-tuning before profiling. Measure first.
  • Synchronous I/O on the hot path — blocking external calls inside a request. Move to async, queue, or pre-compute.
  • Chatty interfaces — fine-grained APIs forcing many round-trips. Coarsen, batch, or use BFF (Ch 08).
  • Unbounded fan-out — one request spawns hundreds (scatter-gather). Bound concurrency, hedge tail requests.
  • Retry storms — synchronous retries amplify load during incidents. Use jittered exponential backoff + circuit breaker (Ch 13).
  • Hot keys — single partition or single cache key absorbs all traffic. Salt, shard, or replicate.
  • Coordinated omission — load tool stops counting when the system slows. Use open-loop tools (wrk2, Vegeta).
  • Log-on-hot-path — synchronous structured logging at debug level under load. Sample or async-buffer.

14.13 · Self-check

Q1 · A pool serves 200 req/s with a mean in-system time of 50 ms. What is the mean concurrency?
4
10
50
200
Q2 · The Universal Scalability Law's coherence term ($\beta$) captures…
CPU cache-line size
The cost of synchronisation between parallel units, producing retrograde scaling
The fraction of code that is serial
Garbage-collection overhead
Q3 · A load tool that uses a fixed number of virtual users with think-time will tend to…
Over-report latency due to coordinated omission
Under-report latency under stress because slow responses throttle the test
Be the best match for public API traffic
Always produce open-loop traffic
Q4 · Which method pairs Rate, Errors, Duration as the per-service signals?
USE
RED
SRE four golden signals
PIE