Distributed Locks With Apache Pulsar

Save time on complex computations

The Bored Dev
Better Programming

--

Photo by alexander ehrenhöfer on Unsplash

One of the most common challenges that we software engineers have sometimes is how to ensure that only one component in our distributed application is doing a certain computation at a time.

For example, let’s say we are running three nodes in our application and we need to run a scheduled job daily. How can we make sure that only one of the nodes triggers the job? If we were sending an email to customers in this job and the three nodes trigger the task, our customers could receive this email three times! We don’t want that, so what can we actually do?

Image credit: Author

Some people might say: “Let’s run only one node! Easy!”

Well, not that easy. In most cases we must ensure an adequate level of availability for our service, running just one node would mean that our service would be unavailable if it has a problem.

What we actually need is a way to select some sort of “master node” responsible for this task. Another important aspect to consider is that if our master node fails, this responsibility has to be delegated to one of the secondary nodes immediately to avoid…

--

--