Rate Limiting and Scheduling for LLM Chat Services Under Compute Pressure

    LLM chat services often hit compute ceilings faster than expected. This article explains how to reason about capacity, where inference bottlenecks actually sit, and how to apply rate limiting, admission control, and scheduling so that limited GPU resources serve more users without collapsing the experience. It covers the prefill/decode split, KV Cache memory accounting, tiered session strategies, an illustrative admission controller, throughput techniques, and a shift toward proactive capacity planning.

    1. Working Backward from “Pausing New Sign-Ups” to Capacity Limits

    The peak concurrency ceiling of any public-facing LLM chat service can be approximated with a rough capacity equation:

    1. Peak sustainable concurrency ≈ available decode resources / (average per-user resource usage × safety margin factor)

    Here, average per-user resource usage is not simply “the GPU memory of a single request.” It is an expected value shaped jointly by context length, the output-length cap, request arrival rate, and session duration. This also explains why “pausing new user sign-ups” is often the fastest and most direct capacity-conservation move for operators. The load curve of existing users is statistically stable, so resources can be reserved against historical baselines. New users, by contrast, are marginal additions, and while they are still exploring they tend to send longer contexts, trigger more retries, and show higher sensitivity to first-token latency. Their resource-demand variance is far larger than their mean. Within a window where compute supply cannot scale elastically in the short term, closing the incremental entry point costs less than degrading the experience for everyone already inside.

    2. The Two-Phase Structure of Inference: Where the Bottleneck Really Is

    Autoregressive decoding involves two phases with completely different characteristics over the lifecycle of a single request.

    • Prefill: processes the entire input in parallel in one pass. It has a high compute-to-memory-access ratio and is compute-bound. The attention portion grows quadratically with input length, and this phase directly determines time-to-first-token (TTFT).
    • Decode: generates tokens autoregressively, one at a time. Every step must read the full set of model weights and the request’s entire accumulated KV Cache. The compute per step is small, but the memory traffic is large, making this phase memory-bandwidth-bound.

    This leads to a conclusion that is easy to overlook: during decoding, the GPU’s nominal compute utilization is usually far below its peak. The real constraints are memory capacity and memory bandwidth. As a result, “how many GPUs to buy” does not translate directly into “how many users I can serve.” The concurrency ceiling is typically set by memory, and by how far you can split that memory across concurrent requests while still holding TPOT (time per output token) at an acceptable level.

    3. KV Cache: The Memory Bill You Have to Do the Math On

    Using a standard Transformer as an example, the GPU memory for a single request’s KV Cache can be estimated as:

    1. bytes = 2 × layers × kv_heads × head_dim × seq_len × batch × dtype_bytes

    Illustrative implementation:

    1. def kv_cache_bytes(layers, kv_heads, head_dim, seq_len, batch=1, dtype_bytes=2):
    2. # The factor of 2 accounts for the two caches (K and V); with GQA/MQA, kv_heads is smaller than the number of attention heads
    3. per_token = 2 * layers * kv_heads * head_dim * dtype_bytes
    4. return per_token * seq_len * batch
    5. for ctx in (4_096, 16_384, 32_768):
    6. print(ctx, round(kv_cache_bytes(32, 8, 128, ctx) / 1024**3, 2), "GiB / request")

    These numbers yield three direct takeaways. Memory usage grows linearly with both concurrency and context length. Long contexts are concurrency killers: a single 32K context can consume as much memory as a dozen short sessions. And because weight loading and memory reservation are fixed costs, only the remaining memory can be converted into concurrency capacity.

    4. Why Chat Workloads Can “Sacrifice” KV Cache

    Traditional database-style services cannot throw away context, but conversational workloads have one key statistical property: a low session reuse rate. Many requests are one-off, single-turn questions, and even when users do ask follow-ups, the chance of the same session being woken repeatedly within a short window is limited. This leaves room for non-sticky session management. Common approaches fall into three tiers:

    Strategy Approach Applicable scenario
    Strong guarantee Keep the session resident in memory for its duration; no swap-out High-priority tiers, low-latency SLAs
    Tiered swap-out Swap cold sessions to fast storage based on idle-time watermarks General tiers; balances cost and experience
    On-demand recompute Discard the KV Cache outright; re-prefill on resume, or rebuild context with a summary Peak rate-limiting periods; long sessions with low reuse

    It is worth stressing that these three tiers are not “best” versus “worse.” They are an explicit trade-off between latency and cost. Recompute turns what should be a roughly 100-millisecond resume into a full prefill that reprocesses thousands of tokens. The cost is quantifiable, and what you get back is roughly doubled concurrency. As long as this trade-off is written into the product’s expectations, for example by showing a “restoring context” state when a conversation resumes, it is a controllable engineering decision rather than an incident.

    5. Admission Control: Making Capacity Conservation as Transparent as Possible

    When capacity runs short, the worst thing you can do is time users out indiscriminately. A usable admission-control layer should include at least a total concurrency quota, per-user concurrency and rate limits, priority-based pooling, and explainable rejection reasons.

    1. class AdmissionController:
    2. """Illustrative admission control: capacity conservation + priority preemption + explainable rejection"""
    3. def __init__(self, capacity, per_user_cap, reserve_ratio=0.15):
    4. self.capacity = int(capacity * (1 - reserve_ratio)) # Reserve a buffer to absorb bursts
    5. self.per_user_cap = per_user_cap
    6. self.running = 0
    7. self.per_user = {}
    8. def try_admit(self, user_id, est_prompt_tokens, max_tokens, tier="standard"):
    9. # Charge long requests by estimated output length so a single request cannot hold a slot for too long
    10. cost = 1 + max_tokens // 1024 + est_prompt_tokens // 4096
    11. if self.per_user.get(user_id, 0) + cost > self.per_user_cap:
    12. return {"admit": False, "reason": "PER_USER_QUOTA"}
    13. if self.running + cost > self.capacity:
    14. if tier != "premium":
    15. return {"admit": False, "reason": "QUEUE_FULL", "eta_ms": self._estimate_wait()}
    16. self.running += cost
    17. self.per_user[user_id] = self.per_user.get(user_id, 0) + cost
    18. return {"admit": True, "cost": cost}
    19. def _estimate_wait(self):
    20. return None # A real implementation can estimate this from historical token rate and queue length

    On top of this, it helps to pre-define a graceful degradation ladder that protects availability before scaling takes effect: shorten the max_tokens cap → limit context length per request → route to a smaller backup model → disable non-core re-reasoning and web-retrieval features → queue low-priority traffic with an estimated wait time. Degradation must support gradual rollout and rollback, take effect per tenant, and be recorded in post-incident reviews.

    6. Squeezing More Effective Throughput from Limited Compute

    Raising “effective compute” (goodput) usually pays off faster than additional procurement:

    1. Iteration-level continuous batching: admit newly prefilled requests dynamically at each decode step so memory and compute stay saturated, instead of idling each batch while waiting for the slowest request.
    2. Paged KV memory management: organize the cache into fixed-size blocks to eliminate the reservation waste caused by fragmentation, lifting both memory utilization and sustainable concurrency together.
    3. Prefix cache reuse: system prompts, tool definitions, and long documents are often shared across sessions. A prefix cache hit skips redundant prefill and cuts TTFT significantly.
    4. KV Cache quantization: store K/V in a lower-precision format, trading an acceptable quality loss for a multiple reduction in memory use. This is usually easier to pass quality review than lowering generation precision.
    5. Prefill/decode disaggregation: the two workloads have opposite resource profiles. Splitting them lets each scale and tune independently against its own bottleneck, avoiding the long-tail latency that interference causes.
    6. Speculative decoding: use a lightweight draft model or parallel drafts to propose several candidate tokens that the main model then verifies in a single pass, raising token throughput in the bandwidth-bound decode phase.
    7. Context governance: prefill long inputs in chunks, summarize historical dialogue, and use retrieval augmentation for retrievable information instead of stuffing everything into the context.

    Cloud platforms generally already offer common building blocks such as elastic container platforms, object storage, message queues, log services, and monitoring/alerting; platforms such as Baidu AI Cloud offer similar infrastructure as well. The engineering focus is not whether you own these components, but whether you can chain “fast loading of weights and model files,” “persistent swap-out of cold sessions,” and “centralized collection of metrics and logs” into a capacity pipeline that can be triggered automatically.

    7. From Reactive Firefighting to Proactive Capacity Planning

    • Capacity baseline: anchor on the historical P95 of peak concurrency, then add a safety factor and a burst buffer, rather than planning against the daily average.
    • Metric selection: GPU utilization alone can misjudge health. Observe goodput, P95/P99 TTFT, TPOT, queue time, swap-out hit rate, and recompute trigger rate together.
    • Cold-start governance: model loading and memory warm-up take minutes. Auto-scaling must rely on warm pools and pre-pulled model artifacts, or the scaling curve will always lag the traffic curve.
    • Validation loop: before launch, calibrate per-instance sustainable concurrency with shadow traffic and stepped load tests, and use chaos drills to verify that admission control, the degradation ladder, and rate-limit recovery behave correctly.
    • External communication: much of the user-experience damage in a capacity incident comes from “not knowing how long the wait will be.” Returning an explainable queue position and an estimated wait preserves retention better than a bare 429.