Rate limiting & backpressure

Token bucket vs sliding window, per-user vs global limits, 429 + Retry-After, load shedding. A favorite "design a small thing well" interview question.

About 32 min read3-question knowledge check

The mental model

Rate limiting is the bouncer at a club with a fixed capacity. The club can hold 500 people safely; the bouncer's job is to let people in at a rate the club can handle and to turn away the rest with a clear "not right now, try again in a minute" rather than letting everyone cram in until the fire marshal shuts the whole place down. Backpressure is the same idea pointed inward: when the kitchen is behind, the club stops seating new tables, because seating people you cannot serve just makes everyone's night worse.

The two concepts are two answers to one question: what do you do when demand exceeds capacity? You can pretend it does not (and fall over), or you can decide deliberately whose requests to serve and whose to reject, and reject them cheaply and clearly so the client can back off and retry. Rate limiting is the outward-facing policy ("you get N requests per minute"); backpressure is the internal mechanism that propagates "I am full" upstream so producers slow down instead of piling work onto a drowning consumer.

Why this exists — what breaks without it. Without rate limiting, one buggy client in a retry loop, one scraper, or one thundering-herd retry storm consumes all your capacity and every other user is denied service — a self-inflicted outage triggered by a single actor. Without backpressure, a fast producer feeds a slow consumer until a queue grows unbounded and the process runs out of memory, or until latency balloons so high that every request times out and the client retries, adding load exactly when you have least to spare — the retry-storm death spiral. The alternative to shedding load is not "serve everyone"; it is "serve no one, slowly, then crash". A system that degrades gracefully rejects some requests on purpose so the rest succeed. This is a favourite "design a small thing well" interview question precisely because the naive version (a counter) is easy and the correct version (atomic, distributed, with the right algorithm and the right response) reveals depth.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision