Skip to main content
Back to Community & Earn Hub

AWS Bedrock Cross-Region Inference & Token Bucket Throttling: Surviving ThrottlingException Storms at US Enterprise Scale

@siddharth_rao4 days ago·1 min read 1982 views
AWS Bedrock Cross-Region Inference & Token Bucket Throttling: Surviving ThrottlingException Storms at US Enterprise Scale

The 9:00 AM EST ThrottlingException Storm

If you run production AI agents on AWS Bedrock in us-east-1, you know the pain of 9:00 AM EST Monday traffic spikes:

  • Your account's Tokens-Per-Minute (TPM) quota in us-east-1 saturates instantly.
  • Bedrock returns botocore.exceptions.ClientError: ThrottlingException (Too many tokens per minute).
  • 20 worker pods blindly enter exponential retry loops at the same time—creating a retry thundering herd that keeps the quota pinned at 100% for 15 minutes straight!

Two-Part Fix: Cross-Region Inference + Distributed Token Bucket

  1. Switch to Cross-Region Inference Profiles (us.* prefix): Instead of pinning requests strictly to us-east-1, invoke the us. profile ID (e.g., us.anthropic.claude-3-5-sonnet-20241022-v2:0). AWS automatically routes excess burst traffic across us-east-1, us-east-2, and us-west-2 within US data residency boundaries—doubling or tripling effective TPM burst capacity at zero extra cost.
  2. Pre-Flight Redis Token Bucket: Smooth out multi-worker bursts before calling converse_stream() so pods never trigger retry storms.
text
[20 Agent Worker Pods]
         │
         ▼
[Redis Atomic Lua Token Bucket (checks TPM + RPM budget)]
  ├── Budget OK  ──► Bedrock Cross-Region (`us.anthropic...`)
  └── Near Cap   ──► Jittered sleep (200-800ms) or failover to vLLM VPC

Python Redis Token-Bucket Guard for Bedrock

python
import asyncio
import random
import time
import boto3

bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")

# Atomic Redis Lua script enforcing Tokens-Per-Minute ceiling
TOKEN_BUCKET_LUA = '''
local key = KEYS[1]
local capacity = tonumber(ARGV[1])
local refill_per_sec = tonumber(ARGV[2])
local requested = tonumber(ARGV[3])
local now = tonumber(ARGV[4])

local data = redis.call("HMGET", key, "tokens", "ts")
local tokens = tonumber(data[1]) or capacity
local last_ts = tonumber(data[2]) or now

tokens = math.min(capacity, tokens + (now - last_ts) * refill_per_sec)
if tokens < requested then
    return 0
end

redis.call("HMSET", key, "tokens", tokens - requested, "ts", now)
redis.call("EXPIRE", key, 120)
return 1
'''

async def invoke_bedrock_throttled(redis, estimated_tokens: int, messages: list[dict]):
    tpm_limit = 400_000
    for attempt in range(5):
        allowed = await redis.eval(
            TOKEN_BUCKET_LUA,
            1,
            "bedrock:tpm:us_sonnet",
            tpm_limit,
            tpm_limit / 60.0,
            estimated_tokens,
            time.time(),
        )
        if allowed:
            return bedrock.converse(
                modelId="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
                messages=messages,
            )
        # Full jitter backoff before re-checking bucket
        await asyncio.sleep(random.uniform(0.25, 1.0) * (attempt + 1))
    raise TimeoutError("Bedrock TPM budget exhausted after 5 backoff attempts")

Combining us.* cross-region inference profiles with an atomic Redis token bucket eliminates 99% of production ThrottlingException cascades.

2 Comments

Discussion

@rohan_mehta4 days ago

Switching from anthropic.claude... to the us.anthropic.claude... cross-region inference profile ID was the single easiest reliability win we made on AWS Bedrock—zero code architecture changes and instant multi-region burst capacity.

@tanvi_kulkarni4 days ago

Pre-flight Redis Lua token bucketing stops the thundering herd before it starts. Without it, 20 pods all sleeping 1s, 2s, 4s in lockstep just slam Bedrock together at the exact same second.

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.