Welcome to Grind Engineer , your guide to becoming a better engineer!
No fluff. Pure engineering insights.

The Future Today: From the president of OpenAI to the CEO of Google, we talk to the actual people changing the world with AI. And then we put all of their insights, advice, and business ingenuity into our newsletter. Join 75K Readers →

Your employees are connecting AI to everything. Now what?

ChatGPT and Claude aren't just answering questions. Employees are connecting them directly to Notion, Linear, Jira, and the rest of your stack — with no security visibility into what data moves or what actions they take.

Harmonic Security gives your team the visibility to control it.

Global hiring doesn't come with a playbook. Join Oyster's webinars and events to learn how leading companies are hiring, expanding, and staying compliant across borders.

Every Kubernetes cluster you've deployed runs a hidden election. Every 3 to 5 seconds, nodes inside etcd exchange heartbeats to confirm: "Yes, you're still the boss." The moment those heartbeats stop, an election kicks off in under 300 milliseconds. Your pods keep running because a consensus algorithm settled a leadership dispute before you noticed.

That algorithm is called Raft. Before Raft existed, the only real option was Paxos, an algorithm so hard to understand that its creator, Leslie Lamport, had to publish a follow up paper titled "Paxos Made Simple" because nobody could parse the original.

Why do distributed systems need a leader, what goes wrong without one, and how do Raft and Paxos actually work once you strip the academic jargon?

TL;DR: Leader election picks one node as the single authority in a distributed cluster. Raft uses a leader/follower model with randomized timeouts. Paxos uses a proposer/acceptor two phase protocol. Both prevent split brain through quorum voting.

Why a Cluster Needs a Boss

Imagine 5 database replicas accepting writes simultaneously. Client A writes balance = 500 to Node 1. Client B writes balance = 0 to Node 3. Same key, different values, no coordination. Which one wins?

Nobody knows. And that's the problem.

A leader (sometimes called a primary) is the single node that serializes all writes. Every write goes through the leader first, then gets replicated to followers in order. One authority, one sequence, no conflicts.

etcd does this for Kubernetes. ZooKeeper did it for Hadoop and Kafka. Google Chubby does it across Google's entire infrastructure.

But picking a leader creates a new problem: what happens when the leader dies?

Split Brain: The Silent Data Killer

When a network partition splits a cluster into two groups, both sides might think the leader is gone. Both sides elect their own leader. Now you have two leaders accepting writes independently.

This is called split brain, and it's one of the nastiest failure modes in distributed systems. Why? Because it doesn't crash. It doesn't throw errors. Both partitions happily accept writes while data silently diverges. You discover the damage weeks later when someone notices that Order #4821 shows "shipped" on one replica and "cancelled" on another.

The fix is brutal in its simplicity: quorum voting. You need a strict majority (more than half the nodes) to elect a leader. In a 5 node cluster, you need at least 3 votes. Since both sides of a partition can't both have a majority, only one side can elect a leader. The other side goes read only or stops entirely.

💡 Key Insight: Quorum based voting (requiring n/2 + 1 nodes to agree) is what makes split brain mathematically impossible. It's the single most important idea in distributed consensus, and every algorithm from Paxos to Raft to ZAB relies on it.

This is also why production clusters use odd numbers: 3, 5, or 7 nodes. A 4 node cluster can only tolerate 1 failure (needs 3 for quorum). A 5 node cluster can also tolerate 2 failures (needs 3 for quorum). Same fault tolerance, fewer machines.

How Raft Actually Works

Diego Ongaro and John Ousterhout published Raft in 2014 at Stanford. The paper's title says everything about their motivation: "In Search of an Understandable Consensus Algorithm."

They weren't trying to invent something new. They were trying to make Paxos understandable. And they succeeded. In a study of 43 students across two universities, 33 answered Raft questions better than Paxos questions after learning both.

Raft breaks consensus into three clean subproblems: leader election, log replication, and safety. Here's how the election works.

Every node starts in one of three states: Follower, Candidate, or Leader.

Followers are passive. They do nothing except listen for heartbeats from the current leader and respond to vote requests. If a follower doesn't hear from the leader within a randomized election timeout (typically 150 to 300 ms), it assumes the leader is dead.

That follower then promotes itself to Candidate. It increments a counter called the term (a logical clock that increases with every election), votes for itself, and broadcasts a "vote for me" request to every other node.

If the candidate gets votes from a majority, it becomes the Leader. The new leader immediately starts sending heartbeats to all followers, resetting their election timers. As long as heartbeats keep flowing, no new election happens.

The randomized timeout is what makes this work in practice. If every node had the same timeout, they'd all become candidates at the same time, split the vote, and nobody would win. Randomization means one node almost always times out first and wins cleanly.

