Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav — full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with ❤️ & By - Anubhav

© 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 05 · Distributed Systems & ConsensusChapter 28 of 33
27.
Phase 05Read time ~24 minDifficulty advanced

Distributed Coordination

In this chapter
  • 01Chapter Overview
  • 02Why Coordination Is Needed
  • 03Common Coordination Problems
  • 04Why Coordination Is Hard
  • 05Failure Detection
  • 06Heartbeats
  • 07Health Checks vs Heartbeats
  • 08Leader Election
  • 09Why Leader Election Is Needed
  • 10Split Brain
  • 11Why "I'm Leader" Is Not Enough
  • 12Leader Epochs / Terms
  • 13Fencing Tokens
  • 14Distributed Locks
  • 15Local Lock vs Distributed Lock
  • 16Local
  • 17Distributed
  • 18Lock Expiration
  • 19The Lease Problem
  • 20Fencing Solves the Stale Worker Problem
  • 21Lease Renewal
  • 22Leader Election and Consensus
  • 23What Consensus Is Trying to Achieve
  • 24Quorum
  • 25Why Majority Matters
  • 26What Happens With a 2/5 Split?
  • 27Availability During Partition
  • 28Raft
  • 29Raft Leader Election
  • 30Raft Terms
  • 31Raft Log Replication
  • 32State Machine Replication
  • 33Consensus Is Not the Same as Replication
  • 34Paxos
  • 35Raft vs Paxos
  • 36Coordination Services
  • 37ZooKeeper-Style Coordination
  • 38Ephemeral Membership
  • 39Service Discovery
  • 40Service Discovery Failure
  • 41Distributed Configuration
  • 42Membership
  • 43Failure Detector Trade-off
  • 44Clock Problems
  • 45Logical Clocks
  • 46Lamport Clock Intuition
  • 47Vector Clocks
  • 48Leader Lease vs Consensus
  • 49Common Coordination Failure
  • 50Preventing Split Brain
  • 51Coordination Pattern: Single Writer
  • 52Coordination Pattern: Sharded Leadership
  • 53Coordination and Rebalancing
  • 54Coordination in Distributed Scheduling
  • 55Coordination in Kubernetes
  • 56Coordination in Databases
  • 57Safety vs Liveness
  • 58Safety
  • 59Liveness
  • 60Example: Leader Election
  • 61Common Misconception #1
  • 62Wrong
  • 63Correct
  • 64Common Misconception #2
  • 65Wrong
  • 66Common Misconception #3
  • 67Wrong
  • 68Common Misconception #4
  • 69Wrong
  • 70Common Misconception #5
  • 71Wrong
  • 72Interview Question: Why Is Leader Election Hard?
  • 73Answer
  • 74Interview Question: What Is Split Brain?
  • 75Answer
  • 76Interview Question: What Is a Fencing Token?
  • 77Answer
  • 78Interview Question: Why Do We Need Quorum?
  • 79Answer
  • 80Interview Question: Raft vs Paxos
  • 81Interview Question: What Happens When a Leader Dies?
  • 82Mini Project
  • 83Build a Distributed Job Scheduler Design
  • 84Advanced Coordination Challenge
  • 85Production Coordination Checklist
  • 86Master Mental Model
  • 87Summary
  • 88Exercises
  • 89Exercise 1
  • 90Exercise 2
  • 91Exercise 3
  • 92Exercise 4
  • 93Exercise 5
  • 94Exercise 6
  • 95Exercise 7
  • 96Next Chapter
  • 97Chapter 27 — High Availability
