Skip to main content
Architecturechapter 4 of 5 · 4 lessons

Rate Limiting

Throttle requests per user/IP to protect services from abuse and overload.

A customer's integration has a bug in its retry loop. At 09:14 it starts calling your API 4,000 times a second instead of four.

Your database saturates, and every other customer's requests start timing out behind it. One misconfigured cron job, and the whole platform is down.

Nobody attacked you. This is the ordinary case, and it is far more common than the malicious one: a mobile release with a polling bug, a scraper walking your identifiers, a data team backfilling through the production API.

A rate limiter turns each of those from an outage into a stream of refusals and a support conversation. It is also how you keep one noisy tenant from taxing everyone, and how the numbers on your pricing page become real.

Lessons

4 in this chapter
  1. Why You ThrottleA rate limiter converts unbounded demand into a bounded promise you can engineer for.2 min
  2. The AlgorithmsToken bucket, leaky bucket, fixed window, sliding window: four answers to what counts as too fast.3 min
  3. Making Limits Hold Across a FleetTen gateways sharing one limit need shared state, and shared state costs a round trip.2 min
  4. Telling Clients No, UsefullyA 429 with good headers turns rejected clients into cooperative ones.2 min