LLM API Outages: Engineering Resilience for External Dependency Failures
When a model API goes down repeatedly, a recovery notice does not guarantee that every account, region, or endpoint can be used again. This article examines how applications can withstand external dependency failures through error classification, bounded retries with exponential backoff and jitter, circuit breakers, degradation and queueing, checkpointed long-running jobs, failover layers, and independent monitoring. It closes with a practical checklist for reducing the blast radius of the next API outage.
1. The Real Problem Behind the Incident
A model service experienced three full outages in a single day. Its status page announced recovery three times, yet some users still could not access the service. A nine-hour automated task failed midway, and all completed work was lost. Such incidents are not rare, but they are instructive for development teams because the core issue is not the stability of any one provider. The core issue is whether the application system can handle the failure of an external dependency.
Three phenomena from the incident are worth analyzing.
First, when the failures peaked, the API returned overload-type errors rather than business-level validation errors. The two error types require completely different handling.
Second, the service recovered and then failed again multiple times, indicating that the root cause had not been eliminated. The recovery period is itself a risk period, and a system should not restore all traffic simply because it receives one “recovered” notice.
Third, a normal status page does not mean that a specific account, region, or endpoint is usable. Relying on the official status page to determine availability can significantly delay a team’s awareness of failures.
These three points correspond to error identification, retry strategy, and availability monitoring. The following sections address each in turn.
2. Classify Errors First
HTTP status codes and provider-specific error codes carry handling guidance. If a client retries every failed request indiscriminately, it wastes quota and worsens server congestion. Common classification principles are as follows:
- 429 (rate limit exceeded): The call rate exceeds the quota. Back off and retry, while checking your own concurrency and quota usage.
- 500, 502, 503, 504 (server or gateway errors): These are usually temporary failures and are suitable for a limited number of retries.
- Overload errors: Most providers use custom status codes to indicate “insufficient overall capacity.” These can be retried, but retry intensity must be strictly controlled. Otherwise, many clients retrying at the same time can create an avalanche.
- 400, 401, 403, 404 (problems with the request itself): Retrying is meaningless. Fail immediately and log the error. In particular, 401 and 403 often indicate credential or permission changes and should trigger an alert.
Putting error classification into code, with accompanying unit tests, is much more reliable than a blanket “retry on failure” policy.
3. Exponential Backoff with Jitter
If a large number of clients retry at fixed intervals at the same time, they will hit the service simultaneously when it recovers and overwhelm it again. Exponential backoff with jitter spreads retry requests over time. The following example shows a basic implementation:
import randomimport timeimport requestsRETRYABLE_STATUS = {429, 500, 502, 503, 504}# Provider-specific overload codes must be added to this set separately,# with their source documented.def call_with_backoff(url, payload, headers,max_retries=5, base=1.0, cap=30.0):for attempt in range(max_retries):try:resp = requests.post(url, json=payload,headers=headers, timeout=30)except requests.RequestException:resp = Noneif resp is not None and resp.status_code < 400:return resp.json()if resp is not None and resp.status_code not in RETRYABLE_STATUS:resp.raise_for_status() # Non-retryable error: raise immediately# Full-jitter strategy: wait randomly in [0, min(cap, base * 2^attempt)]delay = min(cap, base * (2 ** attempt))time.sleep(random.uniform(0, delay))raise RuntimeError("Retries exhausted; check service status and quota")
Three practical points also matter. Retries should be capped, usually at three to five attempts. A per-request timeout should be set explicitly; otherwise threads can block for a long time. All backoff parameters should live in configuration so they can be adjusted quickly during an incident.
4. Circuit Breaking: Stop Ineffective Attempts
Backoff addresses the retry cadence of individual requests. A circuit breaker addresses where overall traffic goes. When the failure rate for a dependency exceeds a threshold, the breaker should open and let subsequent requests fail fast, avoiding a timeout wait on every request. After a cooldown period, the breaker enters a half-open state and allows only a small number of probe requests. If probing succeeds, the breaker closes; if it fails, the breaker remains open.
import timeclass CircuitBreaker:def __init__(self, failure_threshold=5, reset_timeout=60):self.failure_threshold = failure_thresholdself.reset_timeout = reset_timeoutself.failures = 0self.opened_at = Nonedef allow(self):if self.opened_at is None:return Trueif time.time() - self.opened_at >= self.reset_timeout:return True # Half-open: allow probe requestsreturn Falsedef record_success(self):self.failures = 0self.opened_at = Nonedef record_failure(self):self.failures += 1if self.failures >= self.failure_threshold:self.opened_at = time.time()
Circuit breakers are usually deployed as one instance per dependency. If multiple business modules share a single breaker, an anomaly in one module can affect the others. This should be made explicit during design.
5. Degradation and Queueing
When a circuit breaker opens, the system needs an alternative. Otherwise, the error merely changes from a timeout to a fast failure. Common approaches include:
- Cache fallback: For query features, return the most recent successful result and mark the data timestamp in the interface.
- Rule-based fallback: For classification, extraction, and similar tasks, deterministic rules can handle high-frequency cases first, while complex samples are deferred.
- Feature tiering: Rank business functions by criticality. During a failure, protect core paths first and pause non-core features.
- Asynchronous queueing: Write non-real-time tasks to a message queue, and let consumers call the dependency at a controlled rate to flatten the instantaneous peak.
Degradation strategies should be rehearsed during normal operations. Many teams have never actually executed their fallback paths and discover during an incident that the code no longer works.
6. Checkpointing Long-Running Jobs
The nine-hour task in the incident did not fail for a complex reason. The problem was that its design had no checkpoints. Long-running tasks should be split into independently completable steps, with each step’s result persisted promptly and operations made idempotent. Then, after an interruption, the task only needs to resume from the last successful checkpoint.
def run_pipeline(items, store, process):completed = store.load_completed_ids() # Load completed records from persistent storagefor item in items:if item.id in completed:continue # Idempotency: skip items already completedresult = process(item)store.save_result(item.id, result) # Persist each step's result immediately
Checkpoint granularity requires a tradeoff. Too fine a granularity increases storage and write overhead; too coarse a granularity wastes a large amount of completed work during a failure. A single data batch or a single external call is generally a reasonable checkpoint unit.
7. Multi-Channel and Failover
The risk of a single dependency cannot be fully eliminated through retries. A more robust approach is to add a unified interface layer between business code and the specific SDK. This layer handles routing, retries, circuit breaking, and logging. When a switch to a backup channel is needed, business code does not require large-scale changes.
Before switching channels, three areas need evaluation. First, are output quality and format consistent? This is especially important for scenarios that depend on structured output, which require regression testing. Second, do data processing terms and compliance requirements allow sending data to another party? Third, can cost and quota support the backup channel’s traffic? Until these three items are confirmed, fully automatic transparent switching should not be implemented. A manual confirmation step should remain.
8. Monitoring: Real Probes Beyond the Status Page
Official status pages usually rely on the provider’s internal judgment. Publication may lag, and coverage may not match the accounts, regions, and endpoints a team actually uses. Teams therefore need their own monitoring system:
- Synthetic probes: Periodically send a minimal real request and check end-to-end success rate and latency. Probes should cover the endpoints and model configurations actually in use.
- Business metrics: Record error rate, P95 latency, retry count, and circuit breaker open count. These metrics reflect real impact better than simple liveness checks.
- Tiered alerts: A single failure usually does not need an alert. Set a time window and trigger an alert only when the failure rate exceeds a threshold across consecutive windows, avoiding alert fatigue.
- Status page as an auxiliary signal: You can subscribe to official status notifications, but treat them as auxiliary signals and cross-validate them against your own probe results.
9. Implementation Checklist
- The error classification table is implemented in code and covered by unit tests.
- Retry counts, backoff parameters, and timeouts are configurable.
- Long-running tasks have checkpoints and idempotent writes.
- Every external dependency has a circuit breaker, and breaker state is observable.
- At least one degradation path has been rehearsed.
- End-to-end probes and alerts exist independently of the vendor status page.
- Backup channel switching conditions, data compliance review, and cost assessment are documented.
Checking items against this list can help a team keep the impact of the next external service anomaly within an acceptable range.
