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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
200
Code reuse through polymorphic variants
lambda_foo
1
250
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
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
200
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
490
FDEが実現するAI駆動経営の現在地
gonta
2
240
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
130
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
350
メールのエイリアス機能を履き違えない
isshinfunada
0
160
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
350
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
140
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3.3k
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
340
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
2.8k
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
22k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.7k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
Side Projects
sachag
455
43k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
160
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
480
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!