In this chapter (97 sections)
01Chapter Overview02Why Coordination Is Needed03Common Coordination Problems04Why Coordination Is Hard05Failure Detection06Heartbeats07Health Checks vs Heartbeats08Leader Election09Why Leader Election Is Needed10Split Brain11Why "I'm Leader" Is Not Enough12Leader Epochs / Terms13Fencing Tokens14Distributed Locks15Local Lock vs Distributed Lock16Local17Distributed18Lock Expiration19The Lease Problem20Fencing Solves the Stale Worker Problem21Lease Renewal22Leader Election and Consensus23What Consensus Is Trying to Achieve24Quorum25Why Majority Matters26What Happens With a 2/5 Split?27Availability During Partition28Raft29Raft Leader Election30Raft Terms31Raft Log Replication32State Machine Replication33Consensus Is Not the Same as Replication34Paxos35Raft vs Paxos36Coordination Services37ZooKeeper-Style Coordination38Ephemeral Membership39Service Discovery40Service Discovery Failure41Distributed Configuration42Membership43Failure Detector Trade-off44Clock Problems45Logical Clocks46Lamport Clock Intuition47Vector Clocks48Leader Lease vs Consensus49Common Coordination Failure50Preventing Split Brain51Coordination Pattern: Single Writer52Coordination Pattern: Sharded Leadership53Coordination and Rebalancing54Coordination in Distributed Scheduling55Coordination in Kubernetes56Coordination in Databases57Safety vs Liveness58Safety59Liveness60Example: Leader Election61Common Misconception #162Wrong63Correct64Common Misconception #265Wrong66Common Misconception #367Wrong68Common Misconception #469Wrong70Common Misconception #571Wrong72Interview Question: Why Is Leader Election Hard?73Answer74Interview Question: What Is Split Brain?75Answer76Interview Question: What Is a Fencing Token?77Answer78Interview Question: Why Do We Need Quorum?79Answer80Interview Question: Raft vs Paxos81Interview Question: What Happens When a Leader Dies?82Mini Project83Build a Distributed Job Scheduler Design84Advanced Coordination Challenge85Production Coordination Checklist86Master Mental Model87Summary88Exercises89Exercise 190Exercise 291Exercise 392Exercise 493Exercise 594Exercise 695Exercise 796Next Chapter97Chapter 27 — High Availability

1. Chapter Overview#

Distributed systems contain multiple machines that must sometimes agree on:

  • who is the leader
  • who owns a lock
  • which configuration is current
  • which nodes are alive
  • which operation should happen next
  • which state is authoritative

This is the problem of distributed coordination.

A simple application can often make decisions inside one process:

Application
    │
    └── one memory space

A distributed system looks like:

Node A
Node B
Node C
Node D

Now there is no single shared memory space and no perfectly reliable communication channel.

Coordination becomes difficult because:

A node cannot always distinguish a crashed node from a slow node or a broken network connection.

This chapter develops the concepts needed to reason about coordination safely.


2. Why Coordination Is Needed#

Imagine a scheduled job:

Every minute:
generate daily report

You have 10 application instances:

A
B
C
D
E
F
G
H
I
J

If every instance executes the job:

10 reports

may be generated instead of:

1 report

You need coordination:

              Coordinator
              /    |    \
             /     |     \
            A      B      C
                  ...

Only one worker should own the task at a time.


3. Common Coordination Problems#

Distributed coordination appears in:

  • leader election
  • distributed locks
  • job scheduling
  • service discovery
  • cluster membership
  • configuration management
  • failover
  • metadata management
  • shard ownership
  • primary selection
  • database coordination
  • consensus

4. Why Coordination Is Hard#

Consider two servers:

A ───────── B

A sends:

Are you alive?

No response.

What does that mean?

Possibilities:

1. B crashed
2. B is overloaded
3. Network is slow
4. Network path is broken
5. B received the message but response was lost
6. B is alive but cannot communicate

A cannot know the exact reason from silence alone.

This is one of the fundamental difficulties of distributed systems.


5. Failure Detection#

A distributed system often uses:

  • heartbeats
  • timeouts
  • health checks
  • leases
  • membership protocols

Example:

A ── heartbeat ──► B
A ◄─ heartbeat ── B

If heartbeats stop:

timeout
   ↓
suspect B

Notice the wording:

suspect

not:

prove that B crashed

Failure detection is often based on incomplete information.


6. Heartbeats#

A heartbeat is a periodic signal indicating that a node is alive.

Example:

Every 5 seconds:
 
