Advanced Throttling Strategies
You'll learn to
- -Compare token bucket and sliding window throttling algorithms at the gateway level, building on the class-level rate limiter from LLD Fundamentals
- -Design tiered rate limits that differentiate by client plan or identity rather than applying one uniform limit to everyone
The basic rate-limiting chapter earlier in this course covered communicating limits to clients via headers; this chapter covers the algorithms and policy design behind the limit itself, at the scale of an API gateway sitting in front of every request to every backend service - the same token bucket and sliding window algorithms from LLD Fundamentals' rate limiter case study, now applied at gateway scale with tiered policies.
Token Bucket at Gateway Scale
A token bucket per client (or per API key) allows short bursts up to the bucket's capacity while enforcing a steady average rate over time - the same algorithm from the LLD Fundamentals case study, but now the gateway needs to track buckets for potentially millions of distinct clients, which typically means the bucket state lives in a shared, fast store (like Redis) rather than in a single process's memory, so the limit is enforced consistently regardless of which gateway instance actually handles a given request.
Tiered Limits by Plan
{
"free_tier": {"requests_per_minute": 60, "burst_capacity": 10},
"pro_tier": {"requests_per_minute": 600, "burst_capacity": 100},
"enterprise_tier": {"requests_per_minute": 6000, "burst_capacity": 1000}
}A single uniform rate limit across every client treats a free-tier hobbyist and an enterprise customer with a negotiated contract identically, which is rarely the actual business intent - tiered limits, keyed by the client's plan or identity (established during authentication at the gateway), let the throttling policy reflect what each client has actually paid for or been granted, rather than a one-size-fits-all number.
Per-Endpoint Limits, Not Just Per-Client
Not every endpoint costs the same to serve - a cheap `GET /users/42` lookup and an expensive `POST /reports/generate` that kicks off real computation shouldn't necessarily share the same budget. Layering per-endpoint (or per-endpoint-category) limits on top of per-client limits lets the gateway protect specifically expensive operations more tightly, without needlessly restricting a client's access to cheap, high-volume endpoints just because they've been using an expensive one heavily.
A distributed rate limiter (state shared across many gateway instances via a store like Redis) adds real latency to every single request - the shared-state lookup has to happen synchronously, in the request path, before the request is allowed through. This is a genuine performance cost that needs to be weighed against the coarser, but faster, alternative of eventually-consistent local counters per gateway instance.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Design Throttle Engine in the API Design Lab's Full System Design act.