Course contentsShow
← System Design
Lesson 984 of 1,91925. Rate Limiting and ThrottlingFree lesson

Quota Sharding Across Nodes

Dividing total rate limit quota among application instances and handling dynamic node counts.

Quota Sharding Across Nodes

You'll learn how to divide a global rate limit quota among multiple application instances and handle nodes joining or leaving the cluster.

The Core Problem

When you have a rate limit of "1000 requests per minute per user" and multiple server nodes handling requests, you face a challenge: how do you divide that 1000-request quota fairly? If each node independently allows 1000 requests, you've effectively multiplied the limit by your node count—defeating the purpose.

Quota sharding means splitting the total allowed quota across your nodes. If you have 4 nodes and a 1000 req/min limit, each node might enforce a local limit of 250 req/min.

How It Works

The simplest approach:

Local Node Limit = Global Limit / Number of Nodes

Each node tracks its own portion independently. A user hitting Node A consumes from Node A's quota; a request to Node B consumes from Node B's quota.

Dynamic Node Counts

The real challenge is when nodes scale up or down:

  • Node added: Existing nodes must reduce their quotas; the new node claims its share
  • Node removed: Remaining nodes must increase their quotas to maintain the global limit

This requires coordination—nodes must discover each other (via gossip protocols or service registry) and recalculate their local quotas dynamically.

The Inherent Tradeoff

Sharding creates unfairness: if traffic isn't perfectly balanced (sticky sessions, uneven load), some nodes might reject requests while others have quota remaining. It's the price you pay for avoiding centralized coordination overhead.

Key Takeaway:
Quota sharding divides a global rate limit among nodes for independent enforcement, but requires dynamic recalculation as the cluster size changes—trading perfect accuracy for scalability.