If you build webapps,
you build distributed systems.
Slide 24
Slide 24 text
Raft
Slide 25
Slide 25 text
@ongardie
Diego Ongaro
John Ousterhout
and
Slide 26
Slide 26 text
con·sen·sus
/kənˈsensəs/
!
Agreeing upon state across
distributed processes even
in the presence of failures.
Slide 27
Slide 27 text
When should I use it?
Slide 28
Slide 28 text
• Distributed locks
• Configuration
• Background jobs
Slide 29
Slide 29 text
Why not Paxos?
Slide 30
Slide 30 text
Laying the Groundwork
Slide 31
Slide 31 text
{…}
Log
State
Machine
Consensus
Module
Slide 32
Slide 32 text
Leader
Follower Follower
Follower
Slide 33
Slide 33 text
Leader
Follower Follower
Follower
Slide 34
Slide 34 text
Leader
Follower Follower
Follower
Slide 35
Slide 35 text
Follower
Slide 36
Slide 36 text
Leader Election
Log Replication
Safety
Slide 37
Slide 37 text
Follower Candidate Leader
Slide 38
Slide 38 text
Follower Candidate Leader
Slide 39
Slide 39 text
Follower Candidate Leader
Times out,
Starts election
Slide 40
Slide 40 text
Follower Candidate Leader
Times out,
Starts election
Wins election
Slide 41
Slide 41 text
Follower Candidate Leader
Times out,
Starts election
Times out,
Restarts election
Wins election
Slide 42
Slide 42 text
Follower Candidate Leader
Times out,
Starts election
Times out,
Restarts election
Wins election
Discovers current
or new leader,
Steps down
Slide 43
Slide 43 text
Follower Candidate Leader
Times out,
Starts election
Times out,
Restarts election
Wins election
Discovers new leader,
Steps down
Discovers current
or new leader,
Steps down
Slide 44
Slide 44 text
RequestVote
Used by candidates to ask for votes during
an election. Log information included for
comparison.
!
AppendEntries
Used by leaders to tell followers which
entries to replicate and commit. Also used
as a heartbeat to remain leader.
Follower
Candidate
Vote for me please.
Follower
Here are some entries for your log.
Oh, and btw I’m still the leader.
Leader
Slide 45
Slide 45 text
Term
Higher numbers are used to determine
leaders and check log entries. The term is
incremented each time an election is
started. Any command with an old term is
ignored.
Term 1 Term 2 Term 3
Election Normal Operation Split vote
Slide 46
Slide 46 text
Follower
Follower Follower
Follower
Slide 47
Slide 47 text
Candidate
Follower Follower
Follower
Votes
Times out,
starts election
Slide 48
Slide 48 text
Candidate
Follower Follower
Follower
Votes
Votes for self
Slide 49
Slide 49 text
Candidate
Follower Follower
Follower
Votes
Sends out
RequestVotes
Slide 50
Slide 50 text
Candidate
Follower Follower
Votes
Responds
with success
Slide 51
Slide 51 text
Leader
Follower
Votes
Yay! I won!
Follower
Slide 52
Slide 52 text
Leader Election
Log Replication
Safety
Slide 53
Slide 53 text
Log Entries Explained
Slide 54
Slide 54 text
SET X = 1 SET Y = 2 SET Z = 3 SET X = 4 SET X = 5
1 1 1 2 2
SET X = 1 SET Y = 2 SET Z = 3 SET X = 4
1 1 1 2
Leader
Follower
1 2 3 4 5 6