Node A → coordinator:
"I'm alive"

If the coordinator does not receive heartbeats:

5 sec
10 sec
15 sec
      ↓
Node A suspected unavailable

Heartbeat frequency is a trade-off.

Too frequent:

More network traffic
More processing

Too infrequent:

Slow failure detection

7. Health Checks vs Heartbeats#

A heartbeat usually answers:

Is the process communicating?

A health check can answer something more meaningful:

Is the application healthy enough to receive traffic?

For example:

Process alive ✓
Database connection ✗
Disk full ✗
Dependency unavailable ✗

A process can be alive but not healthy.

Therefore production systems often distinguish:

  • liveness
  • readiness
  • health
  • dependency health

8. Leader Election#

A common coordination problem is:

Which node is the leader?

Example:

Node A
Node B
Node C

The system needs:

Leader = A

Other nodes become followers.

        Leader A
        /      \
       B        C

The leader may coordinate:

  • writes
  • scheduling
  • metadata
  • shard ownership
  • replication
  • cluster state

9. Why Leader Election Is Needed#

Suppose the leader crashes:

Leader A ✗
 
B
C

The system needs another leader:

       Leader B
       /      \
      A        C

Without a safe election mechanism, multiple nodes may believe they are leader.

That creates split brain.


10. Split Brain#

Split brain occurs when different parts of a distributed system independently believe they are authoritative.

Example:

      Network Partition
 
   A                 B
   │                 │
   │                 │
"I am leader"    "I am leader"

Now:

Client 1 → A
Client 2 → B

Both leaders may accept conflicting writes.

This can corrupt state.


11. Why "I'm Leader" Is Not Enough#

Suppose:

Node A
term = 10
leader = true

Network partition occurs.

A continues running.

Meanwhile:

Node B + C

elect B as the new leader:

term = 11

A may still think:

"I am leader."

Therefore leadership must be associated with a mechanism that lets the system reject stale leaders.

This leads to terms, epochs, leases, and fencing tokens.


12. Leader Epochs / Terms#

A leader can have a monotonically increasing term:

Leader A
term = 10

New election:

Leader B
term = 11

Any message from the old leader:

term = 10

can be recognized as stale.

The system can reject it when the current term is:

11

This is a powerful defense against stale leadership.


13. Fencing Tokens#

A fencing token is a monotonically increasing number associated with ownership.

Example:

Worker A:
token = 100
 
Worker B:
token = 101

If B becomes the new owner, downstream storage can require:

token >= current token

Then:

A sends token 100
        ↓
Storage
        ↓
REJECT

while:

B sends token 101
        ↓
Storage
        ↓
ACCEPT

This prevents stale workers from performing dangerous operations.


14. Distributed Locks#

Suppose only one worker should process:

job = 123

A distributed lock can provide:

Worker A
   │
   ▼
LOCK(job:123)
   │
   ▼
Process job

Another worker:

Worker B
   │
   ▼
LOCK(job:123)
   │
   ▼
Rejected / waits

But implementing safe distributed locks is much harder than implementing a local mutex.


15. Local Lock vs Distributed Lock#

Local#

Process
 ┌──────────────┐
 │ Mutex        │
 │ Thread A     │
 │ Thread B     │
 └──────────────┘

One memory space.

Distributed#

Node A ───── Network ───── Node B
        \               /
              Lock

Now failures can happen between acquisition and use.

The lock holder can crash.

The network can partition.

A delayed process can wake up later.

These problems require additional safeguards.


16. Lock Expiration#

A distributed lock often has an expiration:

LOCK
TTL = 30 seconds

If the worker crashes:

30 seconds
    ↓
lock expires
    ↓
another worker can acquire it

This prevents permanently abandoned locks.

But TTL creates a subtle problem.


17. The Lease Problem#

Suppose:

Worker A
lease = 30 seconds

A acquires the lock.

Then A pauses for:

40 seconds

The lease expires.

Worker B acquires the lock:

B = owner

A wakes up.

Now:

A thinks it owns lock
B actually owns lock

