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
700
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
190
Code reuse through polymorphic variants
lambda_foo
1
250
Either Error Success
lambda_foo
0
160
Idris States: Dependent types, not just for vectors?
lambda_foo
0
270
Other Decks in Programming
See All in Programming
AI時代のUIはどこへ行く?その2!
yusukebe
21
7.1k
AIで効率化できた業務・日常
ochtum
0
130
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
120
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.2k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
630
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
さぁV100、メモリをお食べ・・・
nilpe
0
140
Claspは野良GASの夢をみるか
takter00
0
190
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
The Limits of Empathy - UXLibs8
cassininazir
1
360
My Coaching Mixtape
mlcsv
0
150
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Writing Fast Ruby
sferik
630
63k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The browser strikes back
jonoalderson
0
1.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
Balancing Empowerment & Direction
lara
6
1.2k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
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!