High Availability Architecture for LLM Services Under Rate Limits
This article examines why LLM services impose quotas, session expiration, and input truncation, and how engineering teams can design around these constraints. It covers externalizing conversation state, tiered request budgets, caching, fallback strategies, and retry handling, with practical Python and YAML examples for building reliable applications on limited-capacity model APIs.
1. The Technical Logic Behind the Limits
A major LLM service recently rolled out usage limits for its consumer-facing client and web app. Three behaviors stand out: once the daily call quota is exhausted, users see a “server busy” message; long sessions with no interaction for a certain number of days can no longer be resumed; and the maximum input length for a single request was reduced to roughly 40,000 characters. The service’s status page also showed multiple outages and incidents over the past month or so.
From an engineering perspective, these behaviors are not isolated product decisions. They are the inevitable result of insufficient elasticity in compute supply. GPU memory usage in LLM inference scales roughly linearly with the number of concurrent sessions. Long contexts keep occupying the key-value cache, and idle sessions that are never reclaimed cause memory fragmentation and scheduling starvation. Overly long inputs directly increase time-to-first-token and queueing time. Quotas, session reclamation, and input truncation are therefore the same resource-governance mechanism projected across different dimensions.
The key takeaway for developers is simple: do not build availability assumptions on “unlimited quota and permanently valid context.” Architecture must treat quotas, session lifecycles, and input budgets as first-class concerns.
2. Externalizing Session State
Since long-idle sessions may be reclaimed by the platform, the application should hold session state itself rather than relying on implicit server-side retention.
# Example: externalized session state with summary compressiondef build_context(session_id, user_input, store, summarizer):sess = store.get(session_id) or {"summary": "", "recent": []}sess["recent"].append(user_input)if token_count(sess["recent"]) > BUDGET:sess["summary"] = summarizer(sess["summary"], sess["recent"][:-KEEP])sess["recent"] = sess["recent"][-KEEP:]store.save(session_id, sess, ttl=DAYS)return sess["summary"] + "\n" + "\n".join(sess["recent"])
Three points matter here. First, state lives in application-side object storage or a cache, with an expiration time aligned to business needs. Second, use a layered structure of “summary plus the most recent turns verbatim” to keep context within budget. Third, treat every request as a stateless call, so correctness does not depend on whether the server retains history.
3. Input Budgets and Request Tiering
Under quota constraints, coarse-grained calling burns through capacity quickly. A tiering mechanism helps: split traffic into online interaction, offline batch processing, and internal evaluation, each with different weights and concurrency limits.
# Example: tiered quotas and budget controltiers:online: { qps: 5, daily_ratio: 0.5, max_input_chars: 20000 }offline: { qps: 1, daily_ratio: 0.4, max_input_chars: 40000 }internal: { qps: 2, daily_ratio: 0.1, max_input_chars: 8000 }
Three supporting measures are recommended. Count characters and requests at the entry point and validate up front, routing over-budget requests straight to a fallback. For long documents, segment first and use retrieval-style recall so only relevant fragments reach the model. For offline jobs, set interruptible checkpoints so work resumes after quota recovers instead of restarting from scratch.
4. Fallback, Caching, and Fault Tolerance
The core of high availability is not never failing, but still producing a reasonable output when failure happens. Three mechanisms can be combined:
- Result caching: semantic-level cache hits for frequent, similar questions consume no quota.
- Multi-level fallback: when the primary model is unavailable, switch to a smaller model, then fall back to rules or retrieval-based answers.
- Streaming and retries: streaming output improves perceived responsiveness; retries must use exponential backoff with jitter, and retryable errors must be strictly distinguished from non-retryable quota errors.
try:return stream_call(prompt)except QuotaExceeded:return cache_or_fallback(prompt) # do not retry quota errorsexcept TransientError:sleep(backoff(attempt)); retry()
Monitoring, alerting, logging, and dashboards should also be connected, with threshold alerts on quota consumption rate, time-to-first-token, and failure rate. That way you notify teams before quota runs out, rather than waiting for users to see a popup.
5. Engineering Checklist and Selection Guidance
- Keep state and quotas observable on the application side; avoid black-box dependencies.
- Make context compression configurable, and decouple the summarizer model from the primary model.
- If the business demands high stability, use an API channel with dedicated call quotas and pay-as-you-go billing, isolated from the consumer-facing entry point so the two do not interfere with each other.
- Reserve multi-model routing in the architecture, and hide differences behind a unified model gateway. This makes it easier to build queueing, peak shaving, and persistence on top of general-purpose container platforms, message queues, and object storage such as those offered by Baidu AI Cloud.
In short, limits are not a step backward in capability; they make resource constraints explicit. Get session externalization, input budgeting, call tiering, and a closed fallback loop right, and you can maintain a stable user experience and a controllable cost curve in a quota-constrained environment.
