Leases
A lease represents ownership with a limited lifetime.
It allows a client to control a resource safely, even in the presence of failures.
The Core Ideaβ
A lease provides:
Exclusive ownership + automatic expiration
- Ownership ensures only one client controls a resource
- Expiration ensures the system recovers if the owner fails
Why Leases Existβ
In distributed systems:
- Processes can crash
- Machines can go down
- Network connections can be lost
Without leases:
- Resources may remain locked forever
- Systems can become inconsistent
Leases solve this by introducing time-bound ownership.
How a Lease Worksβ
A lease follows a lifecycle:
Acquire β Active β Renew (optional) β Expire β Released
1. Acquireβ
- A client acquires a lease for a duration
- The lease becomes active immediately
2. Activeβ
- The client owns the lease
- It can safely perform operations
3. Renew (Optional)β
- The client can extend the lease before expiration
- This resets the expiration timer
4. Expireβ
- If not renewed, the lease expires automatically
- Ownership is released
5. Releasedβ
- Other clients can acquire the lease
Example Scenarioβ
A background worker processes jobs:
- Worker A acquires a lease
- It processes tasks
- If Worker A crashes, the lease expires
- Worker B takes over
No manual cleanup is required.
Binding Keys to Leasesβ
Keys can be associated with a lease.
- The key exists only while the lease is active
- When the lease expires, associated keys are cleaned up automatically
This is useful for:
- Temporary ownership
- Resource tracking
- Distributed coordination
Failure & Expiry Behaviorβ
Leases are designed to handle failure safely:
- If a client crashes β lease expires
- If a network is lost β lease expires
- If renewal stops β lease expires
The system guarantees that:
- Ownership is eventually released
- No stale ownership remains
Lease vs Lockβ
Leases are similar to locks, but safer:
- Lock β ownership until explicitly released
- Lease β ownership with automatic expiry
This prevents deadlocks caused by failures.
Key Characteristicsβ
- Time-bound ownership
- Automatic cleanup
- Exclusive access
- Distributed-safe behavior
Why Leases Matterβ
Leases allow you to build systems that are:
- Reliable
- Self-healing
- Safe under failure
They are a foundational primitive for coordination.
Whatβs Nextβ
π Continue to Coordination Model to see how leases enable locks, counters, and watch