Advertisement
Advanced Redis, Distributed Locks with Redis

What is the Redlock algorithm, and why was it proposed for implementing distributed locks across multiple independent Redis instances?

Short answer

The Redlock algorithm acquires a lock across a majority of several independent Redis instances rather than relying on just one, aiming to provide stronger guarantees against a single Redis instance failure incorrectly causing a lock to be lost or duplicated, though it has also…

Save Redis mock interview
Advertisement
AModel answer
The Redlock algorithm acquires a lock across a majority of several independent Redis instances rather than relying on just one, aiming to provide stronger guarantees against a single Redis instance failure incorrectly causing a lock to be lost or duplicated, though it has also been the subject of debate among distributed systems experts regarding whether it fully guarantees correctness in every failure scenario.
Example

-- Acquire the same lock key across five independent -- Redis instances, requiring a majority to succeed -- before considering the lock successfully acquired

Real-world example
A financial trading system requiring extremely strong locking guarantees implements the Redlock algorithm across five independent Redis instances, accepting the added complexity in exchange for greater resilience against a single instance failure.
Likely follow-ups
  • What are the criticisms that have been raised against the Redlock algorithm's correctness guarantees?
  • Is Redlock necessary for most typical applications, or is a simpler single instance lock usually sufficient?
Related topics