One rule that separates Raft from Paxos: only a node with an up to date log can become leader. Raft bakes safety directly into the election. Paxos allows any node to become leader and then catch up afterward.

How Paxos Actually Works

Leslie Lamport described Paxos in 1989 using a metaphor about legislators on a fictional Greek island. The metaphor was so confusing that the paper wasn't published until 1998, and even then, Lamport had to write "Paxos Made Simple" in 2001 because practitioners still couldn't implement it.

Paxos uses three roles: Proposers, Acceptors, and Learners. In practice, a single node often plays all three roles, but understanding them separately makes the protocol click.

The protocol runs in two phases.

Phase 1 (Prepare): A Proposer picks a proposal number and sends a "prepare" message to a majority of Acceptors. Each Acceptor promises not to accept any proposal with a lower number. If the Acceptor already accepted a previous value, it sends that value back.

Phase 2 (Accept): If the Proposer gets promises from a majority, it sends an "accept" message with the actual value. Acceptors accept it if they haven't made a newer promise in the meantime. Once a majority accepts, the value is chosen. Learners then discover the decided value.

Basic Paxos has no dedicated leader. Any node can be a Proposer at any time. Sounds flexible, but it creates a livelock problem: two Proposers can keep outbidding each other's proposal numbers forever, and nothing ever gets decided.

That's why production systems use Multi Paxos, which elects a stable leader Proposer so Phase 1 only runs once. After that, the leader can skip straight to Phase 2 for every subsequent value. Multi Paxos ends up looking a lot like Raft, which begs the obvious question: why bother with Paxos at all?

The Head to Head Comparison

Dimension

Raft

Paxos

Created

2014 by Ongaro & Ousterhout

1989 by Leslie Lamport

Mental model

One leader, clear hierarchy

Parliament: propose, debate, decide

Leader requirement

Always has a single leader

No leader in basic Paxos, leader in Multi Paxos

Election mechanism

Randomized timeouts + majority vote

Proposal numbers + two phase protocol

Who can become leader

Only nodes with up to date logs

Any node (catches up after election)

Understandability

High (designed for it)

Low (notoriously hard)

Used by

etcd, Consul, CockroachDB, TiDB, Kafka KRaft

Google Spanner, Google Chubby, DynamoDB

Open source implementations

~100+

Fewer, harder to get right

The throughput difference in normal operation is negligible. Both algorithms bottleneck on disk sync and network round trips, not on the consensus logic itself. The real difference is in how easy they are to implement correctly and debug when things go wrong.

Leader Failure and Recovery

Say you have a 5 node Raft cluster and the leader crashes.

The remaining 4 followers are still listening for heartbeats. Each has a randomized election timeout. Node 3 happens to timeout first (say, after 200ms). It becomes a Candidate, increments the term, and asks the other 3 for votes.

Nodes 2, 4, and 5 haven't voted this term yet, and Node 3's log is up to date. They grant their votes. Node 3 becomes the new leader with 4 votes (including its own). The whole process takes roughly one election timeout period.

During this window (a few hundred milliseconds), the cluster cannot process writes. Reads might still work from followers depending on consistency settings. Once the new leader is established, writes resume.

If the old leader comes back online, it discovers the new term number, realizes it's been deposed, and demotes itself to follower. The term number is the tiebreaker, and the transition is automatic.

The Leaderless Alternative

Not every system needs leader election. Amazon's original Dynamo paper (2007) popularized leaderless replication, where any node can accept writes and conflicts are resolved later using techniques like vector clocks and last writer wins.

Cassandra adopted this model. So did Riak. The trade off: higher availability (no election downtime, no single point of failure) but weaker consistency (conflicting writes happen and must be resolved).

DynamoDB (the AWS managed service inspired by the Dynamo paper) actually moved away from leaderless replication. AWS switched DynamoDB to Multi Paxos with a single leader per partition because they wanted to offer strong consistency. The original leaderless design made strong consistency too expensive to guarantee.

When consistency matters, most teams end up choosing a leader.

The Decision Framework

  1. If you're building on Kubernetes, you're already using Raft. etcd runs Raft under the hood. Understanding Raft helps you debug cluster issues, reason about etcd quorum loss, and size your control plane correctly.

  2. If you're choosing a consensus algorithm for a new system, pick Raft. With ~100 open source implementations and a track record in CockroachDB, TiDB, and Consul, it's the safe bet. Paxos is more flexible in theory, but that flexibility buys you complexity most teams don't need.

  3. If you truly don't need strong consistency (caching layers, analytics pipelines, content delivery), skip leader election entirely. Leaderless replication or eventual consistency will serve you better with less operational overhead.

Sources

→ Find me on : Social Links

That’s it for today, keep learning!
Scortier, Signing Off!

Reply

Avatar

or to participate