Education › Inference › Stage 7: Production inference systems

Autoscaling, queues, cold starts and cost per token

Scaling signals, admission control, warm capacity, and the arithmetic of cost per million tokens.

Advanced ~35 min read Module 13 of 15

GPU capacity is expensive, slow to add, and wasted when idle. Running inference in production means deciding how much to keep warm, what signal adds more, what to do with requests while capacity arrives, and what each million tokens actually costs. This lesson covers autoscaling signals for LLM servers, why cold starts take minutes and how to shorten them, admission control and queueing, and the arithmetic of cost per token that ties all of it to a budget.

After this module you can
  • Choose autoscaling signals that reflect LLM load: queue depth, cache use, latency
  • Break a cold start into its parts and shorten each
  • Design admission control so overload degrades gracefully
  • Compute cost per million tokens from GPU price, throughput and utilisation
  • Weigh warm capacity, scale-to-zero, reserved and spot GPUs

Scaling on the right signal

CPU and GPU utilisation are poor autoscaling signals for LLM servers: GPU utilisation reads high as soon as any work runs, and CPU is rarely the bottleneck. Scale on signals that measure unmet demand or latency risk.

SignalScale out whenNotes
Requests waiting (queue depth)Persistently above a small threshold per replicaMost direct measure of unmet demand
KV-cache usageSustained above roughly 85-90%Predicts queueing and preemption
p95 TTFTApproaching the SLOLags the cause slightly, but tracks what users feel
Requests runningAt the configured concurrency ceilingReplica is full
KEDA ScaledObject: scale vLLM replicas on queued requests
yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: chat-vllm
spec:
  scaleTargetRef:
    name: chat-vllm
  minReplicaCount: 2
  maxReplicaCount: 12
  cooldownPeriod: 600
  triggers:
    - type: prometheus
      metadata:
        serverAddress: http://prometheus.monitoring.svc:9090
        query: sum(vllm:num_requests_waiting{model_name="chat"})
        threshold: "5"
        activationThreshold: "1"

Scale in slowly. A long cooldown and HPA stabilisation window prevent removing a replica that took ten minutes to start just before the next burst.

Cold starts

A new replica is useless until it can serve, and for LLMs that takes minutes. Break it down to fix it:

admittedmetricsthresholdaddready (minutes)RequestsAdmission429 when fullReplicasqueue + batchPrometheusrequests waitingKEDA / HPAscale outNew replicaprovision, pull, load
Scale on unmet demand: queue depth drives new replicas, but each one pays a multi-minute cold start before it can serve, so warm capacity and admission control cover the gap.
  1. Node provisioning if no free GPU node exists: often the longest step on cloud autoscaling groups.
  2. Image pull: inference images are large; pre-pull them on GPU nodes or use a registry mirror.
  3. Weight loading: tens to hundreds of GB from storage into VRAM; cache weights on node-local NVMe or stream them from a neighbouring GPU.
  4. Engine warm-up: compilation, CUDA graph capture and memory profiling; reuse compile caches.
  5. Readiness: only after the engine answers health checks should traffic arrive.
  • Keep warm capacity for the latency-sensitive path: a minimum replica count, and spare GPU nodes so provisioning is not on the critical path.
  • Scale-to-zero suits dev, batch and rarely used models where a multi-minute first response is acceptable, not interactive production chat.
  • Set readiness and startup probes with generous initial delays so Kubernetes does not kill a replica that is still loading weights.

Admission control and queueing

Capacity always arrives later than demand, so decide what happens in the gap. An unbounded queue turns a short spike into minutes of terrible latency for everyone. Better: cap the queue per replica (or per tenant), reject excess requests quickly with HTTP 429 and a Retry-After header, and let clients back off and retry with jitter.

  • Give interactive traffic priority over batch, or run batch on separate capacity entirely.
  • Apply per-tenant rate limits and token budgets at the gateway so one customer cannot exhaust shared capacity.
  • Set request timeouts end to end so abandoned requests stop consuming GPU time; engines cancel generation when the client disconnects.
  • Shed load before the cache fills: once preemption starts, everyone gets slower.

