Pidoku

Capacity Planning

Module 23 Lesson 23.b 1h 30m Difficulty 4/5

Prerequisites 12.q, 23.a


Before you start: words you need#

WordPlain meaning
Peak demandThe load in your busiest short window (say, the busiest 5 minutes of the week), not the daily average.
Capacity at SLOThe highest load one replica can take while still meeting its latency objectives. Lower than its peak throughput.
Utilization (ρ)Fraction of capacity in use. Written ρ (“rho”) in queueing formulas.
HeadroomCapacity you hold on purpose above expected load, for bursts, failures and growth.
N+1Enough replicas that losing any one still leaves enough to serve the load.
Lead timeHow long from deciding to buy or reserve GPUs until they are serving traffic.
Heavy-tailedA distribution where a few very large values (long prompts) pull the mean far above the median.

1. What is it?#

Capacity planning answers “how many GPUs do I need?”, and its harder cousin, “how many will I need in six months, and when must I order them?”

12.q did the per-node arithmetic: memory, bandwidth, tokens per second. This lesson adds the production factors on top: the traffic model, the utilization target, redundancy, growth and lead time. The result is a written plan with a number, the reasons for it, and the conditions that would change it.


2. Why does it matter?#

  • GPUs are the cost. Over-provisioning by 30% on a 200-GPU fleet wastes roughly a million dollars a year at 2026 rental prices (H100 ~$2–3 per GPU-hour, 7.b).
  • Under-provisioning breaks the SLO at peak, which is when the most users are watching.
  • You cannot fix it quickly. Cloud reservations take weeks to arrange; owned racks take months; new data-centre power takes years (7.l). Autoscaling handles daily swings, not a shortfall (23.d).

3. Simple analogy#

Planning a restaurant’s staff for a Saturday. You do not staff for the average customer per hour; you staff for the dinner rush. You do not assume each waiter can serve as many tables as is physically possible; you use how many they can serve while food still arrives hot. You add one spare in case someone calls in sick, and if the restaurant is growing, you hire before the queue reaches the street, because new staff take weeks to train.


4. Tiny example#

peak demand                    130 requests/s
capacity per node at the SLO    14 requests/s   (measured, section 5)

nodes busy at peak             130 / 14          =  9.3 → 10
at a 70% utilization target    130 / 14 / 0.70   = 13.3 → 14
N+1                                                       15
growth: 8%/month over 3.5 months of lead time  ×1.31  →  20 nodes

answer: 20 nodes × 8 GPUs = 160 GPUs

Ten nodes do the work; the other ten are deliberate. Each extra node has a reason you can defend.


5. Technical explanation#

The formula#

nodes = ceil( peak_demand ÷ capacity_per_node_at_SLO ÷ target_utilization )
        + spare_nodes
        × growth_over_lead_time

The two terms people leave out are target utilization (latency rises steeply near 100%, 2.c) and growth over lead time (the plan must still be right when the hardware arrives).

Step 1: model the traffic#

This is the input everything depends on, and usually the weakest part of a plan.

FROM THE PRODUCT            FROM MEASUREMENT (per-request logs, 23.h)
daily active users          prompt length distribution (p50, p95, p99, mean)
sessions and turns per day  output length distribution
growth forecast             requests per minute by hour and weekday
                            shape of the peak (a spike, or a plateau?)
WORKED:
  50,000 daily users × 8 sessions × 6 turns          = 2.4M requests/day
  peak hour = 14% of the day (measured)               = 336,000 → 93 req/s
  busiest 5 minutes = 1.4 × the peak-hour rate        = 130 req/s

  prompt:  p50 480, p95 3,200, mean 890 tokens
  output:  p50 190, p95 1,100, mean 320 tokens

  peak prefill: 130 × 890 = 115,700 tokens/s
  peak decode:  130 × 320 =  41,600 tokens/s

Plan with the mean, not the median. Total work is the mean times the count. With heavy-tailed lengths, the mean here is almost twice the median; planning on p50 would under-provision badly.

Two 2026 workload shifts change this model:

  • Reasoning models produce many hidden tokens before the answer. Measure output tokens including reasoning; it can multiply decode demand several times for the same request rate.
  • Agents send many calls per user task, each carrying a long and growing context. Requests per user rises, and prefix caching (12.m) matters far more.

Step 2: measure capacity per node at the SLO#

Not peak throughput. Run an open-loop benchmark (22.g) at rising arrival rates and find where goodput (23.a) starts to fall:

arrival rate   p95 TTFT   p95 ITL   goodput
   4 req/s       280 ms    22 ms     100%
   8             340 ms    26 ms     100%
  12             480 ms    31 ms     99.4%
  14             690 ms    38 ms     98.1%
  16           1,240 ms    44 ms     91.3%    ← the knee
  18           3,100 ms    52 ms     71.0%

capacity at SLO (goodput ≥ 97%) = 14 req/s per node
peak throughput would say 18+, and would be wrong

The gap between peak throughput and capacity at the SLO is commonly 25–40%. A plan built on peak throughput guarantees SLO breaches at peak. Use your real prompt mix: capacity measured on short prompts says nothing about long ones.

