Lesson 6 of 9 · 28m
Capacity Planning for Real Systems, Not Idealized Graphs
Forecast demand, measure saturation, test failure headroom, and preserve enough capacity for growth, peaks, dependencies, and bad days.
Capacity planning is not predicting the future perfectly. It is making sure your inevitable prediction error is survivable. Real systems fail capacity in uneven ways: the database still has CPU, but connection slots are gone; the web tier scales, but the payment provider rate limit does not; autoscaling works, but new nodes take twelve minutes to become useful. The plan must include those constraints or it is a spreadsheet fantasy.
Define capacity in units of work
Start with the unit your system exists to serve: checkouts per minute, concurrent video sessions, messages per second, jobs per hour. Then map that unit to resource consumption:
1 checkout/minute ~= 8 API requests/minute
1 checkout/minute ~= 2 payment-provider calls/minute
1 checkout/minute ~= 12 database queries
1 checkout/minute ~= 0.04 MB egressThis model is crude, and that is fine. It gives you a way to compare growth, peak, and infrastructure supply. Refine it with production measurement rather than waiting for perfect attribution.
Saturation is the warning signal
Utilization is average use of a resource. Saturation is work waiting because the resource is full. Systems often degrade at high saturation long before utilization hits 100%. Watch the indicators that expose queueing:
CPU/memory: run-queue length, throttling, reclaim pressure, OOM events
database: active connections, lock waits, replication lag
network/app: retransmits, drops, pending requests, queue depth, worker occupancyA service can look comfortable at 45% CPU while every worker thread is occupied and latency is doubling. Measure the bottleneck that actually gates user-facing work.
Little's Law gives a sanity check
Little's Law, concurrency = arrival rate x response time, is simple and useful. If 120 requests per second arrive and each takes 250 milliseconds, the system holds roughly 30 concurrent requests. If latency doubles under load, concurrency doubles too. That is why latency and capacity are not separate topics: slower service means more simultaneous work, which means more memory, more connections, and more contention.
Test the headroom you think you have
A controlled load test answers "how does the system behave before the cliff?" A basic k6 test might be:
import http from 'k6/http';
export const options = { stages: [{ duration: '2m', target: 50 }, { duration: '5m', target: 200 }] };
export default function () {
const res = http.post('https://staging.internal/checkout/preview', '{}', {headers: {'content-type': 'application/json'}});
if (res.status !== 200) throw new Error(`preview failed: ${res.status}`);
}Do not only test success throughput. Test failure modes: kill one node, slow a dependency, reduce database capacity, and watch how queues recover. Recovery time is part of capacity.
Plan for N+1 and scaling lag
If you need three nodes to serve peak, four nodes are not automatically luxurious. One may be down for deployment, one may be unhealthy, and one zone may be unavailable. N+1 is a minimum conversation, not a universal answer. Also account for cold start: image pulls, cache warming, connection establishment, schema checks, and DNS propagation. Autoscaling that arrives after the peak is observability, not capacity.
External dependencies count
Payment providers, email services, managed databases, object stores, and even DNS have quotas and failure envelopes. Ask for rate limits, burst behavior, maintenance constraints, and regional dependencies. A beautiful horizontal scaling plan fails when all replicas amplify the same downstream retry storm.
Field notes
- Capacity buffers cost money; hiding the cost does not remove it. Make the chosen headroom explicit.
- Watch percentiles during load tests. Throughput at unbearable p99 latency is not usable capacity.
- The first bottleneck moved by optimization is rarely the last one; re-test after each major change.
- Forecast with ranges rather than false precision.
Was this lesson helpful?