Backendcore
Rate limits & backoff
Providers limit requests and tokens per minute; you limit your users. Both need graceful handling.
What it is and why it exists
Provider limits come as requests/min and tokens/min per model and tier; exceeding them returns 429 with Retry-After. Your own API needs per-user and per-tenant limits (token bucket or sliding window, in tokens as well as requests) so one customer can’t starve others.
Quick prototype
Catch 429, sleep 1 s.
In production, at scale
Client-side token-bucket limiter sized below provider limits, retries with exponential backoff + jitter honouring Retry-After, multiple deployments or providers for headroom, queues for batch work, and per-tenant quotas with clear 429 responses and headers.
Vendors and tools
| tenacity / backoff | Retries |
|---|---|
| Redis token bucket / Upstash ratelimit | Distributed limiters |
| LiteLLM router | Load balancing across deployments |
On AWS: Bedrock service quotas (tokens/requests per minute) and provisioned throughput; API Gateway throttling and usage plans.
How it fails
- All workers retrying in sync
- Rate limits counted per instance, so 10 instances get 10× the limit
What the interviewer asks next
Token bucket in one sentence?
A bucket refills at a fixed rate up to a capacity; each request takes tokens (for LLMs: estimated tokens), so short bursts are allowed but the long-run rate is capped.