The algorithm
Redlock locks across N independent Redis masters, typically five. A client:
- Records the start time, then tries to SET a key with a random value and a TTL on each instance, using a short per node timeout.
- Counts successes. If it captured a majority and the elapsed time is less than the TTL, the lock is held.
- The validity is the TTL minus the elapsed acquisition time.
To release, the client deletes the key on every node, but only if the stored value matches its random token, using a small Lua script for atomicity.
The controversy
Critics argue Redlock relies on bounded clocks and bounded pauses. A long garbage collection pause or a clock jump can let two clients believe they hold the lock at once.
- The random value prevents deleting someone else's lock.
- But it does not stop a stale holder from acting after a pause unless a fencing token guards the resource.
Key idea
Redlock trades a single point of failure for a quorum of Redis masters, but for correctness against pauses you still need fencing on the protected resource.