Low-Latency LLM Inference in Production: Engineering Practices for Engine, Scheduling, and Infrastructure
For real-time LLM services, what users actually feel is not parameter count but time to first token, sustained output rate, and whether tail latency holds up at peak. Many teams see strong throughput offline, then lose speed in production to scheduling jitter, memory fragmentation, and cross-node synchronization. Making high throughput and low latency a production capability requires tightening the inference path, the batching strategy, and the infrastructure at the same time — not just swapping in a faster accelerator.
Where the Problem Comes From
Generative inference behaves differently from traditional online serving. Prefill processes the entire context in one pass and is compute-bound; decode is autoregressive, memory-bandwidth-bound, and the remaining length of each request is unknown in advance. If you keep the generic scheduler that dynamically inserts, preempts, and reorders requests at any moment, kernel launches, memory reallocation, and batch reassembly repeatedly interrupt the decode pipeline. Under high concurrency, average speed still looks acceptable, but P99 latency degrades quickly — real-time voice and interactive coding break first.
So the engineering goal should be written as verifiable constraints, not slogans: under an agreed concurrency level and context length, sustained output rate stays within a business-acceptable band, time to first token and tail latency have upper bounds, and long-running operation does not drift because of fragmentation or hotspots. The specific numbers must be measured by replaying your own traffic; peak figures from public marketing material are not a capacity planning input.
Three Layers That Must Be Optimized Together
Inference Engine: Make the Core Path Statically Orchestrated
Dynamic graphs are flexible and suit research iteration; the production decode path should be as fixed as possible. Common practices:
- Identify the two main paths, prefill and decode, and reduce runtime branching and temporary tensors.
- Compile hot operators such as attention, layer normalization, and sampling for fixed shapes or a limited set of shape buckets, to cut kernel launch overhead.
- Describe with static orchestration “which caches are read at each step, which tokens are written, and when synchronization happens,” so dependency analysis is not redone every step.
- Rewrite memory access order for single-GPU or single-node throughput so the key-value cache stays contiguous and aligned, reducing bandwidth waste during decode.
Static does not mean variable length is impossible. In practice you prepare several length buckets and align each incoming request to the nearest one, trading padding for predictable execution time. Too many buckets increases compilation and cache versions; too few wastes compute. Choose them from the real length distribution.
A schematic scheduling description can be very simple — the point is to take “what happens at each step” out of runtime decisions:
prefill(batch_bucket, seq_bucket) -> kv_cacheloop until stop:decode_step(static_graph, kv_cache) -> next_tokenif batch_changed_only_at_boundary:rebatch()emit tokens at steady rate
Batches are only re-formed at boundaries; no rescheduling happens inside a decode step. This is the main source of gain after giving up fully dynamic scheduling end to end: execution time becomes predictable and the rate curve flattens.
Scheduling: Use Dynamic Batching to Buy Latency Under Concurrency
At high concurrency, one request must not monopolize the GPU, and you cannot dump unlimited requests into the same batch. Dynamic batching has to consider three things at once.
- Batch width. Wider batches raise compute utilization but lengthen each step, hurting the inter-token interval of every request.
- Waiting window. Waiting a few extra milliseconds to fill a batch can cancel out the decode speedup; real-time voice is especially sensitive.
- Fairness and preemption. Long-context requests occupy key-value cache, and if short requests cannot be inserted promptly, the interactive experience “freezes intermittently.”
A reasonably safe strategy: adjust the decode batch at fixed time slices or fixed step boundaries; send new requests to the prefill queue first and merge them into the decode batch once prefill completes; give interactive traffic a smaller waiting window and higher priority; throttle extremely long contexts separately so they cannot drag down the whole batch. Continuous batching lets completed sequences leave the batch at any time and new sequences join at boundaries, but the join frequency must be controlled, or you slide back into dynamic jitter.
Do not measure only average token speed. Record time to first token, quantiles of the inter-token interval, batch utilization, queue wait, and rejection rate together. A high average with a doubled P99 inter-token interval still fails for real-time scenarios.
Infrastructure: Make the Rate Hold Up in Production
Even with the engine and scheduler tuned, the environment can still cap your rate. Typically you need to coordinate:
- Compute and network topology. With multi-GPU tensor or pipeline parallelism, overlap collective communication with decode steps instead of hard-synchronizing every step.
- Memory pool. Manage the key-value cache in pages or blocks to limit fragmentation, and reserve some memory for bursty lengths rather than filling the device completely.
- Service mesh and gateway. Streaming output should minimize intermediate buffering, so the application layer does not re-aggregate the smooth model-side rate into large batches.
- Observability. Break latency down by model version, context bucket, and batch width, separating queueing, prefill, and decode.
- Elasticity. Scale on queue depth and tail latency, not GPU utilization alone. Low utilization is sometimes a deliberate latency margin.
Only when the time budgets of all three layers add up within the constraints is a high output rate genuinely stable and usable, rather than an instantaneous peak in a demo environment.
How to Make Scenario Trade-Offs
Different businesses define “fast” differently, and the parameters cannot be shared.
- AI coding and completion. Time to first token and the first few tokens matter most, contexts are often very long, and prefill is the bottleneck. Limit completion length, cache common prefixes, and give short completions higher priority.
- Real-time conversation. Sustained output must be even — avoid one sentence fast and the next slow. Keep the batch waiting window short and the sampling path simple and predictable.
- Business analysis and decision support. Slightly higher time to first token is acceptable, but the complete answer must finish within the time limit. A somewhat wider batch can raise throughput, combined with a truncation policy for very long generations.
- Real-time voice. The end-to-end budget includes speech recognition, text generation, and speech synthesis. The token interval on the text side must be stable, otherwise perceived pauses are amplified. This traffic should not be co-located with offline long-running jobs.
Co-location is the most common production failure point. Offline batch jobs pursue wide batches and full utilization; online traffic pursues short queues. At minimum, isolate queues, priorities, and key-value cache quotas; isolate compute resources as well where conditions allow.
Capacity Planning and Acceptance
Before launch, use replay rather than synthetic uniform traffic. Cover at least: the context length distribution, peak and burst arrival rates, differences in stop conditions, and slow-consuming streaming clients. Slow consumers inflate server-side buffers in reverse, producing “the model is fast but the user still feels stuck.”
Break acceptance into four items:
- Functional correctness. With identical sampling settings, the static graph and the original dynamic path produce output distributions within an acceptable difference, and special tokens and stop conditions match.
- Latency. P50/P95/P99 of time to first token, inter-token interval, and end-to-end latency meet the scenario budget.
- Stability. Long-duration load testing shows no obvious memory leaks, rate drift, or retry storms.
- Degradation. Under overload, fail fast or shorten generation instead of queueing indefinitely.
The tuning order should also be fixed, otherwise metrics mask each other. First ensure numerical correctness and stop conditions, then tighten the single-request decode path, then tune batching and priorities, and only last do multi-GPU and infrastructure overlap. Change one main factor per step and keep the replay baseline.
Common Pitfalls
Treating peak throughput as committed capacity. Peaks usually come from micro-benchmarks with fixed length, no pauses, and no network; variable length and streaming in production traffic land well below that number.
Optimizing only kernels and not the queue. If kernels are 20% faster but the gateway buffers an extra 100 ms, the user notices nothing.
Assuming bigger batches are always better. Past the compute or bandwidth inflection point, step time rises, interactive latency worsens, and throughput gains flatten.
Ignoring prefix and cache hits. Reusing the key-value cache for repeated system prompts and shared code context is often more worthwhile than shaving another decode operator.
Comparing versions in an unisolated cluster. Network and disk jitter from neighbor workloads distort latency comparisons and make conclusions irreproducible.
Suggested Rollout Order
- Define the scenario budget: time to first token, average inter-token interval, tail latency, maximum context, target concurrency.
- Derive the length distribution and arrival process from real logs, and separate online from offline traffic.
- Fix the decode main path, complete static orchestration and length bucketing, and flatten the rate on a single GPU first.
- Introduce controlled continuous batching, re-form batches only at boundaries, and protect interactive priority separately.
- Add cache management, the streaming path, and quantile monitoring, then consider scaling to multiple GPUs.
- Build the capacity curve with replay: increase concurrency from low to high, mark the point where tail latency crosses the budget, and admit traffic according to that point rather than the peak.
Low latency is not a single framework parameter; it is the joint result of engine determinism, scheduling restraint, and infrastructure that does not hold you back. Once the time budgets of all three layers are observable and regression-testable, real-time coding, conversation, decision support, and voice pipelines have a stable engineering foundation. The concrete deployment shape can rest on common capabilities such as container platforms, load balancing, and monitoring and alerting — the key is to keep validating with the same set of quantile metrics rather than relying on a single demo run.
