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

Gossip Protocols for Rate Limit Sync

How nodes can share rate limit state through eventual consistency gossip without central coordination.

Gossip Protocols for Rate Limit Sync

You'll learn how nodes can share rate limit state through eventual consistency without needing a central coordinator like Redis.

The Core Idea

In a gossip protocol, each rate limiter node periodically shares its local counter state with a few random peers, who then share with their peers, and so on — like rumors spreading through a crowd. Over time, every node learns approximate global state without central coordination.

When a request hits Node A, it checks its local counter. Periodically (say, every 100ms), Node A picks 2-3 random peers and exchanges counter values: "I've seen 45 requests for user X." The peer responds: "I've seen 30." They merge this information (typically summing or taking max values) and update their local views.

How It Works for Rate Limiting

Each node maintains:

  • Local counters for rate limit keys (user IDs, API keys, etc.)
  • A gossip interval timer
  • A list of peer nodes

When gossip fires:

  1. Node selects random peers
  2. Sends its counter deltas since last sync
  3. Receives peer deltas
  4. Merges data (sum counters, reconcile timestamps)
  5. Makes rate limit decisions based on merged state

The Tradeoffs

Pros:

  • No single point of failure (unlike centralized Redis)
  • Scales horizontally as nodes join
  • Tolerates network partitions

Cons:

  • Eventually consistent (not strongly consistent)
  • May allow brief over-limit bursts during propagation
  • Requires more memory (each node stores state)
  • Network chattiness increases with cluster size

Key Takeaway: Gossip protocols enable distributed rate limiting through peer-to-peer state sharing, trading strong consistency for resilience and eliminating central bottlenecks — ideal when approximate limits are acceptable.