How it works
If each limiter keeps a private counter, a caller can exceed its quota by reaching different workers: three workers with a limit of 100 per minute can admit 300. Sticky sessions, which route a caller to the same worker each time, reduce the symptom but complicate scaling and recovery. A shared counter store gives all workers the same decision state. Envoy’s global rate limiting works this way: the proxy asks a separate service for each decision, and the open-source reference service keeps its counters in Redis.
At regional scale, one remote store adds latency: a caller in Frankfurt checking a counter in Virginia pays a transatlantic round trip, tens of milliseconds, on each request. Local regional counters improve speed but allow some overshoot while totals converge. Suppose two regions last synced when 100 requests of quota remained. Each believes it can spend all 100, so together they admit 200: an overshoot of 100. That is a product tradeoff, not exact global enforcement. If most customers call from one region, per-region counters may be accurate enough.
Partition counters by a stable key when one store cannot handle the workload; Redis Cluster does this with hash slots. Replication and failover need careful handling: Redis replicates asynchronously, so a failover can lose recent counts and temporarily reset allowance. Estimate requests per second, state size, and acceptable overshoot before distributing the decision. A strict global cap may require a more coordinated path than an eventually consistent regional quota.
A caller alternates between two data centers and receives twice its stated global quota. Why?
Each region is likely enforcing an independent counter. Use a coordinated global decision or explicitly allocate regional sub-quotas with a documented overshoot bound.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Private counters multiply the effective quota.
- Regional latency and global accuracy must be negotiated explicitly.