Problem
A plain lock held by a crashed or partitioned client is never released, blocking everyone. Detecting a dead holder perfectly is impossible in asynchronous networks. The system needs automatic recovery of abandoned locks.
Also known as: leases, time-bounded-locks, ttl-locks
Grant exclusive access for a bounded time so that a crashed holder cannot block others forever.
A plain lock held by a crashed or partitioned client is never released, blocking everyone. Detecting a dead holder perfectly is impossible in asynchronous networks. The system needs automatic recovery of abandoned locks.
A lease is a lock with an expiry. The holder owns the resource only while the lease is valid and must keep renewing it. If it dies or is partitioned away, the lease lapses and the lock becomes available again. Google Chubby, etcd and Kubernetes leader election use leases.
t=0 acquire(lock, ttl=15s) -> lease granted, id=L1
t=5 renew(L1) -> expires at t=20
t=10 holder crashes
t=20 lease expires
t=21 other client acquires -> lease L2
A typical implementation renews at one third of the TTL, so two missed heartbeats are tolerated. In a database-backed form, a row holds owner and expiry, and acquire is a conditional update: set owner when expiry is in the past or owner is self. The holder should stop work if it has not renewed within the TTL minus a safety margin.
Lock store such as etcd or a database table
Low: tune TTL and renewals
Medium: timing reasoning
Process pause longer than TTL leads to two holders
Renewal failure during transient network blip drops leadership needlessly
Clock skew shortens or extends effective lease