Notesdistributed🌱 seedling

Lease

Also: Leader Lease · Lock Lease · Time-Based Lease · TTL Lock · Session

A grant that expires after a fixed time unless renewed. It lets a leader act alone (serve reads locally, hold a lock) for a bounded window, and lets everyone else take over safely once the window has passed.

Why it exists

A lock or leadership that never expires dies with its holder. Confirming leadership with a majority on every read costs a round trip. A lease bounds both: it frees itself after a crash, and it lets the holder skip coordination while valid.

How it works

  • A majority (or a coordination service) grants the lease for a duration, say 10 s; heartbeats renew it.
  • While valid, the holder serves reads or does work alone; others promise not to elect or grant to anyone else.
  • When the holder goes silent, others wait out the remaining lease (plus a margin) before taking over.
  • Safety assumes bounded clock drift (rates, not synchronized time) and that the holder doesn't pause past expiry.
  • Coordination services expose leases as TTL keys (etcd) or sessions with ephemeral nodes (ZooKeeper).

Trade-offs

Gains Costs
reads without a quorum round trip failover waits for the old lease to expire
crashed holders release automatically depends on clocks and no long pauses
short leases: fast takeover short leases: more renewals, more false expiries

In practice

  • DynamoDB: a new partition leader won't serve writes or consistent reads until the previous leader's lease expires, "only a couple of seconds", but unavailable all the same.
  • Chubby: master lease of a few seconds; default client lease 12 s.
  • Jepsen etcd 3.4.3 (2020): lease-based locks let two holders act at once even in healthy clusters.

Pitfalls

  • Checking "do I still hold the lease?" then acting: a Process Pause can fall between the check and the action. The resource must check a Fencing Token.
  • Measuring lease time with the wall clock instead of a monotonic clock.

Recall

These cards are also in your review deck, scheduled with spaced repetition.