Back to Hub

Distributed Lock Contention Latency.

Microservices simulator demonstrating lock contention and thread starvation when scaling distributed systems relying on Redis (Spinlocks) vs ZooKeeper (Ephemeral Nodes).

## The Thundering Herd Problem

When 500 pods in a Kubernetes cluster all wake up simultaneously to grab a Distributed Lock (mutex), a naive Redis `SETNX` (Set if Not Exists) loop causes a Thundering Herd. They continuously bombard the database with "Can I have it yet?" queries thousands of times per second, DDOSing your own infrastructure.

### FAQ

**Q: How do ZooKeeper or Etcd fix this?**
A: Instead of polling, they use event-driven 'Watchers'. The 500 pods are placed in a strict sequential queue. The system goes to sleep. When Node 1 finishes, the database proactively pings Node 2 and says "Your turn". Zero wasted network traffic.