---
description: Capacity planning—measure first, plan for growth, load/stress test, right-size. Compute, storage, network, DB; thresholds and scaling.
alwaysApply: false
---

# Capacity Planning

Guidelines for planning and scaling capacity.

## Core Principles

1. **Measure First** - Use metrics (utilization, latency, throughput); no guesswork.
2. **Plan Ahead** - Provision for growth before you need it.
3. **Test Limits** - Load and stress tests; know breaking points.
4. **Right-Size** - Avoid over-provision (cost) and under-provision (outage).

## Dimensions

- **Compute**: CPU/memory utilization, pod/node count. Scale vertical (bigger instances) or horizontal (more replicas, HPA). Plan for peak vs average.
- **Storage**: Disk usage, IOPS, throughput, latency. Plan for growth and retention; shard or tier as needed.
- **Network**: Bandwidth, connection count, latency. Plan for traffic spikes and cross-region.
- **Database**: Connections, query latency, replication lag. Connection pooling; read replicas; plan for growth.

## Load Testing

- **Smoke**: Minimal load; every deploy.
- **Load**: Expected peak (e.g. 1.5×); weekly or pre-release.
- **Stress**: Ramp until failure; find limit; monthly.
- **Soak**: Sustained load (e.g. 24h); before major releases.

Use k6, Locust, or similar; define stages and thresholds (e.g. p99 latency, error rate). Run in staging or dedicated env; avoid production surprise.

## Thresholds and Alerts

- **Warning**: e.g. CPU 70%, disk 75%; plan scaling or cleanup.
- **Critical**: e.g. CPU 85%, disk 90%; scale or remediate immediately.
- **Trend**: Growth rate; project when you’ll hit limits; budget and provision in time.

## Definition of Done (Capacity Work)

- [ ] Metrics and thresholds defined; alerts and runbooks in place.
- [ ] Load/stress test run; results documented; scaling verified.
- [ ] Growth projection and next review date set.

## Common Pitfalls

- **No headroom** - Running at 90% leaves no buffer for spike or failure.
- **Only average** - Plan for peak and P99; average hides spikes.
- **Skipping tests** - “We’ll scale when it breaks” leads to outages; test in advance.
