Throttling
Cap how many requests each client can make in a time window, and reject the excess politely, to protect your service and keep it fair.
Description
Throttling counts requests per client (API key, user, IP or tenant) and enforces a limit, such as 100 requests per minute. Requests within the limit go through; the rest get HTTP 429 Too Many Requests with a Retry-After header saying when to try again.
It protects the service from accidental floods (a buggy script, a retry storm) and deliberate abuse, keeps one heavy customer from slowing everyone else down, and can enforce pricing tiers. Common algorithms are the token bucket, which allows short bursts, and the sliding window.
System design
Throttling system design diagram
- API clients (client).
- API gateway (gateway): 100 req/min per key.
- Rate counters (cache): token buckets.
- Orders API (service).
- Step 1: API clients → API gateway: requests.
- Step 2: API gateway → Rate counters: take a token for key.
- Step 3: API gateway → Orders API: within limit.
- Step 4: API gateway → API clients: 429 + Retry-After (failure path).
- Clients send requests with their API key.
- The gateway takes a token from that key's bucket in a shared counter store. The bucket refills at 100 tokens per minute and allows short bursts.
- When a token is available, the request goes through to the API.
- When the bucket is empty, the gateway answers 429 with a Retry-After header, without ever touching the API.
- AWS
- API Gateway usage plans and throttling; AWS WAF rate-based rules.
- Azure
- API Management rate-limit-by-key and quota policies; Front Door/WAF rate limiting.
- Google Cloud
- API Gateway and Apigee quotas; Cloud Armor rate limiting.
When to use it
Use it when
- Public or partner APIs, where you don't control client behaviour.
- Multi-tenant services, where fairness between customers matters.
- Expensive endpoints such as search, exports or AI calls that could be overwhelmed by a few clients.
- Pricing plans that include usage limits.
Avoid it when
- Internal calls between your own services, where backpressure, queues or bulkheads fit better than rejecting requests.
- Load is predictable and well below capacity. Start with monitoring and add limits when needed.
Pitfalls
- Limits counted per instance instead of globally, so the real limit grows with every instance you add. Keep counters in a shared store or at the gateway.
- No
Retry-Afterheader, so clients retry immediately and make it worse. - One global limit for all clients, so one heavy user exhausts it for everyone. Limit per key.
- Failing closed when the counter store is down, which turns a cache outage into a full outage. Decide whether to fail open.
Alternatives
Queue-Based Load Leveling
Choose it when you'd rather accept all the work and process it at a steady rate than reject it.
Bulkhead
Choose it when you want to isolate workloads from each other inside your service, not limit clients.
Autoscaling
Choose it when spikes are legitimate demand you want to serve; scale out, and keep throttling as a safety net.