What it is
Capacity planning answers "how much infrastructure do we need, and when?" with arithmetic you can check. It combines an estimate of demand (requests per second at peak), a measurement of supply (what one instance can do at an acceptable latency), a failure margin, and a growth projection, and repeats the exercise for every tier of the system.
Why it exists
Too little capacity shows up as latency, errors and outages at the worst moment: the evening peak, a launch, a failover. Too much is money spent for nothing. Autoscaling narrows the gap but does not remove it: it reacts with a delay, it is bounded by quotas, and stateful tiers (databases, brokers) rarely scale on demand. A plan tells you where the limits are before users find them.
How it works
1. Demand. Start from what you know: daily active users × requests per user per day ÷ 86,400 s = average requests per second. Then apply a peak factor for the busiest period (2–4× is common for consumer traffic; measure it from your own data where possible). Add known events: launches, campaigns, seasonal peaks. Distinguish reads from writes if they hit different tiers.
2. Supply per instance. For a worker-based service, throughput at 100% busy ≈ workers ÷ service time (8 workers at 40 ms ≈ 200 req/s). Pick a target utilisation at peak: queueing delay grows like ρ ÷ (1 − ρ), so latency-sensitive services usually aim for 60–80%. Then verify with a load test at the target load: measured utilisation and latency should match the prediction. If they do not, your model of the service is wrong (often a hidden dependency or lock), and that is worth knowing before production does.
3. Divide and round up. N = ⌈peak ÷ (capacity per instance × target utilisation)⌉. Predict the resulting utilisation (peak ÷ (N × capacity)) and check it.
4. Failure margin. Size so that the fleet minus its largest failure domain still carries the peak: N+1 for single-instance failures and rolling deploys, or zone-level redundancy (with three zones, each zone's share must be carried by the other two, so each zone runs at most at ~2/3 of the target). The survivors' utilisation after a failure is the number to check, not the healthy utilisation.
5. Growth and lead time. Project the peak forward: peak × (1 + monthly growth)^months. Re-plan at least one provisioning lead time ahead (quota requests, reserved capacity, hardware, database migrations take weeks).
6. Every tier. Repeat for each shared resource: database connections and IOPS, cache memory and network, broker partitions and consumer throughput, third-party rate limits, cloud quotas. The tier with the least margin is your next incident.
When to use it
- Before a launch, a migration or an expected traffic event.
- In a regular review (monthly or quarterly) for growing services.
- When choosing instance sizes or reserved capacity commitments.
- In system design interviews, as back-of-the-envelope estimation.
When not to
- For tiny internal tools where one instance is idle at peak: a minimum of two instances for availability is the whole plan.
- As a substitute for measurement: estimates guide, load tests and production metrics decide.
- When the workload is genuinely unpredictable and elastic infrastructure (serverless, autoscaling with generous quotas) can absorb it at acceptable cost; even then, plan the non-elastic tiers.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Low target utilisation (50–60%) | Stable latency, burst and failure headroom | More instances per unit of traffic |
| High target utilisation (85%+) | Lower cost | Volatile latency; failures and bursts become incidents |
| N+1 per service | Survive any one instance loss or a rolling deploy | One idle-ish instance per service |
| Zone-level redundancy | Survive a zone outage | Up to ~50% extra capacity with two zones, ~33% with three |
| Reserved / committed capacity | Lower unit price, guaranteed availability | Paying for it whether used or not |
| Autoscaling | Pay closer to actual use | Reaction delay, quota limits, cold starts; still needs a minimum plan |
Alternatives
- Autoscaling covers short-term variation inside a planned envelope (minimum, maximum, quotas). See the autoscaling lesson.
- Load shedding and graceful degradation keep the core working when demand exceeds the plan anyway.
- Queue-based load levelling moves non-urgent work out of the peak, lowering the peak you must size for.
Failure modes
- Sizing for the average: fine at noon, overloaded every evening.
- Healthy-only plans: the fleet carries the peak only with every instance up; one failure or deploy at peak overloads the rest.
- Stale plans: growth consumes the N+1 margin silently; the dashboard shows 69% busy until an instance fails.
- Planning one tier: the app tier scales, the database saturates.
- Trusting unverified numbers: a per-instance estimate that ignores a lock, a GC pause pattern or a slow dependency.
- Retries and queues as "capacity": longer queues turn overload into latency; client retries add load exactly when there is none to spare. The lesson's challenge shows both.
In production
Keep the plan as a small, versioned model (a spreadsheet or code) with its inputs: peak traffic per endpoint, per-instance throughput from the latest load test, target utilisation, failure domain, growth rate, lead time. Re-run load tests after significant changes. Alert on utilisation of the surviving capacity (fleet utilisation × N ÷ (N − 1)), not just the healthy average. Track quotas as capacity. Review before known peaks (sales events, launches) with the teams that own each tier.
Common misconceptions
- "We're at 60% CPU, so we have 40% headroom." Latency rises well before 100%, and a failure redistributes load: three instances at 70% become two at 105%.
- "Autoscaling means no capacity planning." It needs minimums, maximums, quotas, and capacity in the tiers it does not scale.
- "Peak is just the average times two." The factor varies by product and day; measure it, and include planned events.
- "Capacity is about the app servers." Databases, caches, brokers and third-party limits are usually the binding constraints.
Interview angle
Interviewers expect quick, explicit arithmetic: users → average RPS → peak RPS (state the peak factor), per-instance throughput from concurrency and latency, instance count at a target utilisation, plus N+1 or zone redundancy. Then storage and bandwidth if relevant. Round numbers aggressively (86,400 ≈ 100,000 s/day is a common shortcut, stated as such), say which tier will bind first, and how you would verify (load test) and keep the plan current (growth, lead time).
Model assumptions
The simulation is a simplified model, not a benchmark. Each app instance has 8 workers and a 40 ms mean service time (lognormal, cv 0.5), so at most about 200 req/s, and queues up to 30 requests before rejecting with 503. Arrivals are Poisson. The load balancer uses round robin with health checks every 500 ms (2 failures eject, 2 successes restore). Network time is about 23 ms each way. Utilisation is the fraction of busy workers, not CPU; the engine has no CPU, memory or GC model. The demand figures (120,000 users, 50 requests a day, a 3× peak factor, 12% monthly growth) are illustrative. Only the app tier is modelled here; a real plan covers every tier.