Software Engineering Glossary

Lease

Also known as: Time Bound Lease Lock with TTL

A lease is a grant that gives one node exclusive access to a resource for a fixed amount of time, called the TTL. The holder has to keep refreshing the lease with heartbeats before it runs out. If it crashes, freezes, or loses the network, the lease expires on its own and someone else can take over.

Key Takeaways

  • A lease is a lock with an expiry. The TTL is what makes locking safe when holders can crash or freeze without notice.
  • Always pair a lease with a fencing token. Without it, a frozen holder can wake up after the lease has been reassigned and corrupt the resource.
  • Leases need a strongly consistent store like etcd, ZooKeeper, or Chubby. Using Redis or another best effort store risks split brain.
  • A short TTL gives faster failover but more renewal traffic. A long TTL is cheaper but recovers slower.

How It Works

  1. A client asks the lease service for a lease on a resource with a chosen TTL.
  2. The service stores a record with the holder id, the TTL, and a fencing token that always goes up.
  3. The holder sends a heartbeat every so often to push the expiry forward.
  4. If the heartbeats stop, the lease expires and another node can grab it with a higher fencing token.

Where It Is Used

  • Kubernetes uses Lease objects for kubelet liveness and for controller manager leader election.
  • etcd’s Grant and KeepAlive APIs are the basis of distributed locks, leader election, and service discovery in many cloud systems.
  • HDFS uses leases to make sure only one client can write to a file at a time.