Overview
Curated: · Written: · Reviewed:
Capacity Planning & Load Testing
In one line
Capacity is the demand a system absorbs while still meeting its SLO, found by modelling the workload and testing up to the first saturating resource. Reach for it before a launch, before a traffic step change, or whenever someone claims a service "can handle" a number.
Key definitions
- Throughput: completed work per unit time (RPS).
- Concurrency: work in flight at an instant. Little's Law links it to rate and latency.
- Saturation: the point where queueing makes latency climb sharply.
- Headroom: the margin between current load and the first saturating resource.
- Open vs closed-loop model: open offers a fixed arrival rate; closed holds a fixed set of users who wait for each response.
- Coordinated omission: latency measured from when the generator actually sent a request, not from when it was due, which hides stalls.
Formulas and complexity
Concurrency equals throughput times mean latency. Use means in steady state. Feeding it p99 overstates concurrency.
M/M/1 mean response time, where S is service time and rho is utilization. At 50% that is 2S, at 80% it is 5S, at 90% it is 10S.
For a fan-out of 20 shards, each with a 1% chance of exceeding 800 ms: 1 - 0.99^20 is about 18% of page loads.
Worked example: 520 peak concurrency on 64-thread replicas at 70% gives 12.
How it works
- Name the journey and the workload unit, then forecast rate, concurrency, payload and dataset size, segmented by tenant, region and request class.
- Translate demand through the dependency graph into CPU, memory, pool connections, IOPS, quotas and queues.
- Ramp an open-model test in steps and record achieved rate and p99 at each step against the SLO.
- Find the first resource to saturate. Change one variable per run and confirm the bottleneck moved where you predicted.
- Size for peak concurrency plus the failure state, then set the alert threshold at the level that leaves time to scale out.
When to use and when not to
| Situation | Test or model | Why |
|---|---|---|
| Known peak | Load test at peak, plus one-zone-lost run | A fleet that meets the SLO only with every zone healthy has no resilience headroom |
| Sudden spikes | Spike test against autoscaler warm-up | Reactive scaling fails when warm-up is longer than the spike |
| Leaks, queue drift, compaction | Soak test for hours | A 30-minute run misses slow growth |
| Write-heavy or mixed workloads | Production write mix | Read-only synthetic load moves the bottleneck elsewhere |
| Cache-dependent paths | Cold and warm runs, realistic key skew | Uniform keys over a small set flatter the cache |
| Production traffic available | Metrics, traces and sampled replay | Validates or replaces synthetic tests; replay needs data controls |
Traps interviewers probe
- Quoting a peak RPS with no latency objective. Fix: report the highest step where every SLO term holds. In the MCQ 1 ramp that is 25,000 rps (p99 240 ms, 0% errors), not 35,000 where p99 reached 620 ms.
- Trusting a closed-loop generator. Fix: use an open arrival-rate model, and check that offered rate stays on target. Slow responses reduce a closed-loop generator's load, so it understates overload.
- Coordinated omission. Fix: measure from intended send time. A 1 s stall in a generator sending every 10 ms leaves about 100 requests that look fast but were really delayed.
- Declaring a service certified after one passing run. Fix: add a zone-loss run, a soak run, and a check that the backlog drains after load falls.
- Blaming the service when the generator or a quota is the limit. Fix: monitor generator CPU, scheduling lag and socket counts, and check downstream quotas before concluding anything.
Interview tips
Open with the answer shape: "The workload is X. The objective is p99 at or below Y with error rate at or below Z. The first resource to saturate is W. Sustainable capacity is N with H headroom."
Follow-ups to expect:
- How do you know the test was representative? Name the mix, key skew, payload sizes and auth, and say what differs from production.
- What is your headroom, and why that number? Tie it to scale-out lead time and forecast error, not a habit.
- What happens when an AZ fails? With peak 900 rps across three zones and one zone lost, two zones must carry 900, so each needs 450 rps, not 400.
- How did you size the connection pool? Use Little's Law: rate times latency gives the connections needed.
- Why did the autoscaler miss the spike? Warm-up of 180 s against a 90 s spike means scaling arrives after the spike ends.
- Why did the retried writes duplicate? Retries without idempotency keys repeat side effects.
- What changes at 10x traffic? Name the next saturating resource, usually a pool, a hot key or a quota.
30-second outline:
- Demand and objective: the workload unit, the peak rate, and the SLO terms.
- Measured limit: the highest passing step, the first saturating resource, and the evidence.
- Headroom and failure state: the margin, and capacity with one zone or one dependency lost.
- Trigger and recovery: the alert threshold, the scale-out lead time, and how fast the backlog drains after load falls.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.