Both can execute.

This is why a lease alone may not be sufficient for safety.


18. Fencing Solves the Stale Worker Problem#

Suppose every lock acquisition returns a fencing token.

First:

Worker A
token = 10

Later:

Worker B
token = 11

Storage remembers:

highest token = 11

A wakes up and sends:

WRITE(token=10)

Storage rejects it:

10 < 11

B sends:

WRITE(token=11)

Storage accepts it.

This is much safer than relying only on lock expiration.


19. Lease Renewal#

Long-running workers can renew a lease:

Acquire lease
    ↓
Work
    ↓
Renew
    ↓
Work
    ↓
Renew

If renewal fails:

Stop processing

A robust design should ensure the worker stops making protected writes after losing ownership.


20. Leader Election and Consensus#

Leader election is closely related to consensus.

Consensus means that distributed nodes agree on a value or decision despite failures.

A consensus system typically needs to reason about:

  • proposals
  • votes
  • quorum
  • terms/epochs
  • committed state
  • leader changes
  • failure recovery

Protocols such as:

  • Raft
  • Paxos

are used to solve consensus problems under defined failure assumptions.


21. What Consensus Is Trying to Achieve#

Imagine:

A
B
C

The nodes need to agree:

leader = B

A safe consensus protocol aims to ensure that correct nodes do not permanently commit conflicting decisions.

Conceptually:

Proposal
   ↓
Agreement
   ↓
Commit

The exact mechanics depend on the protocol.


22. Quorum#

A quorum is a sufficient subset of nodes required for a decision.

For:

N = 5

a majority quorum is:

3

because:

3 > 5/2

Two different majorities must overlap.

For example:

Quorum A:
1, 2, 3
 
Quorum B:
3, 4, 5

They overlap at:

Node 3

This overlap is fundamental to many consensus systems.


23. Why Majority Matters#

Suppose a cluster has:

5 nodes

If the system requires:

3 votes

then at most:

2 nodes

can be unavailable while a majority still exists.

A ✓
B ✓
C ✓
D ✗
E ✗

Majority remains:

3

The cluster can continue making decisions if the protocol permits it.


24. What Happens With a 2/5 Split?#

Suppose:

Partition 1:
A
B
 
Partition 2:
C
D
E

Only the side with:

3 nodes

has a majority.

The 2-node side cannot safely commit decisions that require majority agreement.

This prevents both partitions from independently becoming authoritative.


25. Availability During Partition#

This creates an important relationship:

5-node cluster
 
Partition:
2 nodes | 3 nodes

The majority side can potentially continue.

The minority side may need to stop certain operations.

This is a coordination mechanism for avoiding split brain.


26. Raft#

Raft is a consensus algorithm designed to be understandable and practical.

It organizes nodes into roles:

Leader
Follower
Candidate

Normally:

        Leader
       /      \
  Follower  Follower

Clients send writes to the leader.

The leader replicates entries to followers.


27. Raft Leader Election#

If followers stop receiving heartbeats:

Leader
   X

one follower may become a candidate.

It increments its term and requests votes.

Candidate B
   │
   ├──► A: vote?
   └──► C: vote?

If it receives a majority:

B = Leader

This is a simplified view; actual Raft includes detailed rules for terms, logs, voting, and election safety.


28. Raft Terms#

Raft uses monotonically increasing terms.

Example:

Term 5:
Leader A
 
Leader fails
 
Term 6:
Leader B

A message from term 5 can be recognized as older than term 6.

This helps prevent stale leaders from remaining authoritative.


29. Raft Log Replication#

Suppose the leader receives:

SET X = 20

The leader appends a log entry:

Log:
1 → SET X=10
2 → SET X=20

It replicates the entry to followers.

Once the appropriate majority condition is satisfied, the entry can become committed according to Raft's rules.

Followers then apply the committed entry to their state machines.


30. State Machine Replication#

A useful consensus mental model is:

Client command
      ↓
Consensus log
      ↓
Replicated log
      ↓
State machine

Each correct node applies the same committed commands in the same order.

