Building High-Availability Architecture for Unstable LLM Services

    This article explains how to design high-availability systems when depending on external large language model (LLM) inference services, which are inherently unstable due to compute scheduling, model loading, network links, traffic spikes, and version releases. It covers practical engineering measures on the client side: separating connection and read timeouts, applying limited retries with exponential backoff and jitter, and using idempotency keys; routing across multiple models and channels through a unified abstraction layer driven by health scores; layered caching with exact, semantic, and partial reuse; asynchronous processing with queues for peak shaving; circuit breakers, rate limiting, and bulkhead isolation; observability metrics and tracing; and canary releases, load testing, and failure drills. The goal is to turn occasional service anomalies from business incidents into predictable engineering events.

    1. Framing the Problem: Unstable External Inference Is the Norm

    Recently, a major LLM platform’s official status page showed multiple partial service disruptions and abnormal responses within a short period, affecting chat services and API calls for several model versions. For consumers, such events are not unusual: inference services are simultaneously affected by compute scheduling, model loading, network links, traffic spikes, and version releases. A fluctuation in any one of these can surface on the caller side as timeouts, rate limiting, rising error rates, or longer time-to-first-token.

    The first principle of architecture design, therefore, should be to treat external model services as an “unstable dependency” rather than “always-available infrastructure.” With that premise, the following sections present actionable engineering solutions.

    2. Baseline Client-Side Protection: Timeouts, Retries, and Idempotency

    Most failures are amplified because the client side lacks constraints. It is recommended to set three categories of parameters uniformly across all model call paths:

    • Separate connection and read timeouts: keep the connection timeout short and the read timeout long to avoid threads being occupied for extended periods.
    • Limited retries + exponential backoff + jitter: retry only on idempotent errors (such as timeouts, rate limiting, 5xx); do not retry on parameter errors.
    • Idempotency keys: generate a business idempotency key for each request to prevent duplicate billing or duplicate writes caused by retries.

    Illustrative code (pseudocode, expressing strategy only):

    1. function callModel(req):
    2. for attempt in 0..MAX_RETRY:
    3. try:
    4. return http.post(endpoint, req, timeout=READ_TIMEOUT)
    5. catch e:
    6. if e.type in {TIMEOUT, RATE_LIMIT, SERVER_ERROR} and attempt < MAX_RETRY:
    7. sleep(backoff(attempt) + jitter())
    8. continue
    9. raise e

    It must be emphasized that more retries are not better. Unlimited retries create a “retry storm” during server-side fluctuations, further worsening congestion. In practice, total retries are usually kept to 2 or 3, combined with an overall budget (deadline) to control end-to-end latency.

    3. Reducing Single-Point Dependency: Multi-Model and Multi-Channel Routing

    When a single service experiences a regional outage, the most effective measure is to have a switchable backup channel. In engineering terms, this can be done with a “unified abstraction layer + routing policy”:

    1. Abstract a unified interface: model capabilities (chat, summarization, extraction, embedding) into internal standard interfaces, hiding vendor differences.
    2. Routing dimensions: route by priority, cost, latency, context length, and availability score.
    3. Health-driven: use recent-window error rate and latency percentiles as weights, automatically downgrading abnormal channels.
    4. Semantically equivalent fallback: when the primary model is unavailable, switch to a backup model with similar capabilities, and clearly communicate possible quality differences at the product layer.

    Routing configuration example (illustrative):

    1. routes:
    2. - name: chat-primary
    3. weight: 70
    4. health_window: 60s
    5. - name: chat-secondary
    6. weight: 30
    7. fallback_of: chat-primary

    4. Caching and Result Reuse: Driving Repeated Cost to Zero

    A large volume of business requests are highly repetitive (common questions, fixed templates, batch summarization). Introducing layered caching can significantly reduce dependence on external services:

    • Exact cache: keyed by “prompt + parameters + model version,” returning directly on a hit.
    • Semantic cache: vector nearest-neighbor matching for similar phrasings, reusing results above a hit threshold.
    • Partial reuse: when processing long documents in segments, cache segment results and recompute only changed segments.

    Note: cache keys must include the model version and key parameters (such as temperature, max length); otherwise, after a model upgrade, stale-style results will be returned.

    5. Asynchronous Processing and Peak Shaving: Trading Queues for Stability

    Synchronously waiting for model responses passes traffic peaks directly to external services. It is recommended to:

    • Convert non-real-time tasks (batch generation, offline labeling, report writing) to asynchronous processing via message queues;
    • Return a task identifier to the frontend, with results obtained via polling or push;
    • Set concurrency limits and token-bucket rate limiting on the queue side to smooth burst traffic;
    • Route failed tasks to retry queues and dead-letter queues for manual intervention.

    This way, even if the external service is briefly unavailable, tasks are merely delayed rather than failing outright.

    6. Circuit Breaking, Rate Limiting, and Bulkhead Isolation

    To prevent local failures from spreading into a global avalanche, three isolation mechanisms are needed:

    • Circuit breaker: fast-fail when the error rate exceeds a threshold, entering half-open probing for recovery.
    • Rate limiting: set quotas per tenant, interface, and model to avoid a single caller exhausting resources.
    • Bulkhead isolation: different business lines use independent thread pools/connection pools that do not contend with each other.

    7. Observability: No Measurement, No Optimization

    It is recommended to collect at least the following metrics and set up alerts: request volume, error rate, P50/P95/P99 latency, time-to-first-token, retry rate, circuit-breaker trips, cache hit rate, and cost per request. Also retain call-chain tracing, linking “business request—routing decision—actual channel—latency” so that during a failure it is quick to determine whether it is external fluctuation or an internal bottleneck.

    8. Release and Validation: Canary, Load Testing, and Drills

    • Model or prompt changes go through canary release, validating quality regression with small traffic first;
    • Conduct regular failure drills (shutting down the primary channel, injecting high latency) to verify that the fallback path is genuinely usable;
    • Load testing must cover peak concurrency and long-context scenarios, avoiding validation only under ideal conditions.

    9. Conclusion

    The capability boundaries and availability fluctuations of external LLM services are a premise that application builders must internalize. Through timeout retries, multi-channel routing, cache reuse, asynchronous peak shaving, circuit breaking and isolation, and comprehensive observability, teams can downgrade “occasional service anomalies” from business incidents to predictable engineering events. To further simplify infrastructure operations, you can also rely on general cloud product capabilities such as the container platform, message queue, logging service, and monitoring and alerting offered by Baidu AI Cloud to quickly build the high-availability pipeline described above.