Rate limiting and abuse prevention

DesignMedium40 minGoogle and Stripe style

Your task

Design an API rate-limiting and abuse-prevention layer for a public API gateway handling 1.5M requests/sec across 12 regions. It must enforce per-API-key, per-IP, and per-endpoint limits with multiple tiers, resist distributed credential-stuffing and scraping, and add no more than ~2ms of latency. Limits must be roughly consistent globally (a key shouldn't get 12x its quota by hitting different regions). Cover the algorithm, where counters live, and the global-vs-local consistency trade-off.

It covers

  • Abuse prevention
  • Distributed counters
  • Sliding window