Table of Contents

Motivation

Locks, mutexes, semaphores, monitors are usually associated with concurrent programming. But exclusive resource access is also needed in distributed environments, e.g. when using a micro-service architecture.

Locking service

When having multiple instances of a service, it needs to be ensured that the action is performed only by one instance. A leader will be elected, and failure needs to be detected and dealt with. Consensus algorithm like Paxos exist. A separate locking service could be build, which is able to manage locks. The service needs a strongly consistent datastore, which holds information about the lock (who holds it, how long) and there needs to be logic to deal with failures.

Implementations