Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RAFT: Implementing Distributed Consensus with E...
Search
Tim McGilchrist
May 08, 2014
Programming
710
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RAFT: Implementing Distributed Consensus with Erlang
Talk from Yow LambdaJam 2014 in Brisbane on RAFT Algorithm and implementing it in Erlang.
Tim McGilchrist
May 08, 2014
More Decks by Tim McGilchrist
See All by Tim McGilchrist
Dependently Typed State Machines
lambda_foo
0
210
Code reuse through polymorphic variants
lambda_foo
1
260
Either Error Success
lambda_foo
0
170
Idris States: Dependent types, not just for vectors?
lambda_foo
0
280
Other Decks in Programming
See All in Programming
引き算の組織 ― アウトカムとAIに全振りするために辞めたこと ― / Organization by Subtraction
hirokiyamamoto14
PRO
0
260
Dockerfile CMD for Node.js
grazie1999
0
110
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2k
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
1
170
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.9k
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
130
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
VibeCodingからAgenticWorkflowへ
starfish719
0
700
仕様駆動開発の消費期限
watany
20
8.8k
MySQLとPostgreSQLって何が違うの?
akagami
0
120
AIを紡ぐPMのお話
swdtkuy
0
120
Go 1.27 における memory allocation の高速化
andpad
0
280
Featured
See All Featured
Navigating Team Friction
lara
192
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
GraphQLとの向き合い方2022年版
quramy
50
15k
Mobile First: as difficult as doing things right
swwweet
225
10k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
430
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
380
Become a Pro
speakerdeck
PRO
31
6.2k
Designing for Performance
lara
611
70k
Tell your own story through comics
letsgokoyo
1
1k
Transcript
Tim McGilchrist @lambda_foo lambdafoo.com Raft Implementing Distributed Consensus with Erlang
Outline ❖ Goals! ❖ The consensus problem! ❖ Outline RAFT
algorithm! ❖ Implementing in Erlang
Goals What I want you to get out of this
talk?! • Understand core ideas in RAFT! • Erlang / OTP as a tool for building systems! • Build your own implementation
Consensus In a distributed system, agreement among multiple processes on
a single data value, despite failures. ! ! Once they reach a decision on a value, that decision is final.
Potential Use Case ❖ Configuration Management! ❖ Distributed Transactions! ❖
Distributed Lock Manager! ❖ DNS and Resource Discovery
RAFT ❖ Design for understandability! ❖ Strong leader! ❖ Practical
to implement Goals Raft is a consensus algorithm that is designed to be easy to understand.
Messages ❖ RAFT only needs 2 messages.! ❖ RequestVote includes
term! ❖ AppendEntries includes term and log entries! ❖ Term acts as a logical clock
States 3 states a node can be in. Follower Candidate!
Leader
Leader Leader • Only a single leader within a cluster!
• Receives commands from client! • Commits commands to the log
Follower Follower • Appends commands to log! • Votes for
candidates! • Otherwise passive
Candidate Candidate! • Initiates Election! • Coordinates Votes
Leader Election Follower Candidate! Leader starts up timeout new election
gets majority of votes step down step down timeout restart election
Log Replication add 1 F2 F1 Leader AppendEntries add 1,
index 0 add 1, index 0
Log Replication add 1 add 1 add 1 F2 F1
Leader Ok OK
Log Replication add 1 add 1 add 1 F2 F1
Leader Executes command
Log Replication add 1 add 4 add 1 add 1
F2 F1 Leader AppendEntries add 4, index 1 add 4, index 1 Executes command Executes command
RAFT Summary ❖ 2 types of messages, RequestVote and AppendEntries!
❖ 3 states, Leader, Follower and Candidate! ❖ Save Entries to persistent log
Erlang ❖ Functional language! ❖ Fundamentally a concurrent language! ❖
Actor model as basic abstraction! ❖ No shared state between actors! ❖ OTP behaviours like supervisors and gen_fsm! ❖ Location independent message sending
Implementation Overview ❖ github.com/tmcgilchrist/sloop ! ❖ github.com/andrewjstone/ rafter! ❖ Each
node has 2 supervised behaviours! ❖ gen_fsm implementing the consensus protocol! ❖ gen_server wraps the log store! ❖ passes erlang terms as messages
sloop_fsm ❖ state machine implements leader election and log replication!
❖ each state is a function with multiple clauses! !
Supervisors sloop_sup sloop_fsm sloop_store sloop_state sender
Implementations ! ❖ raftconsensus.github.io! ❖ github.com/tmcgilchrist/sloop ! ❖ github.com/andrewjstone/rafter !
❖ github.com/goraft/raft
Summary ❖ Defined Distributed Consensus! ❖ Looked at core ideas
of RAFT! ❖ Erlang suits distributed systems! ❖ Map Erlang to RAFT
Thanks!