Distributed locking powered by DynamoDB


Distributed locking is not a new topic on our blog. Over time, we have presented two other solutions to this problem based on AWS SWF (here) or using Redis from ElastiCache (here).

To generalize, any solution to this problem has the same approach: a persistent storage that supports conditional writes plus a mechanism to solve zombie locks when the owner thread/node has died until releasing the lock.The AWS world

Now, coming back into AWS world, we want to discuss about a library built on top of DynamoDB to solve this problem. It’s important to say this library is developed and maintain by AWS team. (link here). We used this library in a service we developed and below are some conclusions:

  • It’s easier to integrate comparing to SWF, because it’s just a dependency and the whole headache caused by Flow Framework and AOP dependencies
  • The library offers many options and it’s pretty easy to use
  • The documentation provided on Github is not great. First of all, version 1.2.0 doesn’t exist in Maven; we lost some time until we realized that. Also, the example provided there is far from compiling, With some reverse engineering, you’ll be able to build the correct dependencies needed to create the locking client.
  • If you don’t use Redis, we believe it doesn’t worth adding a dependency on Redis, so again, we encourage you to choose DynamoDB.
  • It is worth appreciating that the library comes with some helper methods. One example is that one for creating the DynamoDB table used for locking. Make sure you use that one once, otherwise you’ll get an exception reporting table already exists.

We presented our outcomes about this library. Since it has a pretty good documentation we won’t provide any code sample. This blog post comes with more technical details you should read.

As usual, your feedback is welcome and we love to read it.

Happy cloud computing!