Engineering Quotas and Stability for LLM Inference Under Compute Constraints

    This article examines how to design reliable applications when upstream large language model (LLM) services face compute shortages, tight quotas, and availability fluctuations. It translates compute pressure into measurable capacity metrics, outlines layered quota governance for session lifecycles, single-request input length, and daily limits, and presents stability practices such as error budgets, backoff retries, graceful degradation, tenant isolation, and observability. It also covers client-side integration patterns and general cloud capabilities for building a buffer against upstream limits.

    1. The Core Problem: When Inference Demand Exceeds Available Compute

    A recent incident at a large model platform illustrates the issue. Due to compute constraints, the platform imposed limits on long conversations across its web and mobile clients: inactive historical sessions are no longer retained after a certain period, single input length was compressed to around 40,000 characters, and once the daily conversation quota is reached, requests return a “server busy” message. Over the same period, the platform’s service status records showed multiple outages within a single month, affecting the chat service and two types of model APIs. The quarterly API availability was about 99.46%, which translates to tens of hours of downtime per year.

    Stripping away the specific product, three typical engineering signals emerge:

    • Resource saturation: Inference is a compute-intensive workload. Peak concurrency and long contexts quickly amplify GPU memory and operator usage. When supply elasticity is insufficient, the only option is to throttle requests to stay alive.
    • Policy tightening: Limiting inactive long sessions, shortening single inputs, and setting daily quotas are essentially ways to reclaim scarce resources from “low-value consumption”—a classic quota governance approach.
    • Availability fluctuation: 99.46% availability means the error budget is consumed quickly, so degradation and retry mechanisms are required as a safety net.

    For developers, the real problem is not that “a platform imposed limits,” but: how do you design your own system when downstream AI capabilities are unreliable, limited, and jittery?

    2. Capacity Perspective: Translating “Compute” into Measurable Metrics

    The first step in capacity planning is to reject vague statements and convert compute into observable, predictable metrics. At minimum, establish the following mapping:

    Business Metric Approximate Resource Usage Notes
    Input tokens Prefill compute Roughly linear with sequence length
    Output tokens Decode steps Each step reads weights, putting pressure on GPU memory bandwidth
    Concurrent sessions KV cache usage Related to the product of context length and concurrency
    Peak QPS Queueing latency Latency rises nonlinearly once service rate is exceeded

    A practical capacity estimation example (illustrating the method only, not any specific product parameters):

    1. # Estimate the resource profile from "daily request volume + average input/output length"
    2. daily_requests = 100_000
    3. avg_in, avg_out = 3_000, 800 # unit: tokens
    4. peak_ratio = 0.15 # share of peak hour in the whole day
    5. tokens_in_day = daily_requests * avg_in
    6. tokens_out_day = daily_requests * avg_out
    7. tokens_peak_h = (tokens_in_day + tokens_out_day) * peak_ratio
    8. print(f"Daily token volume: {tokens_in_day + tokens_out_day:.2e}")
    9. print(f"Peak-hour token volume: {tokens_peak_h:.2e}")

    Key takeaway: long context is a cost amplifier, output length is a latency amplifier, and concurrency is a GPU memory amplifier. The typical governance order is to reduce input first, control output next, and schedule concurrency last.

    3. Quota Governance: Layered Design Instead of One-Size-Fits-All

    The three types of limits above correspond to three reusable governance primitives:

    1. Session lifecycle governance: No longer retaining long context for long-inactive sessions is equivalent to moving “historical state” from hot storage to cold storage or discarding it, keeping only a summary. In engineering terms, use a sliding window plus summary compression:
    1. Retention policy = verbatim recent N turns + structured summary of earlier content
    2. Trigger condition = session idle time > T or cumulative tokens > L
    1. Single-input governance: Limiting single input length prevents a single request from overwhelming the prefill stage. A recommended three-step approach at the gateway layer is “pre-check + truncate + notify”: first estimate tokens, then truncate proportionally while preserving key head and tail segments, and finally clearly inform the user where truncation occurred.

    2. Daily quota governance: Set token buckets per user/tenant/API dimension to smooth out burst traffic:

    1. class TokenBucket:
    2. def __init__(self, rate_per_day, capacity):
    3. self.rate = rate_per_day / 86400
    4. self.capacity = capacity
    5. self.tokens = capacity
    6. self.ts = time.time()
    7. def allow(self, need=1):
    8. now = time.time()
    9. self.tokens = min(self.capacity,
    10. self.tokens + (now - self.ts) * self.rate)
    11. self.ts = now
    12. if self.tokens >= need:
    13. self.tokens -= need
    14. return True
    15. return False

    The key to quota design is not “how much to limit,” but being explainable, predictable, and appealable: error messages should state the remaining quota and reset time, avoiding packaging a resource problem as an unactionable “service busy” message.

    4. Stability Engineering: Holding the Line at 99.46% Availability

    With 99.46% quarterly availability, the error budget is very limited, so engineering must turn “unavailable” into “degraded but available.”

    • Error budget and release discipline: First define SLOs (such as success rate and P95 latency), then compute the error budget; when the budget is consumed too fast, automatically freeze changes.
    • Retry and backoff: Retry only idempotent requests, using exponential backoff with jitter to avoid retry storms:
    1. def call_with_backoff(fn, max_retry=3):
    2. for i in range(max_retry):
    3. try:
    4. return fn()
    5. except TransientError:
    6. sleep = min(2 ** i + random.random(), 8)
    7. time.sleep(sleep)
    8. raise ServiceUnavailable()
    • Degradation path: When the primary model is unavailable, degrade in order to a smaller-parameter model, cached results, and rule-based templates, prioritizing “having a response” over “the optimal response.”
    • Multi-active and isolation: Use per-tenant resource isolation and bulkhead design to prevent a single large customer from dragging down the whole system; deploy across availability zones to reduce single-point-of-failure impact.
    • Observability loop: Monitoring and alerting should cover queueing latency, truncation rate, quota trigger rate, and degradation hit rate—not just error codes.

    5. Integration Patterns for Developers

    Given upstream constraints, the business side should model “AI capability” as an unstable dependency:

    1. Asynchronous: Convert long tasks to submit-poll or callback patterns to avoid holding long connections.
    2. Idempotency keys: Assign an idempotency key to each generation so retries do not double-bill or produce duplicate side effects.
    3. Result caching: Apply semantic caching to high-frequency similar requests; a cache hit returns immediately and directly cuts compute consumption.
    4. Streaming output: Return tokens as they are generated to improve perceived latency and enable mid-stream cancellation.
    5. Cost dashboard: Turn token consumption, quota triggers, and degradation ratios into business-visible metrics so the product side can participate in governance.

    6. Adding Elasticity on the Cloud: A General Capability Mix

    If you need to build or harden an inference service, use a general industry-standard cloud capability mix rather than any proprietary interface: a container platform to host elastically scaled inference replicas; object storage for models and cold data; a message queue for peak shaving and decoupling long tasks; log services and monitoring/alerting as the observability foundation; and key and configuration management to ensure safe canary releases and rollbacks. Baidu AI Cloud offers corresponding capabilities in these general categories, which can be combined along the lines of “elastic compute + asynchronous queue + full-link observability” to form a buffer layer against upstream limits and jitter.

    7. Conclusion

    Quotas and availability fluctuations are not anomalies but inevitable outcomes when compute supply and demand are out of balance. What sets mature teams apart is that they turn scarce resources into measurable metrics, turn limits into explainable policies, and turn unavailability into degradation paths. With these three in place, even when upstream “compute is insufficient,” the business can remain continuous, predictable, and operable.