← Lessons

quiz vs the machine

Gold1400

Concurrency

Redis Redlock and Its Critics

How Redlock spreads a lock across nodes, and why some call it unsafe.

6 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. When does a Redlock client consider the lock acquired?

2. What is the main critique of Redlock for correctness?