AlgoViz

Design an API Rate Limiter

medium 45 min

Decide, in about a millisecond and on every request, whether this caller may go on.

Where it shows up

The same pattern appears across everyday software.

  • Plans and tiers

    A free caller gets 100 requests a minute and a premium caller 1,000. The limiter is where that promise is kept.

  • Login protection

    Sign-in has a low limit for each account and each address, so guessing passwords is slow.

  • Expensive endpoints

    A report that costs fifty times a normal read takes fifty tokens, so a caller cannot spend the whole quota on the worst call.

  • Managed gateways

    AWS API Gateway documents token bucket throttling with a rate and a burst, and warns that the limits are targets, not guaranteed ceilings.

  • Two windows and a weight

    Cloudflare wrote that it estimates a rate from this minute's count and a weighted share of the last minute's.

  • Payment APIs

    Stripe has described a token bucket limiter, plus separate limiters that shed less important work when the fleet is in trouble.