Skip to content

Lesson 9 of 9 · 26m

Capacity Planning: From Headroom Guesses to Evidence

Forecasting CPU, memory, storage, and network needs with utilization bands, growth data, and failure scenarios.

Capacity planning is where performance work becomes operational judgment. The question is not "are we using less than 100%?" It is "how much margin do we need so ordinary growth, failover, deploys, and bad days do not become incidents?" Teams that skip this end up permanently firefighting and calling it tuning.

Measure utilization by busy-hour behavior

Averages across a day hide peaks. Capture busy-hour percentiles for the resources that constrain the service:

CPU:      p95 utilization 58%, peak run queue 1.8x cores
Memory:   p95 available 21%, PSI full avg10 under 2%
Disk:     p95 await 7 ms, p99 await 24 ms
Network:  p95 egress 410 Mbps, retransmits low

The important phrase is constraining resource. A queueing system does not degrade linearly as utilization approaches saturation. At 60% utilization you may have comfortable margin; at 85%, small bursts create disproportionate latency. That is why utilization targets are bands, not single universal numbers.

Headroom must include failure math

If four nodes serve traffic and one fails, the remaining three absorb the load. Running each at 70% busy-hour utilization means failover pushes the survivors near saturation exactly when deploys, alerts, and human stress are highest.

N = 4 nodes
target max utilization during N-1 = 70%
per-node steady target <= 70% * 3/4 = 52.5%

That math feels conservative until the first regional failure or bad deploy. Include maintenance too: one node may be deliberately drained while another fails.

Forecast growth from drivers, not vibes

Tie resource consumption to business or workload drivers: requests per second, active users, bytes ingested, rows indexed, messages processed. Then model the relationship.

CPU cores needed ~= peak_rps * cpu_seconds_per_request / target_utilization

This works even when the coefficients are rough because it exposes assumptions. If CPU per request doubles after a dependency change, the model tells you immediately why the fleet is shrinking in effective capacity.

Storage capacity is latency capacity

Disk planning is not just gigabytes. Filesystems slow as they fill, SSD write amplification rises under pressure, and backups or compaction need temporary space. Set thresholds separately for space and performance. A 70%-full filesystem may be fine for archival storage and unacceptable for a write-heavy database.

Track growth rate and time-to-threshold:

df -h /var/lib/postgresql
du -sh /var/lib/postgresql/* 2>/dev/null | sort -h | tail

Then test restoration and compaction procedures. Capacity plans that assume perfect cleanup are fiction; retention bugs, orphaned snapshots, and failed archival jobs are routine.

Validate with load and failure tests

Before trusting the plan, run controlled load at the projected busy-hour level, then repeat with one node removed. Measure latency, saturation, error rate, and recovery time. A capacity plan is a hypothesis until the system survives the scenario it was designed for.

Field notes

  • Plan for N-1 at minimum; for critical multi-zone services, consider N-2 or zone loss.
  • Do not use weekly averages for capacity decisions. Busy-hour p95 or p99 is closer to reality.
  • Include operational work: backups, vacuuming, compaction, indexing, deploys, and security scans consume real capacity.
  • Scaling out does not fix single-process serialization. If every request waits on one lock or one primary database node, adding replicas may only move the bottleneck.

Was this lesson helpful?

Sign in to rate