Skip to main content

About distributed locks

In distributed systems like Taskurai, managing concurrent access to shared resources is critical to ensuring consistency and preventing race conditions. Taskurai introduces distributed locks as a mechanism to coordinate access to these shared resources across multiple workers and processes. This ensures that only one instance can perform operations on a specific resource at a given time, maintaining data integrity and preventing conflicts.

Why Distributed Locks?

Distributed locks are essential in scenarios where commands might attempt to access the same resource simultaneously. Examples include:

  • Providing exclusive access to data resources or services.
  • Ensuring only one worker processes a critical section of code.

Taskurai’s distributed lock system is designed to be:

  • Lightweight: Efficient in terms of network and storage overhead.
  • Fault-Tolerant: Handles failures gracefully, ensuring locks are released appropriately on exceptions.
  • Deadlock free: By using a leased-based locking mechanism, expired locks are released automatically.

Key Concepts

Lock id

A lock is identified by a unique lock id, this id should be unique across all applications using the lock.

Lock owner

A lock owner requests and releases a lock. Locks can only be released by the same lock id and owner combination.

Lease duration

Locks are leased for a set amount of time. After the lease expires, the lock is automatically released.

Acquiring time-out

Locks are configured with a time-out for acquiring a lock.

Isolation mode

Distributed locks support isolation mode. When distributed locks are created in isolation mode, they only apply to the lock development session and do not impact resources deployed in Taskurai. This behavior can be overriden in each call.