High-Concurrency LLM Inference Architecture: Design and Engineering Practices

    This article breaks down the architecture of high-concurrency large language model inference services and translates it into practical engineering guidance. It explains why real bottlenecks appear under production traffic, how to split a request path into six layers, and how continuous batching and KV cache management drive throughput. It also covers prefix caching, multi-turn state handling, elastic scaling, stability safeguards, observability metrics, and capacity evaluation through replay load testing, ending with a deployment checklist. Readers will get a vendor-neutral framework they can map onto general cloud building blocks such as object storage, message queues, container platforms, logging, and monitoring.

    1. What a High-Pressure Blind Test Reveals About Real Bottlenecks

    Before launch, a general-purpose LLM service is often put through a period of anonymous blind testing on an aggregated API-calling platform. The value of such a test is that it places the model in real, uncontrolled, unoptimized traffic and surfaces problems that lab benchmarks cannot cover. In the source material, a new model processed roughly 44 trillion tokens during the blind-test window and ranked first in weekly call volume. Setting the specific product aside, the part of this that actually matters to an engineering team is the three facts it reveals.

    First, call volume is heavily long-tailed. A small number of heavy users generate most of the tokens, while the majority issue only occasional requests, so capacity planning cannot be based on averages. Second, the distribution of input and output lengths is extremely uneven. Code completion requests have short inputs and short outputs; document analysis and long-form generation requests can carry tens of thousands of input tokens, and the time a single request occupies GPU memory and compute can differ by one to two orders of magnitude. Third, traffic has clear peaks and troughs, and bursts during the blind test can multiply several times within a minute.

    The bottleneck of an inference service, therefore, is usually not “can the model compute the right answer” but “under limited GPU memory and compute, how well can concurrent requests be queued, batched, reused, and scheduled.” That is the starting point for every architectural decision that follows.

    2. Layered Architecture: Splitting a Request into Six Controllable Layers

    A mature high-concurrency inference service should be split by responsibility into six layers, with explicit contracts between them to avoid coupling.

    1. Access layer: protocol adaptation, authentication, rate limiting, and request normalization, turning calls from different sources into a single internal standard request structure.
    2. Scheduling layer: queue management, priority assignment, and admission control, deciding which requests run now, which wait, and which are rejected quickly.
    3. Execution layer: where the model’s forward computation actually happens, with batching strategy and GPU memory usage as the core concerns.
    4. Cache layer: reuse of prefixes, system prompts, and repeated question-answer pairs to cut redundant computation.
    5. State layer: session context, multi-turn conversation history, and intermediate results, typically served by a low-latency key-value store or cache service.
    6. Observability layer: metrics, logs, and distributed tracing, providing the basis for capacity decisions and fault localization.

    The key benefit of layering is fault-domain containment. When the execution layer starts queuing because of an extremely long input, the access layer can still return rate-limit responses normally instead of the whole system collapsing.

    3. Batching and GPU Memory Management: The First Principles of Throughput

    Throughput gains in inference come fundamentally from merging the computation of multiple requests into a single operator call. In engineering practice, two phases are usually distinguished: the prefill phase, which processes the input prompt and is compute-intensive, and the decode phase, which generates token by token and is memory-bandwidth-intensive. Because the two phases behave differently, scheduling them together causes mutual blocking.

    The common approach is continuous batching: instead of waiting for an entire batch to finish, a new request is inserted the moment one completes, keeping the batch full. Illustrative logic:

    1. while engine.running:
    2. batch = scheduler.form_batch(max_tokens=BUDGET)
    3. outputs = engine.step(batch) # one forward pass, shared across requests
    4. for req, out in zip(batch, outputs):
    5. if out.finished:
    6. stream.send(req.id, out.text)
    7. scheduler.release(req)
    8. scheduler.admit(waiting_queue) # refill promptly

    On the memory side, the central tension is that the KV cache grows linearly with context length. In practice, paged cache block management reduces fragmentation, capping the maximum context and maximum generation length per request sets an upper bound, and a dedicated queue for long requests keeps them from occupying batch slots for extended periods. Quantization, operator fusion, and more efficient attention implementations are all general optional optimization directions, and their gains must be measured rather than inferred from parameters.

    4. Cache Reuse and Cost Structure Optimization

    In real traffic, system prompts, tool descriptions, and few-shot examples tend to repeat across a large number of requests. Caching and reusing the computation of that prefix can significantly reduce redundant compute. Three engineering points matter: the cache key design must include the model version and a hash of the full prompt to avoid incorrect reuse caused by version drift; a sensible eviction policy and capacity ceiling must be set; and the invalidation path must be explicit, so that any prompt change invalidates the entry entirely.

    For multi-turn conversations, externalizing history to the state layer and sending only the incremental part to the execution layer both shortens the input and lowers the risk of state inconsistency. Cost optimization should also look at the output side: set a reasonable maximum generation length for cases where truncation is acceptable, and constrain the format first for structured output to reduce wasted tokens.

    5. Elastic Scaling and Stability Safeguards

    Facing minute-level traffic spikes, capacity strategy should be layered: always-on resources guarantee baseline latency, elastic resources absorb peaks, and queues provide buffering. Scaling signals should not be request counts alone; queueing duration, average in-batch length, and GPU memory watermarks are better choices because they sit closer to real pressure.

    For stability, four practices are recommended: rate limiting and tiered quotas at the entry point to protect critical callers; timeouts and retries paired with idempotency keys to avoid duplicate billing and duplicate side effects; explicit error codes and a degradation path for extremely long inputs; and replica isolation in the execution layer so an unhealthy replica can be removed quickly. If a container platform is used, readiness probes should be bound to actual serving capability so that instances which have not finished loading do not receive traffic early.

    6. Observability and Capacity Evaluation

    Without measurement there is no capacity planning. At minimum, four categories of metrics should be collected: throughput (output tokens per second), latency distribution (percentiles for time-to-first-token and overall latency), queueing metrics (wait time and queue depth), and resource metrics (GPU memory usage and utilization). Logs should retain the request identifier, input and output lengths, and cache hit status; traces should connect the whole path from access to execution so it is clear which layer is slow.

    Capacity evaluation should use replay load testing that stays close to reality: construct traffic from a desensitized real length distribution, increase load step by step to find the latency inflection point, and set watermarks and scale-out thresholds accordingly. Observability data is also the basis for cost attribution, which can be split by caller, scenario, and model version to identify heavy consumers and target optimization.

    7. Implementation Checklist

    • Build a length-distribution profile first, then discuss capacity and batching parameters.
    • The access layer and scheduling layer must be able to rate limit and reject fast independently.
    • Cache keys include version information, and any change invalidates them.
    • Scaling signals are primarily queueing duration and GPU memory watermarks.
    • Use real traffic replay to determine the latency inflection point and watermarks.
    • Have observability, logging, and tracing in place before taking large traffic.

    On top of the general cloud infrastructure offered by Baidu AI Cloud, the layering and scheduling methods above map directly onto combinations of general capabilities such as object storage, message queues, container platforms, log services, and monitoring and alerting. What an engineering team really needs to accumulate is not the calling convention of a specific product, but an understanding of traffic characteristics, command of batching and caching mechanisms, and a capacity governance process that can be measured continuously.