
How to Do Distributed Locking (2016) - appwiz
https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
======
DigitalTerminal
In Azure, we solve this with leasing blobs and always renewing, and
additionally checking ETags when writing.

~~~
tybit
That’s cool. S3 is generally fantastic but as far as I know has no similar
option to this. I wonder if they’ll ever have a strong consistency mode.

~~~
appwiz
Within AWS, consider DynamoDB with the fantastic DynamoDB Lock Client[1]. It’s
a “general purpose distributed locking library built on top of DynamoDB. It
supports both coarse-grained and fine-grained locking.”

    
    
      [1] https://github.com/awslabs/dynamodb-lock-client

------
dang
Discussed at the time:
[https://news.ycombinator.com/item?id=11059738](https://news.ycombinator.com/item?id=11059738)

------
delinka
Seems more like “how not to...”

> Conclusion - I think the Redlock algorithm is a poor choice...

------
dajonker
And the reply from the author of Redis:
[http://antirez.com/news/101](http://antirez.com/news/101)

------
diehunde
Best book on distributed systems out there! It's one of the books that made go
into that area of computer science.

------
MuffinFlavored
Why is "how to do distributed locking" not "setnx in Redis with
timeouts/retries"?

~~~
tyingq
Author says this about setnx:

 _" If you need locks only on a best-effort basis (as an efficiency
optimization, not for correctness), I would recommend sticking with the
straightforward single-node locking algorithm for Redis (conditional set-if-
not-exists to obtain a lock, atomic delete-if-value-matches to release a
lock), and documenting very clearly in your code that the locks are only
approximate and may occasionally fail."_

~~~
MuffinFlavored
I guess I don't understand why setnx locks would fail. Race conditions?

~~~
GauntletWizard
The redis server reboots. Simple as that. Redis is very very rarely run in a
transaction mode that guarantees consistency across reboots (and it's rare
enough to doubt the code works even when it is set to the necessary mode). If
you're using redis in this mode, it's significantly slower than a proper
database, so don't do that either.

------
smnplk
Is lockService in this example a single machine or a cluster of machines ?

