Skip to content

Case study: Rate limiter

Design a distributed rate limiter: choose the algorithm, decide where counters live, and make the limiter's own slowness or failure survivable.

30 min9 steps

By the end you can
  • Estimate counter memory, counter-store throughput and the latency budget of a check
  • Design globally consistent per-client limits with atomic counter updates
  • Choose fail-open or fail-closed behaviour and place the limiter in the request path
  • Predict what a burst, a slow counter store and a dead limiter do to clients

Requirements

Per-key/user/IP quotas

  • Allow bounded bursts; live rule updates; 429 + Retry-After

Check p99 <1 ms

  • Shared limits within tolerance; explicit outage policy

Which question decides whether the limiter should fail open or fail closed?

Answer this step to continue.

What this lesson simplifies

  • The simulated limiter is one global token bucket; per-client buckets are discussed but not simulated, so the simulator's 429s also hit well-behaved clients.
  • The shared counter store is modelled as one extra round trip inside the limiter component.

Sources

  1. P. Tarjan (Stripe). Scaling your API with rate limiters, 2017.
  2. M. Nottingham, R. Fielding. Additional HTTP Status Codes (RFC 6585), 2012.
  3. M. Brooker. Exponential Backoff And Jitter, 2015.

Reviewed by Content lead on . Revision 1.