LLM Service Quotas and KV Cache Management: A Practical Guide
This article examines why large language model (LLM) chat services enforce usage quotas under GPU memory pressure, focusing on the KV cache as the core bottleneck. It explains how KV cache memory grows linearly with context length and accumulates across idle sessions, then presents four engineering strategies: session lifecycle and input governance, quota and priority-based admission control, lowering per-context memory cost, and stability with observability. It also outlines how to assemble these capabilities on a cloud platform, offering a practical reference for maintaining user experience and availability with limited compute.
1. The Symptom: Service Quotas Under Compute Pressure
A major LLM chat service recently introduced usage limits for regular users. Three changes are visible on the user side:
- “Zombie sessions” with no interaction for a certain number of days can no longer be resumed.
- The maximum input length per request has been reduced to roughly 40,000 characters.
- Daily conversation counts or credits now have an upper bound; once reached, users see a “server busy, quota limit reached” message.
Over the same period of several months, the service recorded eight incidents on its official status page, with varying severity. Most were performance degradations: higher time-to-first-token (TTFT), lower generation throughput, and occasional request failures, though requests still had a chance of succeeding. A few were partial outages; individual events lasted more than four hours, affecting the web app, mobile app, and two different model API tiers simultaneously, with credits later issued to API callers as compensation. By availability metrics, from August to October the lightweight API was about 99.46% available and the standard API about 99.74%. Normalized to a 8,760-hour year, that corresponds to roughly 47.3 hours of annual downtime for the former and 22.8 hours for the latter.
These numbers are a reminder: the bottleneck in chat services is often not “can the model answer,” but “is there enough GPU memory to hold the context.”
2. Root Cause: Why the KV Cache Is a Scarce Resource
Autoregressive generation re-reads the Key/Value tensors of all historical tokens every time it produces a new token. To avoid recomputation, these tensors are cached in GPU memory as the KV cache. This has two direct consequences.
First, memory usage grows linearly with context length. Let L be the number of layers, H the number of attention heads, D the dimension per head, S the context length, B the batch concurrency, and p the bytes per element at a given precision. Roughly:
KV_bytes ≈ 2 × B × S × L × H × D × p
The factor of 2 accounts for the two copies, Key and Value. Using a simple configuration for mental math (L=32, H=32, D=128, p=2), a single token per sequence takes about 0.5MB. A 40,000-character input (estimated at 1.5 characters/token, roughly 27,000 tokens) approaches 13GB at a concurrency of one, before counting weights, activations, and fragmentation.
Second, long sessions keep accumulating cache. Multi-turn conversations retain all prior turns, and idle sessions do not automatically release GPU memory. Sessions that “hold memory without using it” crowd out the batching space for active requests, directly reducing effective concurrency and throughput.
This clarifies the nature of quota measures: they are not simply throttling to push users away, but a reclamation of resources and a reordering of scheduling priorities—taking memory back from low-value holders and giving it to requests that are actively interacting.
3. Engineering Countermeasure 1: Session Lifecycle and Input Governance
Turning “never released when idle” into “reclaimable by tier” is the fastest win.
- Idle reclamation: set an idle TTL for sessions. On timeout, keep only the summary and metadata, and release the KV cache immediately; when a user resumes, rebuild the context from the summary.
- Tiered caching: the hot tier holds KV for active sessions, the warm tier holds recently used sessions (swappable to host memory or local storage), and the cold tier stores only persisted summaries.
- Input budget: cap single-request input length and pre-validate at the gateway, so oversized requests fail before entering the inference queue rather than wasting queue time and compute.
Example logic:
def admit(session, text):if session.idle_seconds > SESSION_TTL:session.kv = None # release GPU memorysession.ctx = load_summary(session) # rebuild from summarytokens = estimate_tokens(text) # a rough estimate is enoughif tokens > MAX_INPUT_TOKENS:return reject("input too long")return enqueue(session, text, tokens)
4. Engineering Countermeasure 2: Quotas, Priority, and Admission
Quotas should not be arbitrary numbers; they should align with the memory budget.
- Daily quota: convert to a “token budget per user,” and on exhaustion return a clear error code (such as
quota_exceeded) with the reset time. - Priority queue: interactive requests take precedence over batch jobs; high-priority requests can preempt batch slots held by lower-priority ones.
- Admission control: use “the number of concurrent sequences that remaining memory can hold” as the signal, applying backpressure instead of unlimited queuing.
capacity = (free_vram - reserve) / per_seq_kvif inflight + 1 > capacity: apply_backpressure()
5. Engineering Countermeasure 3: Lowering the Cost per Unit of Context
- Paged KV management: split contiguous GPU memory into fixed blocks allocated on demand, significantly reducing fragmentation and increasing the number of sequences that fit.
- Prefix reuse: common prefixes such as system prompts and tool descriptions have their KV computed once and shared across requests.
- Quantization and sparsity: apply low-bit quantization to the KV cache, or sparsify/evict historical tokens, trading controllable precision for memory.
- Length-aware scheduling: batch requests with similar lengths first to reduce padding waste.
6. Engineering Countermeasure 4: Stability and Observability
99.5% availability means tens of hours of downtime per year, so “degradation” must be made an expected capability.
- Metrics: TTFT P95/P99, output token rate per user, queue time, GPU memory usage, swap-out hit rate, and failure rate.
- Alerts: set dual thresholds for latency and failure rate; on trigger, automatically shed load (shorten max context, lower the concurrency cap).
- Degradation path: during peak hours, disable non-core add-on capabilities (such as web-retrieval tools) to preserve basic chat.
- Capacity redundancy: reserve GPU memory and instance headroom for sudden spikes, preventing a single point of failure from spreading into a partial outage.
alerts:- name: high_ttftexpr: p95(ttft_seconds) > 3action: reduce_max_context()- name: vram_pressureexpr: vram_used_ratio > 0.9action: evict_cold_sessions()
7. Cloud Implementation: Assembling with General-Purpose Capabilities
On cloud platforms such as Baidu AI Cloud, the above can be implemented by combining general product categories: a container platform hosts inference instances and elastic scaling; object storage holds session summaries and cold data; a message queue buffers requests and smooths peaks; a logging service collects call traces; and monitoring alerts link to load-shedding policies. The key is to treat “GPU memory” as a first-class resource in scheduling and billing.
8. Conclusion
Quotas and incidents are not isolated events; they result from the combined effect of context cost, memory supply, and scheduling policy. Only by closing the loop across session lifecycle, input budget, quota priority, paged caching, and observable degradation can you preserve both experience and availability under limited compute.