Therefore:

Node A state
Node B state
Node C state

can remain consistent.


31. Consensus Is Not the Same as Replication#

Replication means:

copy data to multiple nodes

Consensus means:

agree on the order/decision

You can have replication without strong consensus.

Consensus protocols combine agreement and replication to maintain a consistent replicated state under specified failures.


32. Paxos#

Paxos is another family of consensus algorithms.

At a high level, Paxos deals with:

  • proposals
  • acceptors
  • proposers
  • values
  • quorums
  • agreement

Paxos is historically important and foundational in distributed systems.

Its descriptions can be difficult to follow, so for practical system-design interviews, it is often more useful to understand:

Why consensus exists
What quorum means
How leaders are elected
How committed state is replicated
What failures are tolerated

before diving into the complete protocol mechanics.


33. Raft vs Paxos#

Aspect Raft Paxos
Goal Consensus Consensus
Teaching Designed for understandability Often more abstract
Leader-based structure Yes Common variants use leadership
Terms/epochs Yes Uses proposal/ballot numbering
Log replication Explicit Multi-Paxos commonly used
Interview value High practical value Important foundational concept

Do not treat one as universally "better."

They are different consensus approaches.


34. Coordination Services#

Many systems use dedicated coordination systems rather than implementing consensus independently inside every application.

Historically/common examples include:

  • ZooKeeper
  • etcd
  • Consul

They can support capabilities such as:

  • leader election
  • distributed configuration
  • service discovery
  • membership
  • watches
  • coordination metadata

The exact features and consistency semantics depend on the system and configuration.


35. ZooKeeper-Style Coordination#

A coordination service can provide a shared namespace:

/config/payment
/config/inventory
/leader/order-service
/locks/job-123

Applications can:

create
read
update
watch

coordination state.

This avoids forcing every application team to implement its own coordination protocol.


36. Ephemeral Membership#

Some coordination systems support ephemeral registrations.

Conceptually:

Node A
   │
   ▼
register /services/api/A

If A disappears or its session expires:

/services/api/A

can disappear automatically.

This can help service discovery and leader election.


37. Service Discovery#

Suppose:

API Gateway

needs to find:

Payment Service

Instead of hard-coding:

10.0.0.5

it can query service discovery:

payment-service
      ↓
10.0.0.5
10.0.0.6
10.0.0.7

The registry tracks service instances.


38. Service Discovery Failure#

What happens if the registry is unavailable?

A good architecture should avoid making every request depend synchronously on the registry.

Possible approaches:

  • local caching
  • DNS
  • sidecars
  • client-side discovery
  • load-balancer discovery
  • stale-but-usable service information

Coordination systems themselves become critical infrastructure and therefore need high availability.


39. Distributed Configuration#

A coordination service can also store configuration:

/config/service-a/database-url
/config/service-a/timeout
/config/service-a/feature-x

Services can watch for changes.

Example:

Configuration updated
        ↓
Watch event
        ↓
Service reloads configuration

Care must be taken with:

  • configuration validation
  • rollout
  • rollback
  • versioning
  • partial updates

40. Membership#

A distributed cluster needs to know:

Who is currently part of the cluster?

Example:

A ✓
B ✓
C ✓
D ✗

Membership systems track nodes and their status.

But again:

"Node D is not responding" does not necessarily prove D is dead.

Membership systems therefore need failure detection rules and timeouts.


41. Failure Detector Trade-off#

Suppose:

heartbeat interval = 5 sec
timeout = 15 sec

A temporary network delay of:

16 sec

could cause a healthy node to be suspected.

If timeout is too short:

false positives ↑

If timeout is too long:

failure detection slows

There is no perfect timeout.


42. Clock Problems#

Distributed coordination also encounters time problems.

Each machine has its own clock:

Node A: 10:00:00.100
Node B: 10:00:00.080
Node C: 10:00:00.130

Clocks can differ due to:

  • clock drift
  • synchronization delays
  • hardware differences
  • operating-system behavior

