Reliability, Security & ObservabilityAdvanced15 min read1 questions

Rate Limiting Algorithms and Distributed Throttling

Four algorithms, one correct default, and the hard part nobody mentions: enforcing a global limit across fifty servers without a round trip on every request.

Covers: Token bucket, leaky bucket, fixed and sliding windows, distributed counters, response headers, layered limits

Rate limiting protects you from abusive clients, buggy clients, and your own retry logic. It is also a favourite interview question because the algorithms are simple enough to implement on a whiteboard and the distributed version is genuinely hard.

Filter
0/1 mastered
Advancedrate limitingalgorithmsthrottlingAsked at Stripe, Cloudflare

30-second answer

Token bucket refills tokens at a fixed rate up to a capacity, so it enforces an average rate while allowing bursts up to the bucket size - that flexibility makes it the usual default for APIs. Leaky bucket drains at a constant rate, smoothing traffic completely, which suits downstream systems that cannot absorb bursts at all. Fixed window is the simplest and has a serious flaw: a client can send a full window's quota at the end of one window and again at the start of the next, achieving double the intended rate. Sliding window log is exact but stores a timestamp per request; sliding window counter approximates it cheaply and is the right choice when precision matters more than burst tolerance.

Showing 1 of 1 questions for rate-limiting-algorithms.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.A limit of 100/minute using a fixed window. A client sends 100 at 10:00:59 and 100 at 10:01:00. What happened?

Question 2

2.Which algorithm allows bursts while enforcing a long-run average rate?

Question 3

3.Fifty nodes must enforce one shared limit without adding latency to every request. Best approach?

Question 4

4.Why must a 429 response include Retry-After?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Build a distributed rate limiter

Implement a limiter enforcing 1,000 requests per minute per API key across a fleet of ten nodes, with no Redis call on the hot path.

Requirements

  • Implement token bucket locally with lazy refill and configurable per-endpoint cost.
  • Design the quota-lease protocol: how each node claims and returns unused allowance.
  • Handle the shared store being unavailable, and justify fail-open or fail-closed.
  • Return correct RateLimit and Retry-After headers on rejection.
  • Load-test with uneven distribution across nodes and measure actual overshoot against the 1,000 target.

Stretch goals

  • Add a second dimension (per user inside an API key) and show both being enforced.
  • Add a burst allowance that recharges hourly and cannot be sustained.