Try
↑ ↓ move↵ openesc close

Interview prep / Locks, leases and fencing

Junior · Locks, leases and fencing · System design interview question

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

Learn it by running it

The locks, leases and fencing lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms