Home / AI & GenAI

AI & GenAIRunbookAdvanced

Sev1: a burst of LLM 429s turned into a full outage — stopping a retry storm across SDK, app and gateway

A short throttling spike became a sustained outage because the SDK, the app and the gateway all retry. Cut the multiplied load, let the quota recover, and fix the retry layering.

Deepak Bhardwaj6 min read

Applies toAzure OpenAI, OpenAI and Amazon Bedrock clients (openai Python SDK 1.x, boto3), Azure API Management or LiteLLM gateways, Kubernetes-hosted apps

Symptoms

  • A traffic peak or a batch job caused a few minutes of 429s. The peak is over, but 429s and timeouts continue.
  • Gateway request count is several times higher than user request count.
  • Latency for the few successful calls is very high; app worker pools and connection pools are saturated.
  • Provider metrics show the deployment at 100% of its tokens-per-minute or requests-per-minute limit, all the time.

Why it doesn't recover on its own

Each layer retries independently. With three attempts at each of three layers, one user request can become up to 27 calls to the model:

Layer Typical default Attempts per call
openai Python SDK max_retries=2 3
App code (tenacity, custom loop) often 3–5 3–5
Gateway (APIM retry policy, LiteLLM num_retries) often 3 3
Client or browser reload user presses retry 2+

The quota is full, so most of those calls fail fast with 429. They still count as requests, and on some providers rejected requests count against the requests-per-minute limit. The load never drops below the limit, so the system stays in throttling.

Step 1: confirm the amplification (5 minutes)

If APIM is the gateway and diagnostic logs go to Log Analytics (resource-specific tables), compare user requests with backend calls:

ApiManagementGatewayLogs
| where TimeGenerated > ago(1h)
| summarize requests = count(),
            backend429 = countif(BackendResponseCode == 429),
            ok = countif(ResponseCode == 200),
            distinctCorrelation = dcount(CorrelationId)
          by bin(TimeGenerated, 1m)
| extend callsPerRequest = round(todouble(requests) / distinctCorrelation, 2)
| order by TimeGenerated asc

The CorrelationId handling depends on how your apps send headers, so treat callsPerRequest as a guide. Also check the app's own logs for retry counts. In the openai SDK, set OPENAI_LOG=debug on one pod to see each retry.

On the provider side for Azure OpenAI, look at the AzureOpenAIRequests metric split by StatusCode. If 429s stay flat at a high level after user traffic falls, you are in a retry storm. Metric names vary by resource type; check the Metrics blade for your account.

Step 2: cut the load now

Do these in order and stop when the 429 rate drops sharply.

Pause non-interactive callers

Batch, embedding and evaluation jobs are usually the biggest contributors and the easiest to stop:

kubectl -n genai scale deploy/embedding-worker --replicas=0
kubectl -n genai patch cronjob nightly-eval -p '{"spec":{"suspend":true}}'

Turn off gateway retries

In APIM, a retry policy like this multiplies load when the backend is throttling:

<retry condition="@(context.Response.StatusCode == 429)" count="3" interval="1" first-fast-retry="true">
    <forward-request buffer-request-body="true" />
</retry>

Remove it or set count="0" for the incident. Retrying in the gateway makes sense only when it sends the retry to a different backend (a backend pool with another region or deployment). Retrying the same throttled backend never helps.

Shed load at the edge

Return a fast, clear error to some users instead of slow failures for all of them. In APIM, a temporary rate-limit-by-key on the AI APIs does this:

<rate-limit-by-key calls="300" renewal-period="60" counter-key="@(context.Subscription.Id)" />

Pick numbers below what the backend can serve. Remove the policy after recovery.

Warning

Don't raise worker counts or scale out the app to "clear the backlog". More workers means more concurrent retries against a quota that is already full.

Step 3: let the quota recover

Once load is below the limit, the tokens-per-minute window drains within a minute or two. Watch the provider's 429 rate. When it is near zero for five minutes, bring callers back one at a time:

kubectl -n genai scale deploy/embedding-worker --replicas=1
# wait, watch 429s, then increase

Step 4: fix the retry layering

Retry in one place, with backoff, jitter and a cap. Everywhere else, fail fast.

Recommended split:

Layer Setting
SDK in the app max_retries=1 or 2, honours retry-after / retry-after-ms
App code No extra retry loop around the SDK; circuit breaker instead
Gateway Retry only to a different backend; never to the same one
UI Disable resend button while a request is in flight

openai SDK (works for Azure OpenAI too):

from openai import AzureOpenAI

client = AzureOpenAI(
    azure_endpoint="https://<resource>.openai.azure.com",
    api_version="<your api version>",
    azure_ad_token_provider=token_provider,
    max_retries=2,       # the SDK backs off and respects retry-after headers
    timeout=30,
)

boto3 for Bedrock:

import boto3
from botocore.config import Config

bedrock = boto3.client(
    "bedrock-runtime",
    config=Config(retries={"max_attempts": 3, "mode": "standard"}, read_timeout=60),
)

Cap concurrency per process so a spike queues locally instead of hammering the provider:

import asyncio
LLM_SLOTS = asyncio.Semaphore(16)

async def call_llm(fn, *args, **kwargs):
    async with LLM_SLOTS:
        return await fn(*args, **kwargs)

Add a simple circuit breaker: after N throttled calls in a short window, stop calling for a few seconds and return a "busy" response.

Tip

If you use LiteLLM as the gateway, check num_retries in the router settings and in each model entry, and the cooldown settings for failed deployments. Retries there are added on top of whatever the client SDK does. Parameter names vary by LiteLLM version; check your config reference.

Step 5: confirm

  • 429 rate at the provider back to baseline for 30 minutes with all callers restored.
  • Gateway calls per user request close to 1.
  • p95 latency back to normal; worker and connection pools no longer saturated.

Prevent it next time

  • Write down the retry budget for every AI call path: which layer retries, how many times, with what backoff. Review it in design and code review.
  • Separate quota for batch and interactive traffic (separate deployments, projects or inference profiles), so a backfill can't trigger a storm on production.
  • Alert on the ratio of gateway calls to user requests, not just on 429 count.
  • Load test with throttling: set a low limit in staging and confirm the system recovers within minutes after load drops.
  • Keep the "pause batch, remove gateway retries, shed load" steps in the on-call runbook with the exact commands.