Therefore wall-clock time should not automatically be treated as a perfect ordering mechanism.


43. Logical Clocks#

Distributed systems can use logical clocks to represent ordering.

Instead of asking:

What physical time did this happen?

we can ask:

What happened before what?

Lamport clocks provide a simple mechanism for representing causal ordering.


44. Lamport Clock Intuition#

Each process maintains:

counter

Before a local event:

counter++

When sending:

send counter

When receiving:

counter = max(local, received) + 1

This creates an ordering relationship.

Important:

A Lamport timestamp can indicate that one event happened before another in the logical ordering, but equal or ordered timestamps alone do not necessarily tell you that two events are causally related in every case.


45. Vector Clocks#

Vector clocks provide more causal information.

For three nodes:

[A, B, C]

Example:

[2, 1, 3]

They can help distinguish:

A happened-before B

from:

A and B are concurrent

The trade-off is additional metadata.


46. Leader Lease vs Consensus#

A lease-based leader mechanism:

Leader
  ↓
lease expires

can be useful, but a lease by itself does not necessarily solve all distributed consistency problems.

Consensus protocols provide stronger agreement mechanisms under defined failure assumptions.

Use the right abstraction for the problem.


47. Common Coordination Failure#

Consider:

Leader A
   │
   X
network partition
   X
   │
Nodes B + C

B and C elect:

Leader B

A still thinks it is leader.

Without fencing/terms/consensus:

A → write
B → write

Both may modify state.

This is split brain.


48. Preventing Split Brain#

Common techniques include:

  • majority quorum
  • leader terms/epochs
  • fencing tokens
  • leases
  • consensus
  • external coordination service

The design should make stale authority harmless.

This is more important than simply detecting that a node is stale.


49. Coordination Pattern: Single Writer#

One way to reduce conflicts:

             Leader
           /   |   \
          A    B    C

Only the leader performs certain writes.

Benefits:

  • simpler ordering
  • easier conflict management
  • centralized ownership

Costs:

  • leader bottleneck
  • failover complexity
  • leadership coordination

50. Coordination Pattern: Sharded Leadership#

Instead of one global leader:

Global Leader

partition leadership:

Shard 1 → Leader A
Shard 2 → Leader B
Shard 3 → Leader C
Shard 4 → Leader D

This can increase scalability.

Example:

User IDs 0-9999
    → Leader A
 
10000-19999
    → Leader B

Each shard has its own ownership.


51. Coordination and Rebalancing#

Suppose:

Leader A owns:
Shard 1
Shard 2
Shard 3

A fails.

The system needs to transfer ownership:

Shard 1 → B
Shard 2 → C
Shard 3 → B

This requires coordination.

Rebalancing should avoid:

  • two owners simultaneously
  • missing ownership
  • excessive movement
  • data corruption

52. Coordination in Distributed Scheduling#

Suppose 10 workers process jobs.

Requirement:

Each job should be processed once logically.

Possible architecture:

Scheduler
    │
    ▼
Queue
    │
 ┌──┼──┬──┐
 ▼  ▼  ▼  ▼
W1 W2 W3 W4

The queue can provide ownership semantics.

For scheduled jobs without a queue, a distributed lock or leader-based scheduler may be used.


53. Coordination in Kubernetes#

Kubernetes itself relies heavily on distributed coordination.

Conceptually:

Control Plane
     │
     ├── API Server
     ├── Scheduler
     ├── Controllers
     └── State Store

The control plane maintains desired state and coordinates cluster changes.

Understanding distributed coordination helps explain:

  • leader election
  • controllers
  • scheduling
  • leases
  • cluster state
  • failover

54. Coordination in Databases#

Distributed databases may use coordination for:

  • leader election
  • replication
  • membership
  • failover
  • partition ownership
  • transaction coordination

For example:

Leader
  │
  ├── Replica A
  ├── Replica B
  └── Replica C

If the leader fails:

Election
   ↓
New leader
   ↓
Replication continues

55. Safety vs Liveness#

A powerful distributed-systems distinction:

Safety#

Nothing bad happens.

