Video in progress

How do you design global rate limiting for a public API running in several regions?

Going to a central counter on every request adds cross-region latency to each one. In practice the limit is split between regions, or each region counts locally and periodically syncs the global state; this trades some accuracy for speed.

📖 Answer

The requirement: 6000 requests per minute depending on the customer's plan, with requests arriving in three regions (EU, US, Asia) through GeoDNS. The limit has to be global, worldwide.

A central counter (one Redis in one region). Correct, but from Asia it adds +150 ms to every request, and if the central region goes down, the whole API either stops or is left without limits. I rule this option out right away.

Static split. Each region gets a share of the limit: EU 3000, US 2000, Asia 1000. Simple, no coordination at all. The problem: if a customer's traffic is mostly in one region, they can use only part of their limit. Recomputing the shares daily based on historical traffic helps.

Local + asynchronous sync. Each region counts in its own Redis and every 1–5 seconds announces its counters to the other regions (or to a global aggregator). The decision: local + the last known values from the others < limit. Between syncs, a customer may go slightly over the limit — usually 5–10%. For most businesses that's enough; this rule should be stated openly in the docs.

Dynamic quota (token lease). A global coordinator hands each region "batches" of tokens: EU took 500 tokens and asks again when they run out. A region that's using more gets more. It's more accurate, but more complex.

I also split by layer:

  • A protection limit (DDoS, bots) — at the edge, local only, very fast. Accuracy doesn't matter.
  • A plan limit (the customer pays) — the local + sync approach above.
  • A hard quota (1 million requests a month, billed for the excess) — not in real time, counted with a delay through usage events in billing.

Also: what happens when the limit state goes down (fail open, but with an aggressive local limit), the X-RateLimit-Remaining and Retry-After headers for the customer, and the ability to change limit configuration without a deploy.