A stampede on release
A simple distributed lock has every waiter watch the same lock node. When the holder releases it, the service notifies all of them at once. They all wake, all retry, and all but one fail again. This stampede is the herd effect, and it wastes work and spikes load.
The cost
With one hundred waiters, releasing the lock triggers one hundred notifications and one hundred retries, ninety nine of which immediately lose. As contention grows, the service spends more effort waking losers than granting the lock.
The queued fix
The cure is to give each waiter a unique place in line and have it watch only the node ahead of it.
- Each client creates a sequential node, getting a unique number.
- The lowest number holds the lock.
- Each waiter watches only the node with the next lower number.
Now releasing the lock notifies exactly one waiter, the next in line. No herd, just an orderly handoff.
Key idea
The herd effect happens when releasing a lock wakes every waiter, so well designed distributed locks queue waiters and have each watch only its predecessor, waking just one node per release.