What is everyone using for distributed locks in lo...
# cfml-general
e
What is everyone using for distributed locks in load balanced environments?
b
Redis, in some cases
Ideally, avoiding distributed locks is best if possible šŸ™‚
In some other projects, I use Couchbase, which has some different strategies for ensuring consistency for shared data • via actual locking on the resource • via CAS (compare and swap) semantics
In your case, I'm not clear if you mean locking data across servers, or if you mean just single-threading code like how cflock works
e
I've gotten away without them for this long. I started writing a wrapper for https://github.com/awslabs/amazon-dynamodb-lock-client
cflock for clusters
šŸ‘ 2
single threading a very busy api
b
Got it. And I would encourage you to ask yourself whether it's absolutely necessary to lock. Locking is the enemy of throughput in a concurrent environment!
Sometimes there are ways to work around it, depending on what you're locking, and for what reason.
e
Its not for overuse. just a specific sync operation that has a race condition about once every 2 years.
b
For example, if rebuilding a cache, rebuild it async while the nodes still serve the outdated version. Then swap the new cache when it's ready, etc
has a race condition about once every 2 years.
Man, how do I get requirements like that?? 😁
e
yeah, its not terrible thing which is why i've revisited this for about 8 years now and never put a plan in place.
šŸ‘ 1
I use dynamoDB streams a lot and just came across that library and it reminded me.
z
Lucee's redis extension has a battle tested distributed lock https://docs.lucee.org/reference/tags/distributedlock.html
l
a
Also using JRedis (but on ACF), we also use setting a flag in a database on some operations which thrash external resources but newer stuff is all jedis
e
Thanks everyone. I'm gonna give some of these a try over the weekend.