A Practical Guide to Large-Scale Online LLM Inference Deployment
This guide breaks down large-scale online inference into four optimization layers—operators, communication, scheduling, and caching—and explains how to stabilize performance through capacity planning, autoscaling, observability, and cost governance. It covers continuous batching, prefill-decode separation, prefix caching, tiered storage, latency percentiles, canary rollouts, and common pitfalls, giving engineering teams a repeatable measure-hypothesize-validate-standardize workflow for serving LLM traffic at scale.
1. Where the Problem Starts: Capability Limits vs. Cost Limits
A large model’s capability ceiling is determined by the model itself, but what users actually experience is “a result returned within acceptable latency and at acceptable cost.” So the central problem of a large-scale inference system is not to train a stronger model, but to deliver existing capability efficiently. When call volume jumps from thousands per day to hundreds of millions, inference serving is no longer a single-machine program that “loads weights and loops over generation.” It becomes a coordinated system spanning nodes, racks, and even availability zones.
This shift has three direct consequences:
- Performance is no longer decided by a single point, but by the weakest link across four chains: operators, communication, scheduling, and caching.
- Any optimization must be tied to specific deployment conditions (chip type, interconnect bandwidth, cluster topology, traffic patterns). A context-free “universal optimum” does not exist.
- Stability and cost become first-class concerns. A single buildup of long-tail requests can trigger global queuing.
2. Thinking About Inference Serving in Four Layers
2.1 Operator Layer: Making Computation Fit the Hardware
Operators are the first line of performance. Generic implementations usually guarantee only correctness, while on specific hardware, memory access efficiency, parallelism, and data type choices determine actual throughput. Engineering work typically focuses on three things: first, operator fusion, merging adjacent normalization, activation, and element-wise operations to reduce round trips to memory for intermediate tensors; second, a data precision strategy that uses lower-bit-width compute and storage formats where precision allows, while preserving higher-precision fallback for sensitive layers; third, overlapping memory access with computation so data movement and matrix operations proceed in parallel instead of leaving the hardware idle.
It is worth stressing that operator optimization must be coordinated with model structure. Choices such as the attention implementation, masking approach, and packing strategy for variable-length sequences can significantly change actual operator efficiency.
2.2 Communication Layer: The Hidden Cost of Parallelism
When a single GPU cannot hold the model or lacks sufficient compute, you need combinations of tensor parallelism, pipeline parallelism, and data parallelism. The benefits of parallelism are explicit; the costs are often hidden in communication. Tensor parallelism introduces frequent point-to-point communication and is highly sensitive to intra-node interconnect bandwidth. Pipeline parallelism introduces bubbles that require sensible partitioning and micro-batch scheduling to compress. When scaling across nodes, network topology and the quality of collective communication implementations often matter more than raw compute.
Practical recommendations: prioritize heavy parallelism within the domain with the most abundant bandwidth, and compress cross-domain communication to a minimum; hide latency through compute-communication overlap and by merging gradient/activation transfers; and use topology-aware placement so instances in the same parallel group land within the same high-efficiency interconnect domain as much as possible.
2.3 Scheduling Layer: Rebuilding from Request-Level to Batch-Level
The scheduling challenge in online inference is that request arrival is a random process and generation length is unknown in advance. Static batching causes head-of-line blocking: one long request holds up the entire batch. The industry commonly adopts continuous batching, dynamically swapping requests in and out after each decoding step so the batch always consists of requests that can currently make progress. Going further, deploying the compute-intensive prefill phase separately from the memory-intensive decode phase, each with its own parallelism strategy and batch size, can significantly improve the balance between latency and throughput.
Scheduling also needs to work with prioritization and fairness: set quotas and priorities for different tenants so a single high-traffic tenant cannot crowd out resources; and cap or apply tiered degradation to extremely long requests to protect overall service quality.
2.4 Caching Layer: Turning Repeated Computation into Reusable Assets
Prefix caching is a high-value optimization in high-concurrency scenarios. Many requests share the same system prompt, template, or document context. Recomputing that prefix every time is continuous wasted work. Content-fingerprint-keyed prefix cache reuse can reduce that overhead to a single computation. A companion piece is tiered storage: hot data stays in GPU memory or system memory, warm data moves down to local high-speed storage, and cold data goes to object storage, with cache eviction policies balancing hit rate against capacity.
Another type is result caching, suitable for knowledge-style Q&A with deterministic output and infrequent changes. It should be used cautiously for high-temperature generation that requires diversity, to avoid homogenized experiences.
3. Capacity Planning and Elasticity: Containing Uncertainty
Capacity planning should start from a traffic profile: peak-to-valley ratio, input/output length distribution, and statistical characteristics of burst arrivals. The length distribution lets you estimate compute and memory usage per request, derive the concurrency ceiling of a single instance, and then multiply by a redundancy factor to get the instance count. GPU memory is often the hard constraint; you need to reserve space for the dynamically growing key-value cache and set a watermark that triggers rejection or queuing rather than waiting for a crash.
Elasticity is best layered: baseline instances handle normal load, elastic instances absorb peaks, and burst traffic is smoothed by ingress rate limiting and queue buffering. Scaling should allow warm-up time, since model loading and cache warming both cost time. Avoid flapping by setting cooldown windows and hysteresis bands.
Illustrative capacity estimation logic (pseudocode):
# Illustrative logic only, not a concrete APItokens_per_req = avg_input + avg_outputkv_cache_per_token = layers * 2 * kv_heads * head_dim * bytes_per_elemmax_concurrent = (gpu_mem - weight_mem - reserve) // (tokens_per_req * kv_cache_per_token)instances = ceil(peak_qps * avg_latency / max_concurrent * safety_factor)
4. Observability: No Measurement, No Optimization
Large-scale inference requires a layered observability system:
- Business layer: request volume, success rate, quota consumption per tenant.
- Service layer: time to first byte, inter-token output interval, and end-to-end latency percentiles (P50/P95/P99) rather than averages.
- Resource layer: compute utilization, memory usage and fragmentation, interconnect bandwidth saturation.
- Cache layer: prefix hit rate, eviction rate, and the ratio of requests falling back to origin.
Metrics must be drillable down to instances and parallel groups; otherwise you cannot tell whether the bottleneck is communication or load imbalance. Logs and tracing should use unified collection and centralized querying, with dedicated sampling for extremely long contexts, abnormal terminations, and repeated failures to make long-tail post-mortems easier.
5. Cost Governance: Spending Every Unit of Compute on Effective Output
The first principle of cost optimization is to reduce wasted computation: improve prefix hit rate, cut meaningless repeated decoding, and downgrade low-value requests to a smaller model or shorter output. The second is to raise resource density: use sensible batch sizes and concurrency ceilings to keep hardware highly utilized rather than highly queued. The third is tiered deployment: route traffic with different latency requirements to different resource pools so high-priority traffic is not disturbed by offline-style workloads. If a container platform is used, pair it with resource quotas, priorities, and topology constraints to reduce the extra communication cost of cross-domain scheduling.
6. Launch and Iteration: Canary, Load Testing, and Regression
Every optimization should be measurable and rollback-able. A three-step loop is recommended: first, replay traffic for offline comparison to confirm changes in latency percentiles and hit rate; then roll out canary-style by percentage and watch long-tail behavior under real traffic; finally, freeze the result as a baseline and add it to regression. Load tests should mirror the real length distribution and burst patterns—uniform load testing alone tends to produce overly optimistic conclusions.
7. Common Pitfalls
- Looking only at average latency: averages hide the long tail, and user churn often happens at P99.
- Blindly increasing parallelism: communication overhead can eat the compute gains.
- Caching without eviction: once memory is full, hit rate can collapse.
- Ignoring warm-up cost: elastic instances that start loading only after the peak arrives are not really elastic.
- Optimizing without deployment context: switch hardware or interconnect, and conclusions may fully reverse.
8. Conclusion
The essence of large-scale inference deployment is joint optimization of operators, communication, scheduling, and caching under given hardware and traffic conditions, then stabilizing the result with capacity planning, autoscaling, observability, and cost governance. In related engineering practice, Baidu AI Cloud likewise emphasizes supporting this loop with composable general capabilities (such as container platforms, object storage, log services, and monitoring/alerting). For technical teams, the most worthwhile investment is not chasing single-point tricks but building a continuous optimization mechanism of “measure, hypothesize, validate, standardize,” so model capability genuinely serves massive numbers of users at reasonable cost.
