Skip to content

Rate limiting algorithms

Calculate token budgets and refill waits, compare fixed and sliding windows, and choose an atomic limiter policy under distributed failures.

25 min8 steps

By the end you can
  • Calculate available tokens and the wait for a request to become eligible
  • Compare token bucket, leaky bucket, fixed window and sliding window behavior
  • Choose an atomic quota boundary and an explicit failure policy
  • Choose a client retry response that avoids amplifying overload

Limit the resource the request consumes

A rate limiter decides whether a request may start. A concurrency limiter bounds work in flight. Pick the one that matches the constrained resource, and a subject (account, key, tenant) and cost per call. IP-only limits punish shared NATs.

Rate limit only

  • 100/s still admitted
  • In-flight work explodes at 10 s each

Plus concurrency cap

  • Bounds active work
  • Explicit rejection policy

Requests stay at 100/s, but a dependency slows from 20 ms to ten seconds and active work explodes. What additional control directly bounds the active work?

Answer this step to continue.

What this lesson simplifies

  • Token arithmetic assumes deterministic refill, a monotonic time source and atomic balance updates.
  • Centralized-store latency and multi-region coordination are discussed but not reproduced by the numerical questions.
  • A leaky bucket can mean a shaper or a meter; this lesson explicitly uses a bounded queue shaper.

Sources

  1. J. Heinanen, R. Guerin. A Single Rate Three Color Marker (RFC 2697), 1999.
  2. S. Blake, D. Black, M. Carlson, E. Davies, Z. Wang, W. Weiss. An Architecture for Differentiated Services (RFC 2475), 1998.
  3. M. Nottingham, R. Fielding. Additional HTTP Status Codes (RFC 6585), 2012.

Reviewed by K1 content review on . Revision 1.