all primitives
easy
~4 hours5 stagespython

Rate Limiter

The primitive sitting between every public API and the queue of clients that will retry-storm it the moment it twitches. Five stages from a single-process token bucket to a pluggable Limiter with a distributed-counter backend, burst budget, Retry-After math, and the three flavors of client-side jitter that prevent the next thundering-herd.

fork the python starterkarnstack/byox-rate-limiter-python
use this template
gh repo create my-rate-limiter-python --template karnstack/byox-rate-limiter-python --private --clone

pick private to keep work to yourself, or public for unlimited actions minutes. verification works on both.

checkinggithub link status

your progresspython
0/5verified

no verifications yet. fork the starter, push to main, watch stages light up here.

stages

tests run on every push to main
  1. stage 01Token bucket
  2. stage 02Sliding-window counter
  3. stage 03Pluggable counter backend
  4. stage 04Burst budget and Retry-After
  5. stage 05Client jitter strategies

references

papers cited
used in production by
  • Stripe APIToken-bucket plus sliding-window hybrid. Per-user and per-account dimensions. Returns Retry-After on 429.
  • GitHub REST API5000 requests/hour authenticated, 60/hour unauthenticated. Sliding-window counter. Returns X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.
  • Cloudflare Rate LimitingPer-zone rules at the edge. Sliding-window counter. Scales to millions of domains.
  • AWS API GatewayToken-bucket per stage and per-method with separate account-level burst and steady-state rates.
  • Discord APIPer-route bucket plus a global limit. Documented via X-RateLimit-Bucket, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-RateLimit-Reset-After headers.

Command Palette

Search for a command to run...