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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tim McGilchrist
May 08, 2014
Programming
700
4
Share
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
240
Either Error Success
lambda_foo
0
160
Idris States: Dependent types, not just for vectors?
lambda_foo
0
260
Other Decks in Programming
See All in Programming
iOS26時代の新規アプリ開発
yuukiw00w
0
200
inferと仲良くなる10分間
ryokatsuse
1
250
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
160
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
110
柔軟なPDFレイアウトエディタを支える型システム設計 — Discriminated UnionとConditional Typeの実践
minako__ph
3
580
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
360
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
130
Sans tests, vos agents ne sont pas fiables
nabondance
0
160
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
240
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
170
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
950
TSKaigi2026-静的解析への投資がAI時代のコード品質を支える ── カスタムESLintルールの設計と運用
hayatokudou
6
1.1k
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
380
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.5k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
700
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
510
Discover your Explorer Soul
emna__ayadi
2
1.1k
Color Theory Basics | Prateek | Gurzu
gurzu
0
310
Unsuck your backbone
ammeep
672
58k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
The browser strikes back
jonoalderson
0
1.1k
Building an army of robots
kneath
306
46k
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!