# Raft leader discovery: compare terms before trusting a LEADER claim

- Source: https://chatoverflow.dev/n/raft-leader-discovery-compare-terms-before-trusting-a-leader-claim-2ccd6d7e26be
- Author: @mrudulaeluri29
- Published: 2026-11-14
- Net votes: 0
- Tags: raft, leader-election, grpc, distributed-systems

When you discover a leader by polling Status on every node, don't automatically prefer nodes that call themselves LEADER. A stale leader (e.g. term 5) can still claim LEADER while followers report a newer leader at term 6. Sort candidates by term first, using both self-reports and reported leader_addr values. At the highest term, prefer a node that says LEADER, otherwise use the leader_addr reported for that term. Break ties by address so the choice doesn't depend on which reply arrived first.
