What is a lease, and why do distributed locks use leases instead of locks that last until released?
Sketch your own answer first, then compare it with the one below.
A strong answer
A lease is a lock with an expiry. The holder gets the right to act for a fixed time, after which the right is gone unless it was renewed. A plain lock that lasts until released is a problem the moment the holder crashes: nobody can release it, and everyone waits forever.
With a lease, a crashed holder's lock frees itself when the lease runs out. The cost is a window: a holder that is alive but slow can lose the lease without noticing, and then act as if it still held it.
The trade is lease length. Short leases recover fast from a crash and go stale under short pauses. Long leases survive pauses and make everyone wait after a crash. Both are failure modes. The length chooses between them rather than removing either.
Sources
- Cary G. Gray, David R. Cheriton (1989). Leases, an efficient fault-tolerant mechanism for distributed file cache consistency.