Backend & APIs · Intermediate

Build a Rate Limiter

Build HTTP middleware that throttles requests per client using token-bucket and sliding-window algorithms backed by Redis, returning standard rate-limit headers.

Intermediate12-20 hoursTypeScriptGo

You build rate-limiting middleware that sits in front of an HTTP API and decides, per client key, whether each incoming request is allowed or rejected with 429 Too Many Requests. You implement at least two algorithms, token bucket and sliding-window log or counter, and back the counters in Redis so limits hold across multiple server instances. The middleware identifies callers by API key or IP, returns X-RateLimit-Limit, X-RateLimit-Remaining, and Retry-After headers, and stays correct under concurrent traffic. It is worth building because rate limiting is a real production concern at every API company and it teaches you distributed counters, atomicity, and the trade-offs between limiter algorithms. It is resume-worthy because it demonstrates you can reason about fairness, race conditions, and shared state across a cluster.

What you build

  • Pluggable token-bucket and sliding-window limiting strategies
  • Per-client keying by API key or IP address
  • Redis-backed counters so limits are shared across instances
  • Returns 429 with Retry-After and X-RateLimit-* headers
  • Atomic check-and-decrement to avoid race conditions
  • Configurable limits and windows per route or per client tier
  • Graceful fallback behavior when Redis is unavailable

What it teaches

  • Token-bucket and sliding-window rate-limiting algorithms
  • Atomic operations on Redis with Lua scripts
  • HTTP middleware design and 429 semantics
  • Distributed shared counters across instances
  • Standard rate-limit response headers
  • Concurrency and race-condition avoidance

Sign in to open the build guide

Free account. Get the step-by-step build and every resource link.

Sign in to continue

Take it further

  • Add per-tier limits driven by an API-key lookup.
  • Implement the sliding-window-log variant and compare accuracy.
  • Expose Prometheus metrics for allowed and throttled counts.

More like this

All projects