Examples:

Never have two valid leaders.
Never commit conflicting state.
Never process stale ownership.

Liveness#

Something good eventually happens.

Examples:

Eventually elect a leader.
Eventually process a job.
Eventually recover.

A system often trades some liveness to protect safety during uncertain failures.


56. Example: Leader Election#

Suppose the network is partitioned.

A system might choose:

No majority
   ↓
No new leader

This reduces availability.

But it protects safety:

No conflicting leaders

Once communication is restored:

majority available
   ↓
leader election
   ↓
progress resumes

This is a fundamental distributed-systems trade-off.


57. Common Misconception #1#

Wrong#

A timeout proves that a server crashed.

Correct#

A timeout only tells us that the expected communication did not complete within the timeout.

The server may be:

  • slow
  • partitioned
  • overloaded
  • alive but unreachable

58. Common Misconception #2#

Wrong#

A distributed lock with a TTL is automatically safe.

Not necessarily.

A worker can outlive its lease and continue operating.

Fencing tokens or another ownership mechanism may be required.


59. Common Misconception #3#

Wrong#

Leader election alone prevents split brain.

Not necessarily.

You also need a mechanism that prevents stale leaders from continuing to perform authoritative operations.

Examples:

  • terms
  • epochs
  • fencing
  • quorum-based authority

60. Common Misconception #4#

Wrong#

More replicas always improve availability.

Not automatically.

More replicas increase potential redundancy but also increase:

  • coordination complexity
  • network traffic
  • quorum requirements
  • failure scenarios

61. Common Misconception #5#

Wrong#

Consensus means every node must respond.

No.

Consensus commonly relies on a quorum.

For:

N = 5

a majority may be:

3

The remaining two can be unavailable while progress remains possible under the protocol.


62. Interview Question: Why Is Leader Election Hard?#

Answer#

Because nodes cannot perfectly distinguish crashes from network delays or partitions. A safe election mechanism must prevent multiple nodes from simultaneously acting as authoritative leaders.


63. Interview Question: What Is Split Brain?#

Answer#

Split brain occurs when different parts of a distributed system independently believe they have authority, such as two nodes both believing they are the leader.

This can cause conflicting writes and state corruption.


64. Interview Question: What Is a Fencing Token?#

Answer#

A fencing token is a monotonically increasing ownership identifier. Downstream resources reject operations carrying an older token, preventing stale workers or leaders from acting after their ownership has expired.


65. Interview Question: Why Do We Need Quorum?#

Answer#

A quorum ensures that decisions require enough nodes to overlap with other valid quorums. Majority-based quorum prevents two independent partitions from both obtaining majority authority.


66. Interview Question: Raft vs Paxos#

A good practical answer:

Both are consensus approaches. Raft was designed with understandability and explicit leader/log concepts in mind, while Paxos is a foundational family of consensus algorithms that is often presented more abstractly. For system design, understand quorum, leader election, terms, replicated logs, commitment, and failure behavior before memorizing protocol details.


67. Interview Question: What Happens When a Leader Dies?#

A typical leader-based consensus system:

Leader fails
    ↓
Followers stop receiving heartbeats
    ↓
Election timeout
    ↓
Candidate starts election
    ↓
Majority votes
    ↓
New leader
    ↓
Replication resumes

The exact mechanics depend on the protocol.


68. Mini Project#

Build a Distributed Job Scheduler Design#

Requirements:

  • 10 scheduler instances
  • 1 million scheduled jobs
  • A job should have one logical owner at a time
  • Scheduler instances can crash
  • Network partitions can occur
  • Jobs may take several minutes
  • Duplicate execution must be minimized
  • Stale workers must not modify job state

Design:

                  Job Store
                     │
              ┌──────┴──────┐
              │             │
          Scheduler A   Scheduler B
              │             │
              └──────┬──────┘
                     │
                  Workers

Consider:

  • leader election
  • leases
  • fencing tokens
  • durable job state
  • retries
  • idempotency
  • heartbeat
  • failure detection
  • recovery
  • observability

