Leases and leader election
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
explain time-limited ownership.
Planned topics
- A lease is a lock that expires automatically unless renewed, so a dead holder cannot block forever.
- Leader election: instances compete; one wins a lease and acts, others stand by.
- Renew before expiry; if renewal fails, stop acting immediately.
- Clocks and pauses matter: the holder may not notice its lease expired.
- Real consensus (Raft, ZooKeeper, etcd) gives stronger guarantees than a plain database row.
Draft outline details
Demonstration
UPDATE lease SET holder = :me, expires_at = now() + interval '30 seconds'
WHERE name = 'nightly' AND (holder = :me OR expires_at < now());
-- 1 row updated = you hold the leaseCheck your understanding
Why do leases expire?
Show answer
So a crashed holder does not block everyone forever.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.