Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Inference and servingAI guideAdvanced#inference#autoscaling#kubernetes#keda
Frame · ai-engineering / inference-serving / 11-autoscaling-and-serverless-gpus.mdGuide 070 / 103

Autoscaling LLM servers and serverless GPU hosting

Autoscaling a web service is mostly solved: watch CPU or request rate, add pods, done. LLM servers break those assumptions. GPU utilisation is a poor signal, a new replica can take minutes to become useful because it has to load tens of gigabytes of weights, and GPUs are expensive enough that idling them overnight is a real line item. This doc covers what to scale on, how to make scale-up fast, and when to hand the problem to a serverless GPU platform.

Why it matters

Traffic for LLM features is spiky: business hours, product launches, batch jobs kicking off. If you provision for peak you pay for idle GPUs most of the day. If you provision for average, queues build at peak and TTFT climbs from sub-second to tens of seconds. Good autoscaling lets you track demand with a modest buffer, and scale-to-zero lets low-traffic models cost almost nothing when unused.

How it works

Pick the right signal

  • GPU utilisation is misleading. A decode-heavy server can report high utilisation while still having room in its batch, or low utilisation while its KV cache is full and requests are queuing.
  • Request rate ignores that requests differ wildly in cost (prompt and output length).
  • Queue depth is the most direct signal of "we need more capacity". vLLM exports the number of waiting requests (vllm:num_requests_waiting), and the vLLM production stack documents KEDA autoscaling on exactly that metric.
  • KV cache usage tells you how close each replica is to preempting.
  • Latency SLOs (p95 TTFT) make good guardrails: scale up if the queue grows or latency breaches.

The AWS EKS guidance for inference pairs a queue-depth trigger with a p95 latency trigger, which is the pattern I recommend.

Rendering diagram…

Cold starts are the real problem

A new replica must: get a GPU node (which may itself need provisioning), pull a large container image, download or mount model weights, load them into GPU memory, and warm up (compile graphs, profile memory). Each step can take a long time for big models. Ways to shrink it:

  • Keep a warm minimum of replicas (minReplicaCount of one or more) for latency-sensitive models.
  • Pre-stage weights on a fast shared volume or local NVMe, or in a node image, instead of downloading from a hub on every start.
  • Slim images and pre-pulled images on GPU nodes.
  • Overprovision slightly with low-priority placeholder pods that reserve GPU nodes and get evicted when real pods need them.
  • Scale up early and down slowly. Short polling intervals with a low threshold for scale-up, longer cooldowns for scale-down.

Serverless GPU platforms

Platforms such as Modal, RunPod Serverless, Baseten and others run your container on GPUs on demand, scale replicas for you (including to zero) and bill for usage. They invest heavily in cold start tricks like snapshotting, cached weight volumes and fast container loading. The vLLM docs point to Modal's tutorial as a supported way to deploy vLLM serverlessly.

Rendering diagram…

Reference architecture

For a Kubernetes deployment I aim for: a GPU node pool managed by a node autoscaler, vLLM Deployments with readiness probes that only pass once the model is loaded, Prometheus scraping engine metrics, KEDA scaling each Deployment on queue depth with a latency guardrail, and a gateway that sheds load when all replicas are saturated (see rate limits and backpressure). Azure's KAITO and the vLLM production stack both package versions of this.

Code

A KEDA ScaledObject that scales a vLLM Deployment on waiting requests, following the vLLM production stack guide, with a latency trigger added:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: vllm-llama8b
  namespace: inference
spec:
  scaleTargetRef:
    name: vllm-llama8b
  minReplicaCount: 1
  maxReplicaCount: 8
  pollingInterval: 15
  cooldownPeriod: 300
  triggers:
    - type: prometheus
      metadata:
        serverAddress: http://prometheus.monitoring:9090
        query: sum(vllm:num_requests_waiting{deployment="vllm-llama8b"}) or vector(0)
        threshold: "5"
    - type: prometheus
      metadata:
        serverAddress: http://prometheus.monitoring:9090
        query: histogram_quantile(0.95, sum(rate(vllm:time_to_first_token_seconds_bucket{deployment="vllm-llama8b"}[2m])) by (le))
        threshold: "2"

The equivalent on Modal is a Python function wrapping the vLLM server, along the lines of Modal's own example:

import subprocess, modal

image = modal.Image.debian_slim(python_version="3.12").pip_install("vllm")
weights = modal.Volume.from_name("hf-cache", create_if_missing=True)
app = modal.App("vllm-serve")

@app.function(image=image, gpu="H100", volumes={"/root/.cache/huggingface": weights},
              scaledown_window=300)
@modal.concurrent(max_inputs=64)
@modal.web_server(port=8000, startup_timeout=600)
def serve():
    subprocess.Popen(["vllm", "serve", "Qwen/Qwen2.5-7B-Instruct", "--port", "8000"])

Label names in the PromQL depend on how your scrape config tags pods, and platform parameter names change, so check current docs before copying.

Trade-offs and pitfalls

  • Scale-up lag versus burst. If a replica takes minutes to start, the autoscaler cannot save you from a sudden spike. Keep headroom, or queue and shed load during the gap.
  • Flapping. Short cooldowns on expensive, slow-starting replicas cause churn. Scale down conservatively.
  • Scale-to-zero means a cold first request. Fine for internal tools and batch, often unacceptable for user-facing chat. Use it per model, not globally.
  • Node availability. Autoscaling pods does nothing if the cloud has no GPUs of that type in your region. Diversify instance types or regions, or reserve capacity for the baseline.
  • Prefix caches reset. New replicas start with empty KV caches, so cache hit rates dip after scaling. Sticky or cache-aware routing reduces the impact.
  • Serverless lock-in and limits. Check maximum request duration, concurrency per replica, region choice and data handling before committing.

Checklist

  • I autoscale on queue depth with a TTFT guardrail, not on GPU utilisation alone.
  • Readiness probes only pass after the model is loaded and warmed.
  • Weights are pre-staged so cold starts do not download from the internet.
  • I measured my actual cold start time end to end.
  • Scale-down cooldowns are longer than scale-up intervals.
  • Latency-sensitive models keep at least one warm replica.
  • I compared self-managed, serverless and hosted API costs for my real traffic shape.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.