Step 3: assemble and cross-check#

Section 4 gives 20 nodes. Now check it against tokens:

20 nodes × 14 req/s × 320 output tokens = 89,600 output tokens/s of capacity
peak demand                             = 41,600
ratio                                   = 2.15

explicit factors: 1/0.70 × 16/15 × 1.31 = 2.00, plus rounding → 2.15. Consistent.

If the ratio is much larger than the product of your stated factors, you have counted something twice.

The factors, justified#

Target utilization is the biggest factor and the one people argue about. A simple queueing model (M/M/1: random arrivals, one server) says the wait in the queue is about the service time × ρ/(1−ρ):

ρ = 0.60 → queue adds 1.5× service time      ρ = 0.90 →  9×
ρ = 0.70 → 2.3×                              ρ = 0.95 → 19×
ρ = 0.80 → 4×

A batching LLM server is not M/M/1 (it serves many requests at once), so treat this as the shape, not the number: the measured knee in step 2 is the real limit. With a 300 ms queue share in the TTFT budget and ~200 ms of prefill, a ratio of 1.5 points to ρ ≈ 0.6–0.7. Batch work with no latency SLO can run at 0.9 or more.

Redundancy.

N+1    survive one node failure: one extra node, or (N+1)/N
N+2    survive a failure during a rolling deploy
2N     survive losing a zone or region (23.f)

For large fleets, N+1 is a small fraction. For a three-node fleet, it is a third more.

Growth and lead time. Headroom = expected growth over (lead time + safety margin). Order date = need date − lead time − safety. A plan whose order date is after its need date is a plan to have an outage.

What changes the plan#

INPUT                          EFFECT
prompt length distribution     linear (and worse at long context) on prefill
output length, incl. reasoning linear on decode
peak-to-average ratio          linear on peak sizing
model size or architecture     large, nonlinear (dense vs MoE, 14.g)
precision (FP8, FP4)           often 1.5–3× (13.b)
prefix-cache hit rate          large for prefill-heavy or agent traffic
SLO thresholds                 large, through batch size and utilization
context-length limits          large, through KV memory and concurrency
new product features           unpredictable: model each one explicitly

Prompt length drift is the most common surprise. A feature that adds retrieved documents to every request can double prefill load overnight with no change in request rate.

The plan is a document#

1. TRAFFIC MODEL        assumptions, sources, measured distributions
2. UNIT CAPACITY        measured at the SLO, with the benchmark method
3. THE CALCULATION      every factor and why
4. THE ANSWER           GPU count, instance type, timeline, order date
5. COST                 per month and per million tokens (23.c)
6. SENSITIVITY          what if traffic is 1.5×? what if prompts double?
7. TRIGGERS             measurements that would invalidate the plan
8. REVIEW DATE

The sensitivity section is what makes it useful: “if peak passes 160 req/s we need 26 nodes; order by March” is actionable; a single number is fragile.


6. Under the hood#

The whole plan as a program, with a sensitivity table.

Go
// capacity.go — from a traffic model to a GPU count, with a sensitivity table.
package main

import (
	"fmt"
	"math"
)

type plan struct {
	peakReqPerSec  float64 // busiest 5-minute window
	nodeReqAtSLO   float64 // measured capacity per node at the SLO (not peak throughput)
	targetUtil     float64 // fraction of capacity you plan to use at peak
	spareNodes     int     // N+1 → 1
	growthPerMonth float64 // expected traffic growth
	leadTimeMonths float64 // order → serving, plus a safety margin
	gpusPerNode    int
}

func (p plan) nodes() (busy, withUtil, withSpare, total int) {
	busy = int(math.Ceil(p.peakReqPerSec / p.nodeReqAtSLO))
	withUtil = int(math.Ceil(p.peakReqPerSec / p.nodeReqAtSLO / p.targetUtil))
	withSpare = withUtil + p.spareNodes
	growth := math.Pow(1+p.growthPerMonth, p.leadTimeMonths)
	total = int(math.Ceil(float64(withSpare) * growth))
	return
}

