LESSON 06 · Distribution

Enforce one quota across many servers

Stateless workers need a common view of each client’s allowance.

SYSTEM VIEW

The decision path

Diagram view
Swipe or scroll to explore the full diagram
Many workers, one logical allowanceRequests may land on either limiter; both use shared counter state to enforce the same quota.Many workers, one logical allowanceroute 1route 2atomicatomicCallerchanging routeLimiter Astateless workerLimiter Bstateless workerShared countersone quota per policy keyRegional local counters trade exact global limits for lower latency.
Requests may land on either limiter; both use shared counter state to enforce the same quota.
Trace the quota decision before a request reaches the API.
THE IDEA

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.

DECISION POINT

A caller alternates between two data centers and receives twice its stated global quota. Why?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Private counters multiply the effective quota.
  • Regional latency and global accuracy must be negotiated explicitly.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

Why does a private in-memory counter on each worker let a caller exceed its quota?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.