Rate Limiting & Backpressure

Difficulty
Importance

The problem

A server has finite capacity, but clients can send requests faster than it can handle them, whether by accident (a buggy retry loop) or on purpose (abuse) — without a deliberate policy for rejecting or slowing excess requests, the server degrades for everyone instead of just the offending client.

Why now

CPU scheduling already established that a scarce resource needs an explicit allocation policy when demand exceeds supply; rate limiting is that same problem at the request-admission level instead of the CPU-instruction level — middleware and request pipelines already gave the mechanism (a pipeline stage) this policy plugs into.

Mental model

Rate limiting is admission control: before doing any real work, ask 'has this client already used its allotted budget in this time window,' and reject if so — protecting the server the same way a scheduler protects the CPU from being monopolized by one process. Backpressure is the same idea pushed further upstream: signaling 'slow down' to a producer instead of silently dropping or endlessly queueing what it sends.

Requires

Used in

Projects

  • Implement a token-bucket rate limiter as middleware, allowing bursts up to a limit but refilling gradually over time
  • Simulate a client exceeding the rate limit and confirm it receives a 429 with a clear Retry-After header

Examples

  • A login endpoint limited to 5 attempts per minute per IP makes brute-force password guessing impractically slow
  • A 429 Too Many Requests response with a Retry-After: 30 header tells a well-behaved client exactly how long to wait before retrying

Resources

Mastery checklist