Leases & Fences— Distributed Design Patterns

--

Ensuring consistency of critical data for which we want to have exclusive access, can be achieved through locking. However, in a distributed setup, we can run into scenarios where because of a network partition, process pauses or nodes go down. This leads to the resources being locked indefinitely!

Leases

To overcome the above problem, we make use of leases.

Leases are time-bound locks, where the locks are automatically released by the system managing them after a timeout.

When a client obtains a lease on a particular resource, the distributed system guarantees that during the tenure of the lease, no other client will be able to make modifications to the resource. The client holding the lease to a resource can also choose to renew the lease on the resource, thereby extending the timeout on the lease. The timeout on the lease is generally tracked by TTL(Time to Live) when the lease is first obtained on a particular resource.

The tradeoff with choosing the lease term

We know that we need to create time-bound leases, but what’s the right timeout that we should choose and what's the impact of setting a short timeout vs a long one?

Short Term Vs Long Term Lease

Clocks & Leases

--

--

Pratik Pandey - https://pratikpandey.substack.com
Nerd For Tech

Senior Engineer with experience in designing and architecting large scale distributed systems.