func main() {
	base := plan{peakReqPerSec: 130, nodeReqAtSLO: 14, targetUtil: 0.70, spareNodes: 1,
		growthPerMonth: 0.08, leadTimeMonths: 3.5, gpusPerNode: 8}

	busy, u, s, t := base.nodes()
	fmt.Printf("nodes busy at peak:            %2d\n", busy)
	fmt.Printf("at 70%% target utilization:     %2d\n", u)
	fmt.Printf("plus one spare (N+1):          %2d\n", s)
	fmt.Printf("plus growth over lead time:    %2d  (x%.2f)\n", t, math.Pow(1.08, 3.5))
	fmt.Printf("GPUs to have in service:      %3d\n\n", t*base.gpusPerNode)

	fmt.Println("queueing (M/M/1 approximation): wait = service × ρ/(1−ρ)")
	for _, rho := range []float64{0.5, 0.6, 0.7, 0.8, 0.9, 0.95} {
		fmt.Printf("  ρ = %.2f → queue adds %4.1f× the service time\n", rho, rho/(1-rho))
	}

	fmt.Println("\nsensitivity: each input 50% worse, the others unchanged")
	cases := []struct {
		name string
		mod  func(p *plan)
	}{
		{"peak traffic ×1.5", func(p *plan) { p.peakReqPerSec *= 1.5 }},
		{"capacity per node ×0.67", func(p *plan) { p.nodeReqAtSLO /= 1.5 }},
		{"target utilization 0.70→0.47", func(p *plan) { p.targetUtil /= 1.5 }},
		{"growth 8%→12%/month", func(p *plan) { p.growthPerMonth *= 1.5 }},
		{"lead time 3.5→5.25 months", func(p *plan) { p.leadTimeMonths *= 1.5 }},
	}
	for _, c := range cases {
		p := base
		c.mod(&p)
		_, _, _, n := p.nodes()
		fmt.Printf("  %-30s %2d nodes (%+d)\n", c.name, n, n-t)
	}
}

Output:

nodes busy at peak:            10
at 70% target utilization:     14
plus one spare (N+1):          15
plus growth over lead time:    20  (x1.31)
GPUs to have in service:      160

queueing (M/M/1 approximation): wait = service × ρ/(1−ρ)
  ρ = 0.50 → queue adds  1.0× the service time
  ρ = 0.60 → queue adds  1.5× the service time
  ρ = 0.70 → queue adds  2.3× the service time
  ρ = 0.80 → queue adds  4.0× the service time
  ρ = 0.90 → queue adds  9.0× the service time
  ρ = 0.95 → queue adds 19.0× the service time

sensitivity: each input 50% worse, the others unchanged
  peak traffic ×1.5              28 nodes (+8)
  capacity per node ×0.67        28 nodes (+8)
  target utilization 0.70→0.47   28 nodes (+8)
  growth 8%→12%/month            23 nodes (+3)
  lead time 3.5→5.25 months      23 nodes (+3)

How to read the sensitivity table: peak traffic, capacity per node and the utilization target sit in the same product, so an error in any of them moves the answer by the same amount. Those three deserve careful measurement; the growth forecast matters less over a short horizon.


7. Performance implications#

  • Every efficiency gain is a capacity gain. FP8 or FP4 weights, prefix caching, better batching and speculative decoding (Module 13) raise capacity per node, which cuts the node count in the same proportion.
  • The SLO and utilization are linked. A tighter TTFT objective lowers the safe utilization, which raises the GPU count.
  • Prefill and decode can bind separately. If prefill demand grows faster than decode (more retrieval, longer agent contexts), consider separate prefill and decode pools (14.j) and plan each against its own limit.

8. Production implications#

  • Base the traffic model on measurement. Per-request logs (23.h) are the source; forecasts are an input, not the input.
  • Measure capacity at the SLO with a realistic, open-loop benchmark.
  • Justify the utilization target from the latency budget and the measured knee.
  • Track actual against planned every month. A plan you never check is a guess.
  • Set triggers: “if p95 prompt length passes 4,000 tokens, re-plan.”
  • Write the efficiency assumptions into the plan: “assumes FP8 and a 60% prefix-cache hit rate; without them, add 8 nodes.”
  • Plan for the next GPU generation. A plan that spans a hardware refresh should say what changes if capacity per node doubles (7.e).

9. Common mistakes#

  1. Planning with peak throughput instead of capacity at the SLO: 25–40% short at peak.
  2. Using median lengths instead of the mean: badly short for heavy-tailed traffic.
  3. Planning for 90%+ utilization with a latency SLO: the queueing wall.
  4. Forgetting growth and lead time: the plan is right and arrives late.
  5. No sensitivity analysis: one assumption moves and the plan is void.
  6. Ignoring efficiency levers: planning at BF16 when you will deploy FP8 roughly doubles the bill.
  7. Counting output tokens without reasoning tokens.
  8. Planning once. Traffic shape drifts all the time.

10. Hands-on exercise#

  1. Run capacity.go. Change the spare to N+2 and the utilization target to 0.6. What is the new answer, and which change cost more?
  2. From real or synthetic request logs, extract the length distributions (mean and percentiles), the hourly rate profile and the busiest 5-minute window.
  3. Using your benchmark harness (22.g), find the goodput knee for one node. How far is it below peak throughput?
  4. Write the eight-section plan for a service you know, including the sensitivity table.
  5. Compute the plan with and without FP8 weights, prefix caching and chunked prefill. How many GPUs does each save, and what is that a year at $2.50 per GPU-hour?

11. Interview questions#

  1. Walk me through capacity planning for an LLM service.
  2. Why plan with capacity at the SLO rather than peak throughput?
  3. Why 70% utilization? Justify it with numbers.
  4. Why the mean request length rather than the median?
  5. How do reasoning models and agents change a capacity plan?
  6. What would invalidate a plan, and how would you detect it?
  7. Your plan says 20 nodes. How do you sanity-check it?

12. Further reading#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in