Designing a distributed rate limiter: share quotas across instances
A distributed rate limiter shares decision state so multiple servers enforce one user or tenant limit. Independent per-process counters can let a client obtain the allowance again when load balancing sends it to another server. A shared store or dedicated rate-limit service reduces that duplication, but adds a dependency to the request path; define its latency cost and failure behavior too.
A distributed rate limiter shares decision state so multiple servers enforce one user or tenant limit. Independent per-process counters can let a client obtain the allowance again when load balancing sends it to another server. A shared store or dedicated rate-limit service reduces that duplication, but adds a dependency to the request path; define its latency cost and failure behavior too.
Local limits versus shared limits
Suppose one client is allowed 100 requests per minute and the service has four servers. If each server independently allows 100, the effective total can approach 400 when traffic is spread evenly and counters are independent. A local limit can protect one server's CPU or queue, but it does not enforce a user-wide quota.
A shared limit reads or updates common state across instances. Redis documents using keys scoped by user, IP, API key, or tenant and using Lua to make read-decide-update atomic. The operator still chooses the algorithm (fixed window, sliding window, or token bucket), time policy, and key dimensions.
Decisions before putting a shared store on the request path
**Scope and key:** Prefer a trusted identity such as an authenticated user or tenant. IP addresses can be shared behind NAT or obscured by proxies. Adding route or method dimensions makes policy finer-grained but increases key count and store load.
**Algorithm and atomicity:** Make the read/check/update operation atomic so concurrent requests on different servers cannot exceed a shared counter. If multiple limits apply, verify that partial token/counter deductions do not remain.
**Store outage policy:** Decide whether to allow requests (fail open), reject them (fail closed), or apply a separate local fallback when the store is slow or unavailable. Choose based on the protected resource and security, billing, and availability requirements; there is no universally safe default.
**Latency and capacity:** A synchronous lookup adds a network round trip to requests. Check timeouts, connection pools, retry amplification, datastore capacity, and hot-key behavior under load.
**Regional consistency:** Separate regional state may not enforce an immediate global limit. Choose between a strict global quota, explicitly divided regional allowances, or an approximate limit based on the store's replication guarantees.
Envoy Gateway and Redis example
Envoy Gateway docs distinguish global limits shared across configured proxy instances from local limits, and show Redis as a global-limit backend. Their examples distinguish route-level buckets from a bucket shared across a Gateway. Do not assume that a Gateway-targeted policy automatically creates one bucket for every route; check the policy scope and merge behavior.
To verify a deployment, inspect policy status and bucket scope, then send traffic through different proxy instances and confirm that requests consume one shared limit. In a test environment, check normal responses, limited responses, and behavior when Redis is unavailable; monitor limit counters and store latency. These are proposed checks, not tests performed for this article.
A global limit does not replace local protection. A local limiter can shed bursts before they reach the shared service. If both layers are used, document their independent allowances, order, and outage fallback.
Sources
[Redis rate limiter guide](https://redis.io/docs/latest/develop/use-cases/rate-limiter/)
[Envoy Gateway global rate limit](https://gateway.envoyproxy.io/docs/tasks/traffic/global-rate-limit/)
[Envoy v1.31.7 global rate limiting architecture](https://www.envoyproxy.io/docs/envoy/v1.31.7/intro/arch_overview/other_features/global_rate_limiting)