Skip to content
Ameen Abozaid
Planned lessonMID-032-L02

Leases and leader election

  • Lesson 2 of 5
  • Mid-level
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

sql
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 lease

Check 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.