Lesson 2 of 4 Resilient Foundation Model Architectures

Handling Throttling with Retries, Backoff and Rate Limiting

This lesson explains how correct retry behaviour turns transient FM call failures into small delays, and how rate limiting stops one client from exhausting shared quotas.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify Bedrock quotas and the errors that indicate them.
  • Configure exponential backoff with jitter in the AWS SDKs.
  • Enforce per-client limits with API Gateway.

Bedrock quotas and errors

Amazon Bedrock enforces per-account, per-Region quotas for on-demand inference, typically as requests per minute (RPM) and tokens per minute (TPM) per model, with separate quotas for cross-Region inference profiles and batch jobs. Quotas are viewed and, where adjustable, raised through Service Quotas. Exceeding them returns ThrottlingException (HTTP 429).

Other errors behave differently. ServiceUnavailableException and InternalServerException are transient and retryable. ModelTimeoutException means generation took too long; ModelNotReadyException means an imported custom model is scaling up from zero, and the SDK retries it automatically. ValidationException, AccessDeniedException and ResourceNotFoundException are caused by the request or configuration and must not be retried unchanged. The following table summarises the behaviour.

ErrorTypical causeAction
ThrottlingExceptionRPM or TPM quota exceededRetry with backoff; reduce tokens; raise quota; cross-Region inference
ServiceUnavailableException, InternalServerExceptionTransient service issueRetry with backoff; fall back if persistent
ModelTimeoutExceptionLong generationStream, shorten output, raise client timeout
ModelNotReadyExceptionImported model scaling from zeroRetry (SDK does automatically); keep warm if latency matters
ValidationExceptionMalformed request, input too longFix the request; do not retry
AccessDeniedExceptionMissing permission or blocked by policyFix IAM, SCP or model access; do not retry

The following diagram groups the errors by the action each one needs.

How Amazon Bedrock errors should be handled. Throttling, service unavailable, internal server and model not ready errors are transient and retried with backoff. Validation, access denied and resource not found errors come from the request or configuration and must be fixed, not retried. A model timeout calls for streaming, a shorter output or a longer client timeout.
Throttling is raised by request or token quotas, which Service Quotas shows.
Sort into groups

Retry or fix the request?

Exam skills 2.4.3 · 5.2.2

Decide whether a client should retry each Bedrock error or fix the request.

Log in to try this activity Interactive activities are free with an account.

Exponential backoff with jitter in the AWS SDKs

Exponential backoff waits longer after each failed attempt, for example 1, 2, 4 and 8 seconds, so clients stop hammering an overloaded service. Jitter adds randomness to the wait so many clients that failed at the same moment do not retry at the same moment. AWS SDKs implement both. In Boto3, the standard retry mode retries throttling and transient errors with backoff and jitter up to a maximum number of attempts; the adaptive mode adds client-side rate limiting that slows the client down when it observes throttling.

Timeouts matter as much as retries. The default read timeout of an SDK client may be shorter than a long generation, causing the client to abandon a request that would have succeeded; for long outputs, raise the read timeout or stream the response.

import boto3
from botocore.config import Config

brt = boto3.client(
    "bedrock-runtime",
    config=Config(
        retries={"max_attempts": 6, "mode": "adaptive"},  # backoff with jitter plus client-side rate limiting
        connect_timeout=5,
        read_timeout=300,                                # long generations need a longer read timeout
    ),
)

The following diagram shows the two traffic paths that protect interactive users from throttling caused by a batch process.

Protecting interactive users from throttling. The web application calls through an API Gateway usage plan and a Lambda function with adaptive retries. The batch process sends work to an SQS queue drained by a limited number of workers. Both reach the model through a cross-Region inference profile for more throughput.
A quota increase is requested only if sustained demand still exceeds the quota.

Rate limiting with API Gateway

When many applications or users share an FM backend, API Gateway enforces limits before requests reach the model. Stage and method throttling set a steady-state rate and burst for the API. Usage plans with API keys give each consuming team its own rate, burst and daily or monthly quota, returning HTTP 429 to the client that exceeds it rather than letting it consume the shared Bedrock quota.

Because FM cost and quota usage depend on tokens rather than requests, a GenAI gateway often adds token-based limits: a Lambda function or container counts tokens per team in DynamoDB or ElastiCache and rejects or queues requests when a team exceeds its token budget. Queues in SQS absorb bursts so that work waits instead of failing.

Scenario questions

Sharing one FM backend fairly

Exam skills 2.4.3 · 2.3.5

Choose the API Gateway feature that meets each rate-limiting requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Throttling at peak

A summarisation service fails with ThrottlingException during a daily peak. Requests come from an internal batch process and an interactive web application. The company wants to protect the interactive users.

Retrying immediately in a tight loop makes throttling worse. A good design uses adaptive retry mode with backoff in both clients, sends the batch process's requests through an SQS queue with a limited number of workers (or moves it to Bedrock batch inference), applies an API Gateway usage plan per consumer, and adds a cross-Region inference profile to raise available throughput. A quota increase can be requested if sustained demand still exceeds it.

Check yourself

Should a ValidationException be retried with backoff?

Show answer

No. It means the request itself is invalid, so it fails again until the request is fixed. Retry only throttling and transient errors.

Exam Tips

Remember for the exam

  • Retry throttling and transient errors with exponential backoff and jitter.
  • Never retry ValidationException or AccessDeniedException unchanged.
  • Adaptive retry mode adds client-side rate limiting.
  • Raise the SDK read timeout or stream for long generations.
  • Per-consumer limits: API Gateway usage plans; token budgets: gateway logic.