Search code examples
redislockingdistributed-system

What problem does the redis distributed lock solve?


So I just read about redlock. What I understood is that it needs 3 independent machines to work. By independent they mean that all the machines are masters and there is no replication amongst them, which means they are serving different types of data. So why would I need to lock a key present in three independent redis instances acting as masters ? What are the use cases where I would need to use redlock ?


Solution

  • So why would I need to lock a key present in three independent redis instances acting as masters?

    It's not that you're locking a key within Redis. Rather, the key is the lock, and used to control access to some other resource. That other resource could be anything, and generally is something outside of Redis since Redis has its own mechanisms for allowing atomic access to its data structures.

    What are the use cases where I would need to use redlock?

    You would use a distributed lock when you want only one member at a time of a distributed system to do something.

    To take a random example from the internet, here's Coinbase talking about their use of a distributed lock to "ensure that multiple processes do not concurrently generate and broadcast separate transactions to the network".