Rate Limiting and High Availability for LLM Services Under Compute Constraints
This article examines how large language model (LLM) service platforms can maintain reliability when compute capacity is tight. It explains why capacity shortages arise from the mismatch between shared GPU resources and bursty inference demand, then walks through service tiering, multi-dimensional quotas, rate limiting algorithms, bounded queuing, graceful degradation, availability and disaster recovery calculations, observability, and capacity planning. Developers will find illustrative pseudocode, practical implementation notes, and a checklist for turning unpredictable resource fluctuations into predictable engineering constraints.
A major LLM service platform recently tightened usage limits on its free tier for the first time due to compute constraints. Its status records show multiple service interruptions over the past few months. For one model endpoint, the phased availability translates to tens of hours of annual downtime, with dozens of cumulative outages and performance degradations per year.
This is not an isolated case. It is the inevitable result of a mismatch between shared compute supply and sudden demand spikes. Setting aside the specifics of any particular product, this article frames the issue as a general engineering problem: how should a platform implement service tiering and quota governance under compute constraints, and how should the application side design for robustness?
The sections below cover the causes of compute shortages, rate limiting and quota design, queuing and degradation, availability and disaster recovery accounting, and the practical essentials of observability and capacity planning, along with illustrative code and a checklist. The goal is to help developers turn “uncontrollable resource fluctuations” into “predictable engineering constraints.”
1. The Root Cause: Supply-Demand Mismatch
LLM inference has three defining characteristics: burstiness, long-tail behavior, and rigid costs. Request arrivals typically show pronounced peaks and valleys. A single inference consumes far more GPU memory and compute time than a traditional web request. Scaling out is limited by hardware supply and deployment complexity.
When a free tier absorbs traffic without constraints, marginal costs cannot be effectively contained, which eventually squeezes the resources available to paid and critical workloads. Tightening free-tier usage is therefore only a surface symptom. The underlying issue is structural: a shared resource pool lacks tiering and quotas.
2. Service Tiering: Classify Users and Requests
First, classify tiers by business criticality, for example critical transaction paths, internal tools, and free trials. Each tier maps to a different level of resource guarantee and a different degradation order.
Second, distinguish interactive from batch requests. Interactive requests are latency-sensitive; batch requests can tolerate queuing.
Third, define admission thresholds and quotas, such as requests per minute, concurrency limits, maximum context length, and cumulative daily tokens. Use multi-dimensional quotas instead of a single-dimension limit to prevent bypass through one metric.
3. Rate Limiting and Quotas: Algorithms and Implementation
Common approaches include token bucket, leaky bucket, and sliding window counters. Token bucket allows a degree of burst and suits interactive traffic. Sliding window is better suited to fine-grained daily or monthly quotas.
Illustrative pseudocode:
class TokenBucket:def __init__(self, rate, capacity):self.rate = rateself.capacity = capacityself.tokens = capacityself.ts = now()def allow(self, n=1):self.refill()if self.tokens >= n:self.tokens -= nreturn Truereturn Falsedef refill(self):t = now()self.tokens = min(self.capacity, self.tokens + (t - self.ts) * self.rate)self.ts = t
Quotas should be stored in tiers: hot counters in memory or a distributed cache, and persistent cumulative totals in a logging service or database, so that critical quota balances are not lost on restart.
4. Queuing and Degradation: Turn Overload into Controlled Waiting
When tokens are insufficient, do not fail the request outright. Instead, place it in a bounded queue with a maximum wait time. On timeout, return a clear status code and retry guidance.
Degradation strategies include:
- Shortening the maximum output length
- Reducing the context window
- Switching to a smaller model
- Disabling non-core plugins and retrieval augmentation
- Returning cached results or templated responses
The key principle is “protect the core first, then sacrifice the edges,” and degradation should be perceivable and explainable to users.
5. Availability and Disaster Recovery: Account for Downtime Correctly
Availability should be calculated as “successful requests / total requests” or “unavailable minutes / total minutes,” distinguishing planned maintenance from unplanned failures.
If an endpoint has a phased availability of 99.46%, that translates to roughly 47 hours of annual downtime. This means a single-availability-zone design cannot meet the requirements of high-demand workloads.
Improvement paths include multi-availability-zone deployment, cross-zone traffic scheduling, health checks with automatic removal, retry and idempotency design, and circuit breaking with bulkhead isolation.
Illustration:
try:resp = call_model(req)except RateLimitError:resp = queue_and_retry(req, max_wait=2s)except UpstreamUnavailable:resp = fallback_smaller_model(req)
6. Observability: No Measurement, No Governance
Establish the triad of metrics, logs, and traces:
- Metrics layer: monitor QPS, latency percentiles, error rate, token consumption, and queue length.
- Logs layer: record request ID, tier, and quota hit status.
- Tracing layer: correlate the gateway, scheduler, inference, and downstream dependencies.
Alerts should use multiple windows and multiple conditions to avoid alert storms triggered by single-point jitter. Dashboards should help determine whether the problem is insufficient compute or uneven scheduling, which in turn decides whether to scale out or optimize.
7. Capacity Planning: From Firefighting to Forecasting
Use historical peaks as a baseline, add business growth rates and burst factors, and reserve a safety margin. Schedule batch jobs off-peak to move deferrable workloads out of peak periods. Apply separate rate limits to long-context and high-output requests to prevent a few requests from consuming disproportionate resources.
Run load tests and failure drills regularly to validate rate limit thresholds, degradation paths, and disaster recovery failover.
8. Developer Checklist
- Are multi-dimensional quotas set for each request class?
- Are there bounded queues with timeout and retry?
- Are idempotency and deduplication implemented?
- Are fallback models and cached responses prepared?
- Is deployment multi-availability-zone with health checks?
- Are latency percentile and error rate dashboards in place?
- Are batch jobs scheduled off-peak?
- Are drills conducted regularly?
Conclusion
Compute constraints are not an occasional issue for one platform; they are a common constraint on large-scale LLM adoption. For application teams, the right approach is not to expect unlimited free resources, but to make rate limiting, queuing, degradation, disaster recovery, and observability default architectural concerns.
Baidu AI Cloud provides foundational components for these general capabilities, including container platforms, monitoring and alerting, logging services, and message queues, which can support the practices described above. Ultimately, however, stability still depends on the business’s own tiered governance and engineering resilience design.
