High-Throughput, Low-Latency LLM Inference Serving: Architecture and Best Practices
This article explains how to build large-scale inference services that balance high throughput with low latency. It covers a five-layer architecture, traffic separation, dynamic batching and scheduling, KV cache and GPU memory management, parallelism strategies, capacity planning, observability, and common pitfalls, with deployment guidance for Baidu AI Cloud.
1. The Core Challenge: Why High Throughput and Low Latency Conflict
Large-scale inference services must handle two very different traffic types at the same time: online interactive requests and offline batch workloads. Online traffic is sensitive to time-to-first-token (TTFT) and per-request latency, while offline traffic cares mainly about the number of tokens produced per unit of compute. These goals compete for the same resources. Reducing batch size to cut latency lowers compute utilization, while accumulating requests to raise throughput increases queueing delay.
Building an inference service is therefore not a single-point optimization. It requires coordinated design across the entire pipeline: queueing, batching, computation, caching, and data transfer.
It is also important to note that throughput (tokens/s or requests/s) and latency (TTFT, TPOT, end-to-end latency) are not simply inversely related. What really determines service quality is the tail of the latency distribution and stability under heavy load. A solution that performs well only at low load often collapses during traffic spikes because queueing gets out of control.
2. Overall Architecture: Layered Decoupling and Traffic Separation
The recommended architecture has five layers:
- Access layer: handles authentication, rate limiting, routing, and protocol adaptation, unifying long-lived and short-lived connections under a common abstraction.
- Scheduling layer: maintains request queues and applies priority and fair scheduling so that large requests do not starve small ones.
- Execution layer: performs dynamic batching, parallel partitioning, and operator execution.
- Cache layer: manages KV cache and result cache, and decides how GPU memory and host memory are allocated.
- Observability layer: collects metrics, logs, and traces to drive autoscaling.
Traffic separation is a key principle: route interactive and batch requests to separate resource pools, each with its own batching window and parallelism configuration, so they do not interfere with each other.
3. Key Mechanism 1: Dynamic Batching and Scheduling
Dynamic batching is about adaptively balancing “wait to fill a batch” against “execute immediately.” Two common approaches are:
- Fixed window: the wait time is constant and easy to implement, but a large window raises latency while a small one wastes compute.
- Adaptive window: the upper bound of the window is adjusted dynamically based on queue length and measured latency, with a latency circuit-breaker threshold.
Illustrative pseudocode:
on_request(r):queue.push(r)if queue.size >= max_batch or now - oldest_ts > window:batch = queue.drain(max_batch)submit(batch)# Adaptive adjustmentif p99_ttft > target_ttft:window = max(min_window, window * 0.8)else if gpu_util < low_watermark:window = min(max_window, window * 1.2)
For scheduling, introduce priorities and quotas: interactive requests get high priority and small, fast steps; offline requests get low priority and large batches. Also set a maximum queueing time per request, fail fast on timeout, and return a clear error code to avoid cascading failures.
4. Key Mechanism 2: KV Cache Management and GPU Memory Governance
During autoregressive generation, the KV cache often consumes more GPU memory than the model weights, and its lifetime is tied to each request. Key governance practices include:
- Paged cache: split the cache into fixed-size blocks allocated on demand to reduce fragmentation.
- Prefix reuse: share cache blocks across identical system prompts or long document prefixes to significantly reduce repeated computation.
- Eviction policy: score entries by combining least-recently-used with the request’s remaining length, releasing cache for requests that are about to finish first.
- Preemption and swapping: when GPU memory is tight, swap out cache for low-priority requests to host memory or local storage, and swap it back when they resume.
Note that swapping adds extra data movement overhead. Set thresholds based on measured bandwidth to avoid frequent thrashing.
5. Key Mechanism 3: Parallelism and Compute Partitioning
The choice of parallelism directly affects both latency and throughput in LLM inference:
- Tensor parallelism reduces per-GPU memory pressure and per-token compute latency, but adds communication overhead, making it suitable for high-bandwidth interconnects within a node.
- Pipeline parallelism improves overall utilization but introduces bubbles, so it needs a reasonable number of micro-batches.
- Data parallelism raises throughput, with replicas serving requests via load balancing.
A practical rule is to “set the parallelism degree by GPU memory first, then fine-tune for the latency target.” For latency-sensitive scenarios, prefer tensor parallelism within a node. For throughput-first scenarios, add data-parallel replicas with request-level load balancing.
6. Key Mechanism 4: Elastic Scheduling and Capacity Planning
Capacity planning should be driven by load-test data, not experience-based estimates. A recommended process:
- Establish a baseline: fix the input/output length distribution and measure the throughput and latency curves of a single replica.
- Find the inflection point: locate the load level where latency starts rising non-linearly, and treat it as the safe watermark.
- Set the watermark: run at 60–70% of the safe watermark under normal conditions, leaving headroom for bursts.
- Elastic scaling: trigger scale-out and scale-in on two signals, queue length and P99 latency, to avoid misjudgment from a single metric.
Scaling out has cold-start costs, so pair it with warm-up and connection draining to prevent new instances from being overwhelmed by instant traffic.
7. Stability and Observability
Build a layered observability system: QPS and rate-limit rejection rate at the access layer, queue length and wait time at the scheduling layer, batch size and compute utilization at the execution layer, and hit rate and swap volume at the cache layer. Alerts should be based on SLOs rather than single-point thresholds, for example triggering when P99 TTFT exceeds the target for a sustained period.
Stability measures include request timeouts and retry budgets, circuit breaking and degradation (such as shortening the maximum generation length), replica isolation and fault-domain spreading, and regular chaos drills to validate disaster-recovery paths.
8. Deployment on Baidu AI Cloud
When building this kind of service on Baidu AI Cloud, you can deploy the stateless access and scheduling components on a container platform for fast scaling; store model files and cache snapshots in object storage to reduce cold-start pull time; use a message queue to buffer requests and smooth peaks; and use logging and monitoring/alerting services for full-pipeline observability and SLO alerting. These are general cloud product capabilities; refer to the official documentation for specific specifications and quotas.
9. Common Pitfalls
- Looking only at average latency and ignoring the tail, causing user experience to drop sharply at peak times.
- Blindly increasing batch size, triggering GPU memory swap thrashing and actually lowering throughput.
- Scaling on a single CPU or GPU memory metric, causing repeated scale up/down.
- Lacking a fast-fail mechanism, so requests queue indefinitely until the whole service becomes unavailable.
10. Conclusion
A high-throughput, low-latency large-scale inference service is essentially the engineering application of queueing theory and resource governance. With adaptive batching as the engine, KV cache governance as the lever, parallelism as the backbone, and elastic scheduling plus layered observability as safeguards, you can stably approach the target SLO under real traffic.
