Capacity planning and cost
Combine workload distributions, latency-tested capacity, failure headroom, and explicit unit economics into a defensible scaling plan.
On this page
The question for today
What you’ll understand
- Size capacity using measured safe throughput and a stated failure scenario.
- Calculate cost per successful unit with clearly fictional prices.
- Distinguish a useful planning model from uncertain demand and hardware performance.
A capacity plan is an argument about what the system can sustain when the workload and the world change. It is not a screenshot of average utilization. For an AI service, request lengths, model choice, batching, cache behavior, and required latency shape usable capacity. The financial counterpart is cost per successful useful outcome, including idle reserve and failures, rather than the advertised cost of one busy accelerator.
Define a workload and measure its safe operating envelope
Start with arrival patterns, prompt and output length distributions, model mix, regions, and user-facing latency objectives. Benchmark representative distributions rather than only the shortest request. Record the largest sustained rate that meets the objective with acceptable errors and memory headroom. A service may process more tokens per second after a larger batch while violating inter-token latency. Safe capacity is tied to the objective and workload, so a single universal requests-per-second number is usually misleading.
Distinguish a demand forecast from a load test and a hardware peak. Forecasts have uncertainty; load tests cover specified scenarios; theoretical peaks are bounds under assumptions. Examine bursts, correlated retries, cold starts, dependency limits, and degraded hardware. Little's law relates average in-flight work to arrival rate and average residence time in a stable, consistently measured system, but it does not predict tail latency. Use it to reconcile measurements, not to excuse missing overload or percentile tests.
Buy recovery capacity before assuming autoscaling will rescue you
Reserve headroom for an explicit failure scenario: one replica, one node, or an entire zone. These are not interchangeable. If losing a zone also removes storage or the control plane, spare compute elsewhere may not suffice. Check load-balancer behavior and remaining dependency capacity. Keep a bounded queue and an admission policy during the transition. An autoscaler cannot instantly acquire unavailable devices, download large weights, warm kernels, or restore a cache; measure those delays and pre-provision where required.
Scaling signals should reflect the constrained work: queue age, admitted token load, active cache demand, or measured saturation, not CPU percentage alone. Use stabilization to avoid oscillation, and avoid scaling down below recovery reserve because one quiet minute looks cheap. Alternatives include workload shaping, separate interactive and offline pools, and routing simpler tasks to appropriately evaluated models. Each changes quality, isolation, or reliability assumptions and must be tested, rather than treated as a free multiplier on capacity.
Calculate a unit cost with an honest denominator
Choose the business unit: a successfully completed request, an accepted document embedding, or a validated training run. Include provisioned compute, storage, networking, observability, and relevant operational costs in the same window. Separate input and output tokens when their resource behavior differs. A low cost per attempted request can conceal failures, retries, or low-quality answers. State which costs are included and whether reserve capacity is charged to the unit; otherwise comparisons can silently use different accounting boundaries.
Sensitivity analysis is more valuable than a false decimal precision. Vary demand, failure reserve, output length, cache-hit assumptions, and price. The prices below are fictional teaching inputs, not provider quotes. Model optimization can reduce compute yet increase engineering cost or shift the bottleneck to memory or storage. Preserve the workload and quality target when comparing options. More advanced planning adds stochastic demand and correlated failures, but even then a model should expose its uncertainty and be checked against observed outcomes.
Work it through
Plan a small inference pool with one-replica reserve
Peak demand is 180 requests/s. A replica sustains 60 requests/s at the required latency under the measured workload. Survive one unavailable replica. Assume fictional costs of USD 3 per replica-hour and USD 12/hour for all other included infrastructure. Average successful demand is 90 requests/s.
Three replicas meet peak demand only when all are available. For one-replica reserve, require N ≥ 1 + ceil(180/60) = 4 replicas.
At the stated peak with one replica unavailable, the remaining three provide exactly 180 requests/s. This meets the arithmetic bound but leaves no extra margin for forecast error or unequal loading.
Hourly included cost is 4 × USD 3 + USD 12 = USD 24. The average successful volume is 90 × 3,600 = 324,000 requests/hour.
Divide USD 24 by 324,000 to get approximately USD 0.0000741 per successful request, or USD 74.1 per million. This includes the specified reserve and other costs, but only the costs named in the scenario.
Four replicas satisfy the stated one-replica-loss arithmetic. The estimated included unit cost is USD 74.1 per million successful requests; load testing and additional demand margin remain separate decisions.
The living notebook
Explore the model
Interactive lab · queue
Test the capacity margin
Change λ and μ to compare growth of a fluid backlog with the separately labelled stable M/M/1 mean 1/(μ − λ). The latter assumes Poisson arrivals and exponential single-server service. Neither model includes dynamic batching, autoscaling delay, prices, or correlated failures.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forThe cheapest fully saturated configuration may fail the latency and recovery requirements that define useful capacity.
Pause & reason
Check your understanding
Your turn
Try it yourself
Demand peaks at 250 requests/s and each replica safely handles 70. Survive one unavailable replica. At fictional USD 2.50 per replica-hour plus USD 7.50/hour in other included costs, find required replicas and cost per million successful requests when average demand is 100/s.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Round up the capacity requirement before adding reserve. Convert the average successful rate to an hourly count so the numerator and denominator share a window.
Compare with the solution
N ≥ 1 + ceil(250/70) = 5 replicas. Four survivors provide 280 requests/s. Hourly included cost is 5 × USD 2.50 + USD 7.50 = USD 20. Successful hourly volume is 360,000, so the included unit cost is USD 20/360,000 × 1,000,000 ≈ USD 55.56 per million requests. Real planning must still validate latency, demand uncertainty, and failure-domain assumptions.
Keep the idea
Take it with you
- Capacity is measured against a workload, latency target, and failure scenario.
- Autoscaling has acquisition and startup delays; headroom must cover the transition.
- Unit economics require explicit included costs and successful useful output.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.