LLM Inference Capacity Planning and Rate Limiting: A Practical Guide

    This article explains why rapid growth in LLM API traffic leads to service disruptions, and how to treat it as a resource structure problem rather than a simple traffic spike. It covers the three-part cost structure of inference (prefill, decode, and state residency), a Token-based capacity model, layered rate limiting and multi-dimensional quotas, context lifecycle management, observability and capacity alerts, and a cost optimization checklist for developers. Readers will learn how to turn Token consumption into a measurable, compressible, and degradable budget.

    1. The Real Problem: Resource Structure Imbalance, Not Just Traffic

    One platform saw call volume climb sharply within a single month, with weekly usage jumping from single-digit trillions of Tokens to more than 30 trillion, alongside several service outages. In response, it introduced policies such as idle timeouts for long conversations, reduced single-input length limits, and daily call quotas.

    Viewed together, these moves are not isolated product decisions. They are projections of the same resource constraints at different layers.

    It is worth stressing that such adjustments usually signal a shift into a more refined stage of capacity governance, not a regression in capability. Understanding the underlying mechanics matters more than memorizing specific numbers.

    1.1 Inference Cost Structure Differs from Traditional Web Services

    Traditional services have a relatively constant per-request cost, so scaling can be estimated linearly by QPS. LLM inference cost has three components:

    • Prefill: consumes a large amount of compute in one pass, roughly linear in input length;
    • Decode: generates Token by Token, constrained by concurrent batch size and memory bandwidth;
    • State residency: conversation context occupies GPU memory continuously, proportional to “number of sessions × average context length.”

    This means the truly scarce resource is often not total compute, but GPU memory and concurrency slots. A long-context session with a million-scale Token count can have a residency cost equivalent to thousands of short requests.

    1.2 Why 8x Growth Breaks the System

    Queueing theory offers the intuition: as utilization approaches 1, waiting time diverges non-linearly. If the original design watermark was 40%–50%, an 8x traffic increase pushes the system into overload, showing up as timeouts, retries, and cascading failures. Retry amplification can further multiply effective load several times over, creating a positive feedback loop.

    2. Capacity Modeling: Turning Tokens into an Accountable Resource Unit

    Governance starts with measurement. Use Tokens as a unified ledger with three layers of metrics:

    1. Entry layer: request count, input Tokens, output Tokens, session activity
    2. Engine layer: batch size, queue time, KV cache occupancy, GPU memory watermark
    3. Business layer: per-tenant quota consumption, timeout rate, retry rate, cost per request

    A practical capacity estimation skeleton is below (illustrative, not product-specific parameters):

    1. # Derive the daily capacity ceiling from the total concurrent context GPU memory can hold
    2. def capacity(gpu_memory, weights_mem, per_token_kv, avg_ctx, reserve_ratio=0.2):
    3. usable = gpu_memory * (1 - reserve_ratio) - weights_mem
    4. concurrent = usable // (per_token_kv * avg_ctx)
    5. return concurrent # multiply by average daily service rounds to get the Token ceiling

    The key conclusion: daily capacity ceiling ≈ concurrent context slots × average daily rounds × average context length. Among the three factors, average context length is the variable most easily amplified by user behavior and most easily suppressed by governance measures.

    3. Admission Control and Rate Limiting: From One-Size-Fits-All to Tiered Quotas

    3.1 Three Rate Limiting Layers

    • Edge layer: token buckets by identity dimension to absorb bursts;
    • Gateway layer: quotas and priority queues by tenant/API dimension;
    • Engine layer: request queue limits and fast failure to avoid unbounded waiting.

    3.2 Quota Design Principles

    Single-dimension quotas (such as request count alone) fail. Multi-dimensional combinations are required: request count, input Tokens, output Tokens, and concurrent sessions. Set an independent, stricter quota pool for long contexts so short requests are not crowded out by long ones.

    1. quota:
    2. free_tier: { rpm: 60, daily_tokens: 200k, max_input_chars: 40k }
    3. standard: { rpm: 600, daily_tokens: 5m, max_input_chars: 200k }
    4. priority: { rpm: 3000, daily_tokens: null, max_input_chars: 1m }

    3.3 Overload Protection

    Use adaptive rate limiting (negative feedback based on queue time and rejection rate), together with circuit breaking and degradation: prioritize high-priority tenants, and return a retryable response to low-priority requests instead of leaving them hanging. Fast failure protects overall availability better than slow success.

    4. Context Lifecycle Governance

    Recycling inactive sessions is essentially changing “permanent residency” into “load in and out on demand.” In engineering terms, this can be split into three tiers:

    1. In-memory residency: active sessions, lowest latency;
    2. Serialized offload: write context to object storage or cache, releasing GPU memory for cold sessions;
    3. Summary compression: apply rolling summaries to very long histories, compressing N rounds into a fixed-length representation.
    1. class SessionState:
    2. def touch(self): self.last_active = now()
    3. def evictable(self, ttl_days=7): return now() - self.last_active > ttl_days

    Input length limits serve the same purpose: they set a hard boundary on GPU memory usage, turning capacity planning from “unpredictable” into “bounded from above.” For developers, the response is retrieval augmentation and segmented summarization, sending only truly relevant fragments into the context rather than concatenating everything.

    5. Observability and Capacity Alerts

    No measurement, no governance. At minimum, you need: Token throughput and distribution histograms, queue time P95/P99, KV cache hit rate, rejection and retry rates, and per-tenant cost attribution. Alerts should use dual thresholds based on trend and watermark, triggering scale-out early at 60%–70% utilization rather than waiting for rejection rates to spike.

    6. Developer-Side Cost Optimization Checklist

    • Trim prompts, removing redundant examples and repeated instructions;
    • Use retrieval instead of full injection to control single-input size;
    • Apply semantic caching to reusable results to reduce repeated computation;
    • Use streaming output plus client-side timeouts and exponential backoff to suppress retry storms;
    • Explicitly release sessions when they end to avoid long-term quota occupation;
    • Build local Token metering and bring cost into CI and budget alerts.

    7. Conclusion

    The “happy problem” of surging call volume ultimately turns into an engineering standard around quotas, context, and observability. For consumers, the real moat is not unlimited quota, but designing applications that treat Tokens as a finite budget: measurable, compressible, and degradable. If you already use Baidu AI Cloud’s inference and governance capabilities, consider linking quota policies, monitoring alerts, and logging services into a closed loop so capacity expansion keeps pace with business growth.