69. Advanced Coordination Challenge#

Imagine:

5-node cluster
 
A B C D E

Current leader:

A
term = 10

Partition:

A B | C D E

Questions:

  1. Can A safely remain authoritative?
  2. Can C/D/E elect a new leader?
  3. Why does majority matter?
  4. What should happen to writes from A?
  5. How can stale A be prevented from modifying shared storage?
  6. What happens when the partition heals?

A strong solution should mention:

majority
terms/epochs
fencing
log reconciliation

70. Production Coordination Checklist#

Before deploying coordination infrastructure, ask:

  • What exactly needs coordination?
  • Can the problem be solved without a distributed lock?
  • What happens when the coordinator fails?
  • What happens during a network partition?
  • How is leader election performed?
  • How is stale leadership prevented?
  • Are leases used?
  • Are fencing tokens required?
  • What quorum is needed?
  • How is membership detected?
  • What happens if a node is slow but alive?
  • How are configuration changes versioned?
  • How are stale nodes removed?
  • How is recovery tested?
  • What happens after a partition heals?
  • Can two nodes ever believe they own the same resource?
  • What prevents stale writes?
  • What metrics detect coordination failures?

71. Master Mental Model#

Think of distributed coordination as:

Many nodes
    │
    ▼
Need shared decision
    │
    ▼
Communication can fail
    │
    ▼
Cannot trust silence
    │
    ▼
Need protocol
    │
    ├── Quorum
    ├── Terms / epochs
    ├── Leader election
    ├── Leases
    ├── Fencing
    └── Consensus

The goal is not simply:

"Make all nodes agree."

The deeper goal is:

Make distributed decisions safely despite delays, crashes, partitions, and stale participants.


72. Summary#

You learned:

  • Why distributed coordination is necessary
  • Why coordination is difficult
  • Failure detection
  • Heartbeats
  • Health checks
  • Leader election
  • Split brain
  • Terms and epochs
  • Distributed locks
  • Lease-based ownership
  • Fencing tokens
  • Quorums
  • Majority decisions
  • Consensus
  • Raft
  • Paxos concepts
  • Replicated state machines
  • Coordination services
  • ZooKeeper-style coordination
  • Service discovery
  • Membership
  • Distributed configuration
  • Logical clocks
  • Lamport clocks
  • Vector clocks
  • Sharded leadership
  • Rebalancing
  • Scheduling
  • Safety vs liveness
  • Coordination failure scenarios
  • Interview questions
  • Distributed scheduler design

The most important takeaway:

In distributed systems, you cannot assume that a missing response means failure. Safe coordination requires explicit mechanisms for authority, quorum, ownership, ordering, and stale-node protection.


73. Exercises#

Exercise 1#

Explain why a timeout does not prove a server has crashed.

Exercise 2#

Design a distributed lock for 5 nodes.

Explain:

  • acquisition
  • expiration
  • renewal
  • failure
  • stale workers
  • fencing

Exercise 3#

Explain split brain with a 5-node cluster.

Exercise 4#

Why is a majority quorum important?

Exercise 5#

Explain the difference between:

Replication
vs
Consensus

Exercise 6#

Explain:

Safety
vs
Liveness

using leader election.

Exercise 7#

Design leader election for a scheduled-job system.


74. Next Chapter#

Chapter 27 — High Availability#

Next we will move from coordination into high availability.

We will learn:

  • What availability means
  • Availability percentages
  • SLA / SLO / SLI
  • Nines of availability
  • High-availability architecture
  • Redundancy
  • Active-active systems
  • Active-passive systems
  • Failover
  • Automatic failover
  • Health checks
  • Load balancer failover
  • Database failover
  • Multi-AZ architecture
  • Multi-region architecture
  • Failure domains
  • Graceful degradation
  • Dependency failures
  • Cascading failures
  • Availability calculations
  • Error budgets
  • Real-world HA architecture
  • Interview questions
  • HA design exercise

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 25 — Distributed TransactionsNext ChapterChapter 27 — High Availability
PrevNext