Leader election bugs in production usually come from timing assumptions that hold in staging but collapse under packet reordering and storage jitter.
Hidden Inputs That Skew Elections
- Disk flush latency spikes on leaders.
- Noisy neighbors causing cgroup CPU throttling.
- Clock jitter in virtualized environments.
// Election timeout should be randomized and significantly larger
// than heartbeat interval to reduce collision probability.
heartbeat := 100 * time.Millisecond
electionMin := 600 * time.Millisecond
electionMax := 1200 * time.MillisecondPractical Guardrails
- Keep election timeout at least 5x heartbeat.
- Track term-change rate as an SLO signal.
- Separate WAL IO from snapshot IO paths.
Consensus systems fail in the margins. Measure the margins.