LE

leader-election

Implement leader election to ensure only one instance executes scheduled tasks.

Install

mkdir -p .claude/skills/leader-election && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/6980" && unzip -o skill.zip -d .claude/skills/leader-election && rm skill.zip

Installs to .claude/skills/leader-election

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Elect a single leader among multiple instances. Only one instance runs cron jobs or processes queues. Automatic failover when leader dies.
138 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Elect a single leader among multiple service instances
  • Coordinate distributed workers or queue consumers
  • Execute automatic failover when a leader stops sending heartbeats
  • Manage leadership state via database heartbeats

How it works

Instances compete to become the leader by updating a shared database table; the leader maintains its status by sending periodic heartbeats, and followers take over if the heartbeat times out.

Inputs & outputs

You give it
Service name and unique candidate ID
You get back
Leadership status and automated failover management

When to use leader-election

  • Ensure exclusive cron job execution
  • Manage distributed task queues
  • Failover for background processing

About leader-election

Manages a distributed lock or election mechanism to assign a single leader among multiple service instances. Supports automatic failover.

Elect a single leader among multiple instances. Only one instance runs cron jobs or processes queues. Automatic failover when leader dies.

When not to use it

  • When instances share the same candidate ID
  • When the heartbeat interval is not significantly shorter than the timeout

Prerequisites

Database connectivityPostgreSQL-compatible database for leader_election table

Limitations

  • Requires a database to store election state
  • Requires explicit handling of SIGTERM for graceful shutdown

How it compares

This approach uses atomic database operations to manage distributed state rather than relying on manual coordination or external locking services.

Compared to similar skills

leader-election side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
leader-election (this skill)16moReviewIntermediate
applescript288moReviewAdvanced
bazel-build-optimization142moNo flagsAdvanced
home-assistant-manager98moReviewAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry