LLM API Concurrency Limits and Resource Isolation: A Practical Guide

    This article explains how to set concurrency limits for large language model APIs and isolate resources across traffic types. It covers why in-flight requests are a better throttling metric than QPS, how to build a layered quota model across entry, account, tenant, and single-request levels, how to derive per-model quotas from memory and KV Cache estimates, why developer API traffic must be separated from consumer-facing traffic, how to handle requests that exceed the limit through fast failure, backoff retries, bounded queues, model fallback, and priority preemption, and how to close the loop with observability and capacity reviews. It also lists common pitfalls to avoid.

    1. Background: Why Concurrency Limits Are the First Gate on the API Side

    Resource consumption in large model inference differs fundamentally from that of traditional web APIs. During the decoding phase, a single request continuously occupies GPU memory and compute slots. The lifetime of one request ranges from a few hundred milliseconds to tens of seconds, and its length is unpredictable. As a result, metrics such as “requests per second” cannot accurately describe the real load. In engineering practice, in-flight requests are more commonly used as the throttling dimension, which is what is usually called the account-level concurrency limit.

    There are three direct reasons for setting a concurrency limit:

    1. Fairness: Prevent a single account from crowding out shared resources with burst traffic and causing long-tail latency for other accounts.
    2. Predictability: Turn unpredictable traffic into a bounded queue length so that capacity planning becomes calculable.
    3. Cost control: Inference resources are expensive, and a hard limit avoids unexpected bills and resource abuse.

    2. A Layered Quota Model: Account-Level Concurrency Is Just One Layer

    A mature throttling system is usually multi-layered, narrowing down from top to bottom:

    • Entry layer: Apply coarse-grained traffic shaping by source and block abnormal bursts.
    • Account layer: Set separate concurrency limits for different models. For example, a lightweight model can be given a higher quota (such as 2,500 in-flight requests), while a more capable heavy model is tightened to a lower quota (such as 500), matching the resource cost per request.
    • Tenant/project layer: Subdivide the quota by business line below the account level so that a single internal experiment cannot exhaust the entire quota.
    • Single-request layer: Cap the maximum input length and maximum generation length to prevent overly long contexts from inflating memory usage.

    The key principle of layering is: upper layers do coarse filtering, lower layers do precise allocation. Pressing all the logic into a single layer results in either rigid rules or rules that are hard to debug.

    3. The Basis for Differentiated Quotas per Model

    Resource usage differences across model sizes are often several times or even an order of magnitude apart, so a uniform quota is neither fair nor economical. Differentiated quotas should be derived from measurable metrics rather than guesswork:

    1. Safe concurrency per model ≈ (available GPU memory - weight footprint - activation reserve) / estimated KV Cache per sequence
    2. Safe concurrency = theoretical concurrency × safety factor (0.6~0.8)

    KV Cache grows linearly with context length and is the part most easily underestimated in long-context scenarios. It is recommended to measure separately at P50/P95 input lengths, use P95 as the quota baseline, and treat P50 as room for elastic scaling.

    4. Resource Pool Isolation: The API Side and the Consumer Side Must Be Separate

    Putting developer-facing API traffic and end-user interaction traffic in the same resource pool is a common pattern behind stability incidents. The reason is that their traffic profiles are complete opposites:

    Dimension Consumer interaction traffic API call traffic
    Peak/valley pattern Strong periodicity, clear morning and evening peaks Triggered by programs, steep spikes
    Latency tolerance Seconds are unacceptable Several seconds to tens of seconds acceptable
    Failure handling Users churn directly Retries and degradation are possible
    Context length Short, concentrated distribution Long, heavy tail

    Isolation measures range from shallow to deep: separate resource pools and separate quotas, a separate gateway and authentication path, separate rate-limiting counter storage, and, when necessary, separate availability zones. The benefit of isolation is containing the failure domain—when a batch job runs out of control, it will not drag consumer-side availability down with it.

    5. Handling Requests Over the Limit: Rejection Is Not the Only Option

    When concurrency hits the ceiling, returning an error directly is only the most basic strategy. A more complete handling chain looks like this:

    1. Fast failure: Return a clear rate-limiting status code and a retry hint, along with a suggested backoff duration.
    2. Client-side backoff retry: Use exponential backoff with jitter to avoid a retry storm.
    1. import random, time
    2. def call_with_backoff(fn, max_retry=5, base=0.5):
    3. for i in range(max_retry):
    4. try:
    5. return fn()
    6. except RateLimited:
    7. if i == max_retry - 1:
    8. raise
    9. sleep = base * (2 ** i) + random.uniform(0, 0.3)
    10. time.sleep(sleep)
    1. Queue buffering: For offline tasks that can tolerate latency, move them into a bounded queue for asynchronous consumption. The queue must have an upper limit and be configured to drop items on timeout.
    2. Model fallback: During peak periods, route requests to a lighter model tier, trading quality for availability.
    3. Priority preemption: Reserve quota for online interactive workloads, and let batch jobs use preemptible quota.

    6. Observability and the Capacity Governance Loop

    Without data support, a quota policy quickly drifts away from actual load. At a minimum, collect: the in-flight concurrency distribution, queueing time, rate-limit trigger rate, time to first token, token consumption per request, and quota utilization per account. Build a weekly review process on top of these metrics: if quota utilization stays below the threshold for a long time, lower it to free up resources; if it keeps hitting the ceiling and the business demand is legitimate, raise it according to the calculations.

    The governance loop can be summarized as: collect → baseline calculation → quota rollout → observation and validation → iterative adjustment. Missing any of these steps degrades the limit into a static configuration.

    7. Common Pitfalls

    • Using QPS instead of in-flight concurrency as the throttling metric, which severely underestimates pressure in long-request scenarios.
    • Limiting concurrency but not context length, so memory can still be exhausted.
    • A retry strategy without jitter, which creates a secondary spike the moment recovery happens.
    • Isolation that stops at the quota level while the underlying resource pool is shared, so failures still propagate.
    • Quotas that are never revisited and drift away from the actual business shape.

    In summary, concurrency limits and resource isolation are not a simple matter of number configuration, but a systems engineering effort spanning capacity estimation, layered quotas, failure domain partitioning, degradation plans, and an observability loop. Looking at the general practices of cloud platforms such as Baidu AI Cloud, throttling on the right dimension and isolating at the right boundary is the core of stable large model API supply.