Skip to content
StackDecode
System Design
20. System Design Case StudiesAnimated

API Rate Limiter

Limit how often clients can call.

The idea

Counters per client in a fast store decide whether to allow each request.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

arrivals 4tokens 5allowed 4 rejected 0steady rate
  • allowed
  • rejected

4 requests arrive. The bucket refills 3 tokens per tick (max 9), so bursts are allowed until it empties. 4 pass.

tick:
1
allowed:
4
rejected:
0
1/24

Bars show how many requests were let through each tick.

Step by step

  1. 1Identify the client
  2. 2Check its counter
  3. 3Allow or reject
  4. 4Update the counter

Where it is used

Protecting APIs.

Watch out for

Races in distributed counters and burst fairness.

Related