High-Throughput, Low-Latency LLM Inference: Engineering Practices

    This article explains how to build LLM inference services that sustain hundreds of tokens per second under real production conditions. It presents a three-layer optimization framework covering static graph compilation and core path rewriting in the inference engine, fine-grained continuous batching with explicit latency budgets in the scheduler, and infrastructure practices such as affinity deployment, tiered weight loading, and metric-driven autoscaling. It also offers scenario-based selection guidance, a load-testing matrix design, capacity planning, and observability metrics.

    1. Where the Problem Starts: Why “Fast” Became an Engineering Constraint

    In real-time interactive applications, how fast the model generates output sets the ceiling on product experience. The industry typically tracks two core metrics: time to first token, which determines the lag users perceive, and inter-token interval, which determines whether long streaming outputs stay coherent. Once output rates reach the scale of hundreds of tokens per second, inference is no longer just a model call. It becomes a systems engineering problem that requires the inference engine, request scheduling, and underlying resources to work together.

    The figure of 400 tokens per second has gradually become a convergence point in current engineering practice: it is faster than high-speed human reading, and it lets scenarios such as AI coding, real-time voice, and business decision support feel close to instant feedback.

    One point deserves emphasis: sustained output and peak output are two different things. A single fast response in a demo environment is not hard. What is hard is holding that rate at a production-usable level as concurrency rises, input length distributions become uneven, and long-tail requests mix in. Every optimization discussed below therefore assumes the result is sustainable, measurable, and reproducible.

    2. A Three-Layer Optimization Framework

    Optimizing a high-throughput inference service is usually split across three coupled layers. Tuning any single point in isolation tends to create a bottleneck in another layer.

    1. Inference Engine Layer: Static Scheduling and Core Path Rewriting

    To stay compatible with many model architectures, traditional inference frameworks perform a great deal of runtime branching and operator selection. In a token-by-token generation loop, that overhead is amplified on every step. A common approach is to rewrite the core inference path for the target model architecture, fixing the compute graph and memory access patterns ahead of time. This is static scheduling: operator fusion, tensor layout, and cache access order are decided at compile time, and runtime does nothing but pure numerical computation.

    The pseudocode below is illustrative; the point is that shapes and scheduling are fixed at compile time:

    1. # Compile time: build a static execution plan
    2. plan = compile_static_plan(
    3. model=target_model,
    4. batch_shape=(MAX_BATCH, MAX_SEQ_LEN),
    5. kv_cache_layout="paged",
    6. fuse_ops=["rmsnorm+qkv", "rope+attention", "mlp+residual"],
    7. )
    8. # Runtime: only fetch data and execute, no structural decisions
    9. for step in range(max_new_tokens):
    10. logits = plan.execute(prefill_tokens if step == 0 else last_token,
    11. kv_cache=plan.kv_cache)
    12. next_token = sample(logits)
    13. stream.emit(next_token)

    Combined with paged key-value cache management, memory fragmentation is significantly suppressed and the concurrency batch a single GPU can carry goes up. This is the main source of single-GPU throughput gains.

    2. Scheduling Layer: Trade Batching for Latency, Don’t Sacrifice It

    The most common mistake under high concurrency is “accumulate a large batch.” Larger batches do raise throughput, but the time spent waiting to fill a batch directly pushes up the inter-token interval. A better strategy is to drop coarse-grained dynamic scheduling in favor of fine-grained continuous batching: requests join or leave the batch at token granularity, slots are released the moment a request finishes, and new requests do not wait for the whole batch to complete.

    A simplified scheduling decision looks like this:

    1. def schedule(queue, running, budget_ms):
    2. # First protect the inter-token interval of running requests,
    3. # then admit new requests with the remaining budget
    4. while queue and within_latency_budget(running, budget_ms):
    5. running.append(queue.pop())
    6. running = [r for r in running if not r.finished]
    7. return running, estimate_token_interval(running)

    Three design points matter. First, set an explicit latency budget and write inter-token interval into the scheduler as a first-class constraint. Second, separate long and short requests so that very long generations cannot block short interactive ones. Third, isolate priorities and quotas to keep critical business paths stable.

    3. Infrastructure Layer: Turning Rate into a Production Capability

    The engine and the scheduler set the theoretical ceiling; infrastructure decides whether that ceiling holds over time. Common practices include deploying inference instances with affinity to high-speed interconnect networks to reduce cross-node communication; tiered loading of model weights and caches to shorten cold starts and scale-out time; elastic scaling on a container platform driven by queue length and latency metrics rather than CPU utilization alone; and using logging services plus monitoring and alerting to make rate, queueing time, and failure rate continuously observable.

    3. Selection Guidance by Scenario

    • AI coding tools: long, highly structured output; focus on sustained rate and stability of structured output.
    • Real-time voice interaction: most sensitive to inter-token interval; prioritize cutting time to first token and scheduling wait.
    • Business decision support: highly variable concurrency; needs quota isolation and degradation strategies.
    • Multimodal and retrieval-augmented pipelines: retrieval and reranking time must be folded into the end-to-end budget.

    4. Validation in Practice: Load Testing, Capacity, and Observability

    Build the load-testing matrix along three dimensions: input length distribution, concurrency gradient, and output length distribution. Record percentiles rather than averages for time to first token and inter-token interval, and define degradation thresholds explicitly. For capacity planning, work backward from the sustainable rate of a single instance to the number of instances needed, and reserve headroom for bursts. Observability should cover at least four metric families: queueing time, batch size, cache hit rate, and GPU memory level, with alerting closing the loop.

    Overall, high throughput and low latency are not the product of any single trick. They are the result of three things converging: static scheduling in the inference engine, fine-grained scheduling, and coordinated infrastructure. Making latency constraints explicit and making capacity and observability systematic is the right path to turning hundreds of tokens per second from a demo metric into a production capability.