Cost per million tokens

The arithmetic (example prices and throughput, not quotes)
text
cost per 1M tokens = GPU cost per hour / (tokens per hour / 1,000,000)

GPU at $4.00/hour, sustaining 2,500 output tokens/s at your latency target:
  tokens/hour = 2,500 x 3,600 = 9,000,000
  at 100% busy: $4.00 / 9 = $0.44 per 1M output tokens
  at 40% average utilisation: $0.44 / 0.4 = $1.11 per 1M output tokens

Two levers dominate. Throughput per GPU at your latency target (goodput, not peak), raised by batching, quantization, prefix caching and the right engine. Average utilisation, raised by autoscaling well, sharing GPUs across models, and filling quiet hours with batch work. A deployment that is twice as fast but idle 80% of the time can cost more than a slower, busy one.

  • Account for input tokens too: prefill is cheaper per token than decode but not free, and long-prompt workloads spend much of their GPU time there.
  • Reserved or committed GPUs lower the hourly price for the always-on floor; on-demand covers peaks; spot or preemptible GPUs suit batch jobs that tolerate interruption.
  • Compare against hosted APIs honestly: include engineering time, idle capacity and on-call, not just GPU-hours.
Hands-on practice

Price your own deployment

  1. From your benchmark lab results, take the highest output tokens per second that met your latency target on one GPU.
  2. Look up the on-demand hourly price of that GPU on a cloud you use.
  3. Compute cost per million output tokens at 100%, 60% and 30% utilisation.
  4. Sketch a daily traffic curve and decide minimum replicas, scale-out signal and threshold, and cooldown.
  5. Time each part of a cold start on your setup (image pull, weight load, warm-up) and pick the largest to optimise.
  6. Write a one-page capacity plan: floor, ceiling, signal, admission policy and expected cost per million tokens.
Cheat sheet

Autoscaling, queues, cold starts and cost per token — at a glance

Main things to focus on

  • Scale on queue depth, cache usage and TTFT, not CPU or GPU utilisation.
  • Cold start = provision + pull + load weights + warm-up: attack the largest.
  • Keep warm capacity for interactive traffic; scale-to-zero for batch and dev.
  • Bound queues and return 429 with Retry-After instead of letting latency explode.
  • Cost per token = hourly price / tokens per hour, divided by utilisation.
  • Throughput at your SLO and average utilisation are the two cost levers.

Formulas

$/1M tok = $/hour / (tok/s x 3600 / 1e6)At full utilisation
effective $/1M = $/1M / utilisationIdle time is paid for
replicas ~ peak tok/s / goodput per replicaCapacity at peak
cold start = provision + pull + load + warm-upWhere the minutes go

Scaling signals

sum(vllm:num_requests_waiting)Queue depth
vllm:kv_cache_usage_perc > 0.9Cache pressure
histogram_quantile(0.95, ... time_to_first_token ...)Latency risk
minReplicaCount / cooldownPeriodWarm floor and slow scale-in

Admission control

HTTP 429 + Retry-AfterReject fast under overload
per-tenant rate and token limitsIsolation at the gateway
priority classesInteractive before batch
end-to-end timeouts + cancel on disconnectStop wasted generation

Capacity options

reserved / committedCheaper always-on floor
on-demandPeaks
spot / preemptibleInterruptible batch work

Common pitfalls

  • Autoscaling on GPU utilisation, which is always high.
  • Scaling in quickly and losing replicas that take minutes to come back.
  • Unbounded queues that turn spikes into minutes of latency.
  • Quoting cost per token at 100% utilisation when real utilisation is 30%.
  • Scale-to-zero on an interactive endpoint with multi-minute cold starts.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →