L7 - Consensus Flashcards

1
Q

What does Consensus mean in Distributed System?

A

Traditional formulation of consensus several nodes come to an agreement about a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is total order broadcast?

A

A method used for state machine replication where all nodes receive messages in the same order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is manual leader failover problematic?

A

It requires human intervention, which is slow and inefficient during unplanned outages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the four key properties of a consensus algorithm?

A

Uniform Agreement – No two nodes decide differently.
Integrity – No node decides twice.
Validity – A decided value must be proposed by some node.
Termination – Every non-crashed node eventually decides on a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name some common consensus algorithms.

A

Paxos (Lamport, 1998) – Single-value consensus.
Multi-Paxos – Generalization for total order broadcast.
Raft (Ongaro & Osterhaut, 2014) – FIFO-total order broadcast.
Zab & Viewstamped Replication – Other total order broadcast algorithms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why can’t consensus be deterministic in an asynchronous system?

A

Due to the FLP result (Fischer, Lynch, Paterson), no deterministic algorithm can guarantee termination in a fully asynchronous, crash-stop system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do Raft and Multi-Paxos handle leader election?

A

Use a failure detector (timeouts) to suspect crashes.
Elect a new leader when needed.
Prevent multiple leaders via term-based voting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the “split-brain” problem in leader election?

A

A situation where multiple nodes incorrectly believe they are the leader.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the three states of nodes in Raft?

A

Follower – Passive, expects heartbeats.
Candidate – Actively requests votes to become leader.
Leader – Sends AppendEntries RPCs and maintains log replication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if a leader’s term is outdated?

A

The leader steps down, updates its term, and becomes a follower.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does Raft ensure log consistency?

A

Each log entry includes an index, term, and command.
AppendEntries RPCs include the previous log index/term to detect mismatches.
Followers reject entries that don’t match their logs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does Raft prevent conflicting leaders?

A

Each node votes only once per term.
A majority vote is required for election.
If no candidate wins, a new election starts with an incremented term.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What ensures that logs across nodes remain identical?

A

A leader’s log is always the authoritative source.
Entries must be replicated on a majority of nodes before commitment.
Leaders never overwrite existing committed entries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of heartbeats in Raft?

A

Leaders send heartbeats (empty AppendEntries RPCs) to maintain authority.
Followers start a new election if no heartbeat is received within the timeout.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens when a new leader is elected?

A

The new leader synchronizes logs by overwriting conflicting entries on followers.
Any uncommitted entries from the previous leader may be discarded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does Raft neutralize old leaders?

A

Every RPC includes a term number.
If an RPC’s term is outdated, the sender steps down.
This prevents old leaders from making changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do clients interact with a Raft cluster?

A

Send requests to the leader.
If leader is unknown, contact any node (which redirects to the leader).
The leader commits and executes the command before responding.

18
Q

How does Raft ensure exactly-once semantics?

A

Clients embed a unique ID in each command, preventing duplicate execution.

19
Q

Why can’t a system switch configurations immediately?

A

It could create conflicting majorities between old and new configurations.

20
Q

How does Raft handle configuration changes?

A

Uses a 2-phase joint consensus approach.
Both old and new configurations must approve changes before applying them.

21
Q

What is ZooKeeper and what functions does it provide?

A

A KV Store that is distributed across multiple nodes (also known as configuration-membership services):

Designed to hold a small amount of data (ideally fits in memory)
that is replicated across all the nodes using a fault-tolerant total order broadcast algorithm.

22
Q

How does ZooKeeper ensure linearizable atomic operations?

A

By using a consensus protocol that provides strict ordering.

23
Q

How does ZooKeeper detect failures?

A

Clients maintain long-lived sessions with heartbeat messages. If heartbeats stop, the session is terminated.
Any locks holded by this client are then released.

24
Q

What is a fencing token in ZooKeeper?

A

A monotonically increasing number assigned when acquiring a lock to prevent stale processes from interfering.

25
Q

What is the nextIndex in Raft?

A

It is the index of the next log entry that the leader will send to a follower.

26
Q

How does Raft repair log inconsistencies?

A

If a follower rejects an AppendEntries RPC due to a log mismatch, the leader decrements nextIndex and retries until consistency is restored.

27
Q

Why does Raft track nextIndex separately for each follower?

A

Because different followers may have different log inconsistencies that need to be resolved.

28
Q

When can a leader commit an entry in Raft?

A

Only when the entry has been stored on a majority of nodes and at least one entry from the leader’s current term is committed.

29
Q

Why must a leader commit an entry from its own term before committing older entries?

A

To prevent an outdated leader from overwriting committed log entries.

30
Q

What happens if a leader crashes before an entry is fully committed?

A

The next leader may override uncommitted entries to maintain consistency.

31
Q

Why do consensus algorithms perform worse than asynchronous replication?

A

Because they require synchronous communication and must reach agreement before processing writes.

32
Q

What is the minimum number of nodes required for consensus to tolerate 1 and 2 failures?

A

3 nodes to tolerate 1 failure.
5 nodes to tolerate 2 failures.

33
Q

Why does Raft struggle with highly variable network delays?

A

Because leader election relies on timeouts, and if delays fluctuate, false leader elections can occur, causing instability.

34
Q

How does ZooKeeper detect node failures?

A

By maintaining long-lived client sessions where heartbeats are exchanged periodically.

35
Q

What happens if a client stops sending heartbeats to ZooKeeper?

A

The session is declared dead, and any locks or leases held by the client are automatically released.

36
Q

How does ZooKeeper ensure time-ordered operations?

A

By assigning a monotonically increasing transaction ID to each operation, preventing race conditions.

37
Q

Why do old leaders need to be neutralized in Raft?

A

Because after a network partition, an old leader may reconnect and try to append outdated log entries.

38
Q

How does Raft detect and reject outdated leaders?

A

Every RPC message includes a term number:
1. If a leader’s term is older than the follower’s, the RPC is rejected.
2. If a follower’s term is older than the sender’s, the follower steps down and updates its term.

39
Q

How does Raft prevent outdated leaders from committing new log entries?

A

The election process updates the terms of a majority of nodes, ensuring that a deposed leader cannot gain quorum.

40
Q

How does a Raft leader handle client requests?

A

The leader appends the command to its log, replicates it to followers, and applies it once a majority acknowledges it.

41
Q

What 2 RPCs are used in Raft?

A

RequestVote RPC – Used by candidates to request votes during leader elections.
AppendEntries RPC – Used by the leader to replicate log entries and send heartbeats.

42
Q

How does Raft prevent log inconsistencies after a leader crash?

A

The new leader overwrites conflicting entries in followers’ logs using nextIndex tracking and AppendEntries RPC retries.