Skip to content

Consensus and coordination: recap and quiz

  1. Quorums. A write that needs W acknowledgements and a read that needs R replies share a replica when R + W > N, and W above half of N keeps two sides of a partition from both writing.
  2. Consensus and leader election. Nodes agree on a leader by majority vote in numbered terms, started by a follower that hears no heartbeat within the election timeout, and the time without a leader is about that timeout.
  3. Leases and fencing tokens. A leader that pauses past its lease can wake up and write after a new one is elected, and only a storage that refuses older tokens stops the write.
  4. Distributed locks and coordination services. A safe lock is a lease plus a token, a lock for efficiency can be approximate and a lock for correctness cannot, and coordination services stop serving on the minority side.
  5. Two-phase commit. A coordinator that fails after every participant has voted yes leaves them unable to decide while they hold their locks, and a consensus group in place of the coordinator removes the stall.
Idea What breaks What you see What helps
Quorums R + W is not more than N, or W is at most half of N Stale reads from a small side, or two sides that both write R + W > N and W above half of N
Elections The timeout is too short or too long Needless elections, or a long wait with no leader A timeout that suits the network, and randomised timeouts
Leases The holder pauses past the lease An old leader writes after a new one is elected A token that increases with every grant
Locks A lock for correctness without a token Corrupted state that nobody was told about A consensus-backed service and a token check at the storage
Two-phase commit The coordinator fails after the votes Participants wait and hold locks A consensus group as coordinator, or no distributed transaction

A checklist for using agreement between nodes

Section titled “A checklist for using agreement between nodes”

Each question points to the lesson that answers it.

  1. What must the nodes agree on? A value, a leader, or an outcome. If one node can decide alone, do not use consensus. (Consensus and leader election)
  2. What happens on the minority side of a partition? Decide whether it refuses requests or serves stale ones, before the partition. (Quorums)
  3. Is R + W more than N, and is W above half of N? They guard different things. (Quorums)
  4. How long is the election timeout, and what does it cost in both directions? Measure the delays of your own network and processes. (Consensus and leader election)
  5. What happens when a leader pauses and wakes up? If the answer is that it writes, you need a token. (Leases and fencing tokens)
  6. Does the storage compare tokens? A token that nobody checks protects nothing. (Leases and fencing tokens)
  7. Is this lock for efficiency or for correctness? Only the second needs a consensus-backed service. (Distributed locks)
  8. Is the transaction spread over several databases, and who holds the decision? Know what a failed coordinator leaves locked, or keep the data together. (Two-phase commit)
  9. Did you run the failure? The labs and the failure labs are there to be broken.

Seven questions cover the whole module. Every option is explained, whether it is right or wrong.

Consensus and coordination: module quiz

This quiz needs JavaScript to check your answers.

Question 1 of 7

A consensus cluster of five servers needs a majority to work. How many servers can fail while it keeps working?

Enter a number and choose its unit.

servers
Question 2 of 7

What does R + W > N guarantee?

Choose one answer.

Question 3 of 7

The leader pauses. A follower waits 300 ms for a heartbeat, becomes a candidate, and wins after one message to ask for a vote and one to get it, each taking 10 ms.

How long is there no working leader?

Enter a number and choose its unit.

milliseconds
Question 4 of 7

A lock holder pauses for longer than its lease. Another client takes the lock. The first client wakes up and writes.

What stops the late write?

Choose one answer.

Question 5 of 7

Which of these are true of a fencing token? Select all that apply.

Choose every answer that applies.

Question 6 of 7

Two workers might both send the same weekly digest email. If the lock that prevents this fails, a few people receive a duplicate.

What does this lock need to be?

Choose one answer.

Question 7 of 7

Why does two-phase commit block when the coordinator fails after all the votes?

Choose one answer.

This module showed how nodes agree and what it costs when they cannot. The next modules turn to asynchronous systems, where work travels through queues and streams, and where the same questions come back in another form: what happens when a message is delivered twice, and who decides which copy counts.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.