SystemKit

Rate Limiter

Protect a service from overload and abuse. Compare token bucket and window algorithms, keep counters correct under concurrency, and decide what should happen when the limiter itself fails.

Lessons

  1. 01Define what is being limitedA limit has an identity, an action, a quota, a time scale, and a response.
  2. 02Choose where requests are checkedThe gate must run before the expensive work and share policy across instances.
  3. 03Allow controlled bursts with tokensCapacity sets burst size; refill rate sets the long-run pace.
  4. 04Pick the accuracy and memory tradeoffCounting requests by time is simple until traffic lands on a boundary.
  5. 05Make each decision atomicA read, check, and write sequence can approve too many simultaneous requests.
  6. 06Enforce one quota across many serversStateless workers need a common view of each client’s allowance.
  7. 07Explain throttling and tune the ruleA useful limiter tells clients when to retry and tells operators whom it affects.

Practice this chapter

  1. LabWhich rate limiting algorithm lets a burst through?Run fixed window, sliding log, sliding counter, and token bucket on the same traffic and compare what each one admits.
  2. TaskDesign rate limits and plan quotas for a public APIApply the rate limiter chapter to two limits with different jobs: a per-second limit that protects capacity and a monthly quota that customers pay for.