educative.io

Educative

Lock system without herd effect

Can you elaborate this part about implementing a lock that does not have herd effect?

There is a different way to implement locks to avoid this problem. All the clients compete for the lock file to create a sequential, ephemeral znode with the same prefix (i.e. /lock-). The client with the smallest sequence number will acquire the lock. The rest of the clients will register watches for the znode with the next lower sequence number. Once a node gets notified, it checks if it’s now the lowest sequence number, which means it can acquire the lock. Otherwise, it registers a new watch for the next znode with the lower sequence number.

It’s not clear to me how the clients know their sequence numbers. It sounds like they have a number and they use that to compare with the sequence number of the most recent znode? Can you elaborate this process more?


Course: https://www.educative.io/courses/distributed-systems-practitioners
Lesson: Examples of Powerful Primitives by Zookeeper’s API - Distributed Systems for Practitioners