How to Use, Optimize, and Serve an LLM in Your Production System
From the publisher’s feed, collected in the ZeroLabs newsroom.
A plain guide for engineers who just deployed an LLM and realized the hard part hadn’t even started yet.Image by AuthorIs Your Project Asking Any of These Questions?You shipped the demo. The model works. Stakeholders are happy. Then real traffic hits, and suddenly:“Why is the first response taking 3 seconds?”“We’re burning $8,000/month on GPU bills — there has to be a better way.”“The model is fast in testing but crawls under load. What’s going on?”“We tried vLLM, TensorRT-LLM, and SGLang — which one do we actually use?”“Our P99 latency is 4 seconds but P50 is fine. What does that even mean?”“Can we fit a 70B model on two GPUs without destroying the quality?”“Batch inference is killing our real-time users. How do we fix this?”If any of these hit close to home — this is exactly the guide you need. And if you want to go really deep, I wrote a 3-part technical series on Medium that covers every layer of this problem from GPU kernels to cluster scaling. This article is the map. The series is the territory.Why This Problem Is Harder Than It LooksDeploying an LLM isn’t like deploying a REST API. A Flask endpoint is stateless, horizontally scalable, and usually CPU-bound. An LLM inference server is none of those things.Here’s what makes it genuinely hard:1. Two completely different compute phases, back to backEvery LLM request has two phases. The prefill phase reads your prompt — it’s compute-intensive, runs fast, and can process many tokens in parallel. The decode phase generates the response one token at a time — it’s memory-bandwidth-bound and inherently sequential. The bottleneck for each phase is different hardware resource. Optimizing one without the other gets you half the gains.2. The GPU’s memory is both the product and the bottleneckThe model weights live in GPU memory (VRAM). The “KV cache” — the stored attention state for every active request — also lives in GPU memory. These two fight each other. A 7B model in FP16 alone eats 14 GB of VRAM. On a 40 GB A100, that leaves 26 GB for batching real users. How you manage that 26 GB determines whether you serve 4 concurrent users or 40.3. Latency and throughput are oppositesThe things that make throughput high (large batches, long waits for requests to fill the batch) make latency worse. The things that make latency low (small batches, immediate dispatch) waste GPU capacity. Production systems have to serve both interactive users who need sub-500ms responses and background jobs that need to process millions of documents cheaply. You can’t use one configuration for both.4. The ecosystem moves fast and breaks thingsvLLM, SGLang, TensorRT-LLM, TGI — the inference engine landscape has had major changes in 2025 and 2026. What was best practice 12 months ago may be outdated or deprecated today (TGI, for example, was fully archived in March 2026 — if you’re still building on it, you need to migrate).The Three-Layer Mental ModelEvery production LLM problem lives in one of three layers. This is the organizing principle of the full series:┌─────────────────────────────────────────────────────┐│ Layer 3: ENGINE CHOICE ││ Which inference runtime? vLLM, SGLang, TRT-LLM? │├─────────────────────────────────────────────────────┤│ Layer 2: SERVING SYSTEM ││ Queuing, traffic routing, autoscaling, SLAs │├─────────────────────────────────────────────────────┤│ Layer 1: THE MODEL ITSELF ││ Quantization, attention, GPU kernels, KV cache │└─────────────────────────────────────────────────────┘Most engineers start at Layer 3 (picking an engine) and then discover their problems are actually in Layer 1 or 2. The right order is bottom-up: make the model efficient, then make the serving layer stable, then pick the engine that fits your workload.Let’s walk through each layer.Layer 1 — Making the Model Itself FasterThe Core Insight: Decode Is Starving Your GPUModern GPUs have hundreds of TFLOPS of tensor core capacity. But when generating tokens one-by-one, the GPU is actually just reading weights from memory and doing almost no math on them. The arithmetic intensity during decode is roughly 1 FLOP per byte of memory read. To actually saturate tensor cores, you need over 200 FLOP/byte. This means for most of the request lifetime, your expensive GPU is sitting idle at maybe 5–15% compute utilization, bottlenecked entirely on memory bandwidth.This is why quantization and caching work so well — they don’t make the math faster, they reduce how much data the GPU has to haul across the memory bus per step.The Five-Level Optimization LadderLevel 1 — BF16 + Flash Attention (free wins, zero quality loss)Flash Attention rewrites the attention operation to avoid materializing the full N×N attention matrix in GPU memory. Instead of writing intermediate results back to slow HBM (High Bandwidth Memory) and reading them again, it fuses the operation into a single GPU kernel that stays in fast on-chip SRAM. The result: 30–50% faster prefill on prompts longer than ~2K tokens, with zero change to model quality. It’s already enabled by default in vLLM and SGLang. If you’re running anything else, check that it’s on.Level 2 — INT8 Quantization (1.5–2× batch size, negligible quality loss)Storing weights as 8-bit integers instead of 16-bit floats cuts memory use in half. The perplexity degradation is under 0.1% on standard benchmarks [1] — essentially invisible. This means you can fit twice the model (or twice as many concurrent users) into the same VRAM. Libraries like bitsandbytes make this a one-line change.Level 3 — INT4 Quantization / AWQ / GPTQ (3–4× memory, 2–3× throughput)Taking quantization further to 4-bit gives you a 4× memory reduction. The challenge is doing it without quality collapse. Two methods have emerged as production-grade:AWQ (Activation-Aware Weight Quantization): Instead of quantizing all weights equally, AWQ identifies which weights actually matter (by looking at activation magnitudes) and protects them with higher precision. This is the recommended default for quality-sensitive deployments.GPTQ: Uses a Hessian-based approach to minimize quantization error per layer. For inference speed, set desc_act=False — it's 2–3× faster at inference time with minimal quality trade-off.Both are well-supported in vLLM and SGLang.Level 4 — Paged KV Cache + KV Cache Quantization (2–3× concurrency)The KV cache is where LLMs store the attention states for all active requests. Without memory management, this space gets fragmented — you might have 40% of your VRAM technically allocated but unusable because it’s scattered in non-contiguous chunks. vLLM’s PagedAttention solves this the same way an OS solves memory fragmentation: by managing KV cache in fixed-size pages (16–64 tokens each), GPU memory utilization typically improves from ~45% to ~85%.On top of that, you can quantize the KV cache itself to FP8 (8-bit floating point). The cost is ~5–10% throughput reduction. The benefit is that the same VRAM can now hold twice as many active requests. At scale, that trade is usually very worth it.Level 5 — Speculative Decoding + Tensor ParallelismSpeculative decoding uses a small “draft” model to predict several tokens ahead, then verifies them all at once with the main model. If the predictions are mostly right (which they often are for common phrases and patterns), you effectively generate multiple tokens per main-model forward pass. This can cut TTFT and per-token latency by 2–3× on the right workloads.Tensor parallelism splits the model across multiple GPUs. It’s the standard approach for 70B+ models that don’t fit on a single GPU.Most teams stop at Level 3 and see TTFT drop from ~800ms to ~250ms, and throughput improve from ~30 to ~80 tokens/second. Levels 4 and 5 are for teams with serious production scale.To see the exact code implementations for these techniques, check out Part 1 of my series on Medium. https://medium.com/@abir.aust.102/3-part-series-llm-latency-in-production-part-1-babc85a2128aLayer 2 — Building a Serving System That Doesn’t Fall Apart Under LoadThe Counterintuitive Truth: Your Latency Problem Is Probably Queueing, Not ComputeHere’s something most people don’t realize: once a model is reasonably optimized, P95 and P99 latency are almost never caused by the GPU being slow. They’re caused by requests waiting. A request that takes 50ms of actual GPU work can easily spend 800ms in queue because the batch scheduler waited for one more request, or because a 4K-token document summary monopolized the prefill slot while 12 chat queries waited.The Traffic Lanes PatternThe single most impactful serving change most teams can make is also the simplest: run interactive traffic and batch traffic on separate replicas.Interactive users (chat UI, streaming responses) need low Time-to-First-Token. They can tolerate lower throughput. Batch jobs (document summarization, embedding pipelines) need high throughput. They can tolerate higher latency. These two workloads want opposite things from the scheduler. Forcing them to share a GPU means one will always suffer.vLLM lets you tune this per instance:Interactive lane: --max-num-seqs 4 (small batches, fast dispatch)Batch lane: --max-num-seqs 16 (large batches, maximum throughput)Add short-prompt vs. long-prompt splitting and you’ve removed the most common source of P99 spikes in production.Measure the Right ThingsMost teams log “total request time.” This is nearly useless for diagnosis. Log these instead, on every request:TTFT (Time-to-First-Token) — User-perceived responsiveness. This is the number users feel.TPOT (Time Per Output Token) — Decode speed, e.g. 20 ms/token. The inverse of tokens-per-second.Queue wait time — How long the request waited before the GPU touched it. If this is high, your problem is the serving layer, not the model.Prefill time — Cost of reading the prompt. Spikes here mean long prompts or Flash Attention is off.Decode time — Cost of generating the response. Spikes here mean quantization or batching issues.P95/P99 per traffic lane — Not global P99, but per-lane. Interactive vs. batch. Short vs. long prompt.Per-lane P99 is especially important. If you mix 50-token chat queries with 4K-token RAG summaries, global P99 will always look terrible and always be caused by the wrong thing.Backpressure, Admission Control, and Graceful DegradationProduction systems need a way to say “no” before they fall over. The right approach:Admission control: Return HTTP 429 Too Many Requests (or 503 Service Unavailable) when the queue depth exceeds a threshold. This is far better than letting requests queue for 30 seconds and then timeout.Streaming backpressure: If a client is consuming tokens slowly (e.g., a mobile app on a slow connection), don’t let it pin GPU memory indefinitely. Use a bounded async queue between the inference engine and the network layer.Cancel-on-disconnect: If a user closes the browser tab, stop generating. Sounds obvious; most teams don’t implement it.Cold Start and AutoscalingLLM replicas are expensive to start. Weight loading, KV cache allocation, and warmup can add 30–90 seconds to a cold start. During an autoscale event, this means the new replica can’t help for over a minute — and during that minute, remaining replicas absorb the full load spike.Two mitigations:Keep minReplicaCount: 2 at all times. Never scale to zero for production models.Scale on vllm:num_requests_waiting (the queue depth metric), not CPU/GPU utilization. By the time utilization-based autoscaling triggers, users are already waiting.For a deep dive into serving architectures and traffic routing, read Part 2.https://medium.com/@abir.aust.102/part-2-serve-level-speed-system-design-that-stabilizes-p95-p99-61543d856588Layer 3 — Choosing the Right Inference EnginevLLM — Best for generalist production workloads, multi-LoRA, and broad model support. The default choice for most teams. Trade-off: not quite peak throughput on narrow, well-defined workloads.SGLang — Best for high-throughput APIs and shared-prefix workloads (RAG, few-shot prompting). Used at xAI and Microsoft Azure scale. Trade-off: multi-GPU ops less mature than TRT-LLM.TensorRT-LLM — Best for maximum raw throughput on NVIDIA hardware and latency-SLA-bound systems. Trade-off: requires compilation (~28 min for a 70B model [2]), more complex setup.llama.cpp — Best for edge, local development, CPU, or Apple Silicon. Runs anywhere. Trade-off: not for production GPU serving at scale.LMDeploy — Near-SGLang throughput with simpler setup. Trade-off: smaller community and fewer integrations.The Decision ShortcutsIf you’re starting fresh: Use vLLM. It has the broadest model support, the most production documentation, and is the default choice for most teams in 2026.If your workload is primarily RAG or few-shot prompting (many requests that share a long system prompt or set of examples): Use SGLang. Its RadixAttention automatically caches shared prefixes, giving you ~29% higher throughput on these workloads compared to vLLM [3].If you need the absolute lowest latency and have NVIDIA hardware: Compile with TensorRT-LLM. The compilation time is a one-time cost. The runtime performance is the best available on NVIDIA GPUs.If you’re on the edge or local hardware: llama.cpp. It runs on anything.To see the comprehensive engine benchmarks and decision matrix, read Part 3.https://medium.com/@abir.aust.102/part-3-implementation-engine-level-choosing-the-runtime-that-gives-you-these-for-free-b0e9081205b0The Full Picture — Why All Three Layers Matter TogetherHere’s how the layers interact in a real production scenario. Suppose you have a 7B model serving a chat application with 500 concurrent users:Layer 1 (model optimization): You apply AWQ INT4 quantization. The 14 GB FP16 model shrinks to ~4 GB. VRAM freed up for KV cache. TTFT drops from 800ms to ~250ms.Layer 2 (serving system): You split interactive and batch traffic into separate replicas. You add admission control at depth > 20 requests. You configure KEDA to scale on vllm:num_requests_waiting and keep minReplicaCount: 2. P99 drops from 3.5 seconds to ~600ms.Layer 3 (engine choice): You’re using SGLang because your chat product has a long shared system prompt. RadixAttention caches it automatically. Every request after the first skips re-computing 500 tokens of prefill. Throughput increases by ~29%.None of these three layers alone gets you there. The model optimization means nothing if the queueing system serializes every request. The serving system tuning means nothing if the model is eating all the VRAM. The engine choice means nothing if you haven’t quantized.TL;DR — The One-Page Cheat SheetSlow first token (high TTFT)? Layer 1 + Layer 2. Quantize to INT4/AWQ, split traffic lanes, add prefix caching.High GPU cost or low concurrency? Layer 1. Quantize the model, enable paged KV cache, consider KV FP8 quantization.P99 much worse than P50? Layer 2. Switch to per-lane metrics, add admission control (HTTP 429), implement cancel-on-disconnect.Crashing under load? Layer 2. Add backpressure with a bounded queue, scale on queue depth not GPU utilization.Not sure which engine to use? Layer 3. Start with vLLM. Move to SGLang if your workload is RAG or few-shot heavy. Use TRT-LLM only if you have hard latency SLAs and NVIDIA hardware.Model doesn’t fit on one GPU? Layer 1 + Layer 3. Quantize first — a 70B model at INT4 fits on two 40 GB A100s. Add tensor parallelism only if quantization isn’t enough.Cold starts causing latency spikes? Layer 2. Set minReplicaCount: 2, send warmup prompts on startup, and scale proactively on queue depth.Written by Mehedi Hasan Abir — AI Engineer building production-grade Document AI, Speech AI, and LLM extraction pipelines.References[1] T. Dettmers et al., “LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale,” arXiv preprint arXiv:2208.07339, 2022.[2] NVIDIA, “TensorRT-LLM Documentation and Performance Benchmarks,” 2026. [Online]. Available: https://github.com/NVIDIA/TensorRT-LLM.[3] L. Zheng et al., “SGLang: Efficient Execution of Structured Language Model Programs,” arXiv preprint arXiv:2312.07104, 2023.How to Use, Optimize, and Serve an LLM in Your Production System was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.