PRO

Effect Leader Lease Election

Leader election that recovers from a dead leader and fences a zombie one. A plain lock leader that crashes without releasing holds the role forever; a time-bounded lease expires unless renewed, so a dead leader's grip lapses and a follower wins the next election with no human. A leader that pauses past its lease (GC, VM freeze) and resumes must not act on stale authority: every lease carries a monotonic fencing token, and the protected resource rejects any write stamped below the highest token it has seen. The demo elects one leader from a contested lease, hands off after a lapse, and fences a thawed zombie's overwrite. Pinned to effect 4.0.0-beta.98.

Install
npx shadcn@latest add https://ui.aryank.space/r/effect-leader-lease-election.json

Installs from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.

Visualization
guard
zombie write
Effect<void, never>
resource owner
a
resource.write(staleValue) // no token check

The old leader froze past its lease, node-b took over, then node-a thawed and wrote with stale authority. Without a fencing token the resource accepts it, rolling the value backward.

Files

Dependencies