By KP | TZoneLabs | DevOps & Cloud Engineering
LLM inference is two different workloads sharing one name. Prefill reads the prompt in one parallel burst and is limited by compute. Decode writes one token at a time and is limited by memory bandwidth. Most serving decisions we make (how much VRAM to plan for, how to load balance, how to share a GPU, what to autoscale on) follow from that split.
This post goes deeper on serving than our AI infrastructure overview, which covers the wider platform. Each concept below is lined up against the DevOps task it mirrors, since that is the quickest way into unfamiliar territory.
The numbers in the examples are illustrative round figures, picked to show the shape of each problem. Real results depend on the model, the GPU, the serving stack and the traffic.
1. Inference and the Life of One Request
- Inference means running a trained model to answer a request. No learning happens, the weights stay fixed.
- One request goes through four steps
- Tokenize: the CPU turns the text into token IDs.
- Prefill: the GPU processes the whole prompt and produces the first output token.
- Decode: the GPU generates the rest of the answer one token at a time, streaming each token back.
- Detokenize: the CPU turns token IDs back into text.
- Like
- A request through a proxy to a backend that streams its response. The streaming part is where most of the time goes.
2. Prefill vs. Decode
- Prefill
- Processes every prompt token in one pass, in parallel.
- Compute-bound: the GPU’s math units are the limit.
- Builds the KV cache (section 4) and ends with the first token.
- Cost grows with prompt length.
- Decode
- Produces one token per pass, and every pass reads all the model weights plus the KV cache from VRAM.
- Very little math per byte read, so it is memory-bandwidth-bound.
- Runs once for every output token, so long answers mean many passes.
- They interfere
- A long prompt arriving on a busy GPU hogs it for its prefill, and every other user’s next token waits.
- Users see this as a stutter in the middle of a stream.
- Fixes: chunked prefill (split long prompts into pieces) or run the two phases on separate GPUs (section 9).
- Like
- Prefill is a bulk import: parallel and heavy. Decode is a long-lived streaming response: small chunks, one after another.
3. Latency: The Delays That Matter
- Time to first token (TTFT)
- Queue wait plus prefill. It is the “thinking” pause before anything appears.
- Inter-token latency (ITL, also called time per output token)
- The gap between tokens during decode. Around 25 ms feels smooth, which is about 40 tokens per second.
- End-to-end latency
- TTFT plus output tokens times ITL.
- Example: a 2,000-token prompt, a 300-token answer, TTFT of 0.4 s and ITL of 25 ms gives 0.4 + 300 x 0.025 = 7.9 s.
- Decode is 7.5 s of that 7.9 s, so long answers are mostly a decode problem.
- Throughput
- Tokens per second across all users. Bigger batches raise it and also raise latency, so it trades against the two above.
- What to do with them
- Set separate SLOs for TTFT and ITL, at p95 or p99.
- High TTFT usually means queueing or long prompts. High ITL usually means batches that are too big or prefill interference.
- Like
- TTFT is time to first byte. ITL is the streaming rate. We would never track only one of them on a streaming API.
4. The KV Cache
- What it is
- For every token, the model stores keys and values for each layer so decode does not recompute the whole history on every step.
- How big it gets
- It grows with context length times the number of concurrent sequences.
- Llama 3 70B (80 layers, 8 KV heads, head size 128, 16-bit values) needs about 320 KB per token, so one 8k-token sequence takes about 2.7 GB.
- 32 concurrent 8k sequences come to about 86 GB. That is more than the weights of the same model at 4-bit (about 35 GB).
- Why it matters
- The cache, not the weights, often sets how many users one GPU can serve.
- vLLM’s PagedAttention stores it in fixed-size blocks like virtual memory pages, which avoids fragmentation.
- Like
- An in-memory cache with an eviction problem, using page-style allocation.
5. Batching and Prefix Caching
- Static batching
- Collect a batch, run it, return it. Short requests wait for the longest one.
- Continuous batching
- The scheduler adds and removes requests at every decode step, so finished sequences leave and new ones join immediately.
- This is why one GPU can serve many users. Like connection pooling for the GPU.
- Prefix caching
- Requests that share a prompt start (a system prompt, a long document, earlier chat turns) reuse the stored KV cache and skip that part of prefill.
- TTFT drops sharply on prefix-heavy traffic.
- Like a Docker layer cache: unchanged layers are not rebuilt.
- The catch
- It only helps if the next request lands on the replica that holds the cache. That is a routing question (section 8).
6. VRAM vs. RAM
- What each one is
- VRAM is memory on the GPU card (HBM on data center GPUs). An H100 80 GB moves about 3.35 TB/s.
- RAM is host memory, reached from the GPU over PCIe. A PCIe Gen5 x16 link carries roughly 64 GB/s each way.
- That gap is about 50 times.
- What has to fit in VRAM
- Model weights, the KV cache, activations and framework overhead.
- If it does not fit, the process hits an out-of-memory error, or we offload to RAM and pay the PCIe penalty on every step.
- Budget example
- 80 GB card, vLLM left at its usual 90% memory target: about 72 GB usable.
- Llama 3 70B at 4-bit takes about 35 GB, which leaves about 37 GB for the KV cache.
- At 2.7 GB per 8k sequence, that is roughly a dozen concurrent long conversations.
- Where RAM still helps
- Cold cache blocks can move to host RAM or disk and come back later, which suits prefix reuse. It does not suit the active decode path.
- Weights load from disk through RAM into VRAM, so host RAM and disk speed shape cold starts.
- Like
- RAM against swap. Offloading a hot path to the slower tier works until traffic arrives.
7. CPU vs. GPU
- What each does in serving
- CPU: HTTP server, tokenization, scheduling, networking, health checks.
- GPU: the matrix math.
- The decode speed limit
- Rough ceiling for one stream: memory bandwidth divided by bytes read per token.
- An 8B model at 16-bit is 16 GB. On an H100 (3.35 TB/s) that is about 200 tokens per second at most.
- On a CPU with about 100 GB/s of memory bandwidth it is about 6.
- Real numbers come in lower, but the ratio explains why GPUs win.
- When a CPU is enough
- Small quantized models, low traffic, dev and test, edge devices (llama.cpp is the usual tool).
- A monitoring trap
- A GPU-bound server pod can sit at low CPU while the GPU is saturated, so CPU-based autoscaling misses it (section 12).
- Like
- A database on spinning disk against NVMe. It works fine until real load arrives.
8. ALB vs. llm-d
- What an ALB does well
- TLS termination, WAF, authentication, host and path routing, health checks, and round robin or least outstanding requests across targets.
- Keep it at the edge. None of that goes away.
- What an ALB cannot see
- Which replica already holds a prompt’s KV cache.
- How deep each replica’s queue is, or how full its KV cache is.
- Whether a replica is in the middle of a heavy prefill.
- What goes wrong
- A chat app with a 3,000-token system prompt. Round robin spreads one conversation’s turns across replicas, and each replica repeats the same prefill. TTFT stays high and GPU time is wasted.
- One replica collects a pile of long requests while another sits idle, and the ALB sees equal connection counts.
- llm-d
- An open-source, Kubernetes-native stack that sits on top of model servers such as vLLM. Red Hat, Google Cloud, IBM Research, CoreWeave and NVIDIA founded it, and it joined the CNCF as a sandbox project in 2026. See the llm-d repository.
- Routing uses the Gateway API Inference Extension: an InferencePool groups the model pods, and an Endpoint Picker scores each pod on prefix cache hits, queue depth and load.
- It also supports prefill/decode disaggregation (section 9).
- The project README reports about 3x output throughput and 2x faster TTFT with prefix-cache-aware routing against round robin. That is for prefix-heavy workloads. With unique prompts there is little to gain.
- Typical layout
- ALB with WAF at the edge, then the llm-d gateway inside the cluster, then vLLM pods.
- One ALB gotcha
- The idle timeout defaults to 60 seconds. A non-streaming request that takes longer to produce its answer gets cut. Stream tokens, or raise the timeout.
- Like
- Round robin against consistent hashing on a cache key in front of a cache cluster. The second one is what keeps the hit rate up.
9. Prefill/Decode Disaggregation
- The idea
- Run prefill on one pool of GPUs and decode on another. The KV cache moves from the prefill pod to the decode pod over a fast transfer path (llm-d uses NIXL by default).
- Why
- The two phases have different bottlenecks, so each pool can scale and be tuned on its own.
- Long prompts stop stalling other users’ decode.
- Cost
- The cache transfer needs a fast network, and there is more to operate.
- Short prompts do not benefit, so llm-d can skip disaggregation below a token threshold.
- It pays off at scale with long prompts, and it is overkill for a small deployment.
- Like
- Splitting a monolith into a batch tier and a serving tier so each scales on its own.
10. GPU Time-Slicing
- What it does
- The NVIDIA device plugin advertises one physical GPU as N schedulable GPUs, and pods take turns on it.
version: v1
sharing:
timeSlicing:
resources:
- name: nvidia.com/gpu
replicas: 4
- What it does not do
- No memory isolation: every pod can allocate the full VRAM.
- No fault isolation: a crash or out-of-memory error in one pod can hit its neighbors.
- No guaranteed share of compute, so latency jitters.
replicas: 4is four turns, not four quarters of memory. Four pods that each load a 30 GB model onto an 80 GB card will run out of VRAM by the third.
- Where it fits
- Works on any NVIDIA GPU, including older ones that lack MIG.
- Good for dev, notebooks and light, bursty jobs. Poor for latency-sensitive production. See the NVIDIA GPU Operator docs.
- Like
- CPU overcommit with no limits. Fine until a noisy neighbor shows up.
11. MIG (Multi-Instance GPU)
- What it does
- Splits one GPU in hardware into up to 7 instances. Each gets its own compute units, memory, cache and memory bandwidth.
- Memory and fault isolation, so a neighbor cannot starve or crash an instance.
- Where it runs
- A30, A100, H100, H200 and Blackwell data center GPUs. Not T4, V100 or A10.
- Profiles are fixed
- On an H100 80 GB, examples are 1g.10gb (seven of them), 2g.20gb, 3g.40gb and 7g.80gb.
- With the mixed strategy a pod requests a slice by name, for example
nvidia.com/mig-1g.10gb: 1.
- Sizing trap
- A 1g.10gb slice has 10 GB. An 8B model at 16-bit needs 16 GB, so it will not load. Use a 2g.20gb slice or quantize the model.
- Operational limits
- Repartitioning is disruptive: workloads have to leave the GPU first, so plan profiles per node pool.
- MIG is not a full security boundary for tenants who do not trust each other.
- Like
- cgroup limits with hard caps, against overcommit with none.
| Sharing mode | Memory isolation | Fault isolation | Best for |
|---|---|---|---|
| Time-slicing | None | None | Dev, notebooks, bursty jobs |
| MPS | Partial (limits can be set) | None, one fatal fault reaches every client | Cooperating processes on one GPU |
| MIG | Hardware | Hardware | Production inference with predictable latency |
Time-slicing and MPS cannot be combined, and in the GPU Operator neither can MPS and MIG. MIG with time-slicing on top is possible, and the workloads sharing one slice still share its memory.
12. Autoscaling Inference
- CPU percentage is the wrong signal
- The GPU can be saturated while the pod’s CPU looks idle.
- Better signals
- Requests waiting in the queue, KV cache utilization, and p95 TTFT.
- vLLM exposes these as Prometheus metrics. Exact names change between versions, so check yours.
- Cold starts shape the policy
- A new replica loads tens of GB of weights before it can serve, and GPU nodes can take minutes to arrive.
- Keep a warm minimum, scale on early signals, and cache weights on the node.
- Like
- An HPA on custom metrics. Our HPA setup guide and Cluster Autoscaler guide cover the mechanics.
13. Speculative Decoding
- How it works
- A small draft model guesses the next several tokens. The large model checks all of them in a single pass, the same parallel way prefill works, and keeps the ones it agrees with.
- The output is identical to what the large model would produce alone.
- Why it helps
- Decode is limited by memory reads, so verifying several tokens per pass gets more tokens out of each read of the weights.
- The gain depends on how often the draft is right.
- Like
- Branch prediction or optimistic execution: do the likely work early, discard it when wrong.
Key Lessons
-
Prefill and decode have different bottlenecks.
Prefill is limited by compute and decode by memory bandwidth, so a fix for one rarely helps the other. -
Size VRAM for the KV cache, not only the weights.
Concurrency and context length decide how much cache we need, and that often exceeds the model itself. -
Track TTFT and inter-token latency separately.
One average hides whether users are waiting to start or stuttering mid-answer. -
Route by cache, not by round robin.
An ALB stays at the edge, and inference-aware routing such as llm-d decides which replica gets the request. -
Match the sharing mode to the isolation we need.
Time-slicing for dev, MIG for production, and plan MIG profiles around real model sizes.
Summary
| Concept | DevOps Equivalent | What to Watch |
|---|---|---|
| Prefill | Bulk import | TTFT, prompt length |
| Decode | Streaming response | Inter-token latency |
| KV cache | In-memory cache with eviction | Cache utilization |
| VRAM vs. RAM | RAM vs. swap | VRAM headroom, OOM errors |
| ALB vs. llm-d | Round robin vs. consistent hashing | Prefix cache hit rate, queue depth |
| Time-slicing | CPU overcommit | Neighbor OOMs, latency jitter |
| MIG | Hard resource limits | Profile fit, repartition windows |
| Autoscaling | HPA on custom metrics | Queue depth, p95 TTFT |
If we already run caches, load balancers and autoscalers, we know the shape of all of this. What changes is that the cache is the bottleneck and the load balancer needs to read it.
Read Next
- AI Infrastructure for DevOps People
- Setting Up Horizontal Pod Autoscaler on Kubernetes: The Settings That Actually Matter
Follow along on LinkedIn to catch the next post when it goes up.
Tags:
#LLMInference #AIInfrastructure #GPU #Kubernetes
#MLOps #DevOps