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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tim McGilchrist
May 08, 2014
Programming
690
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
180
Code reuse through polymorphic variants
lambda_foo
1
230
Either Error Success
lambda_foo
0
150
Idris States: Dependent types, not just for vectors?
lambda_foo
0
240
Other Decks in Programming
See All in Programming
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
820
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
5
2.5k
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
340
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
110
感情を設計する
ichimichi
5
1.3k
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
130
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
2
260
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
230
「速くなった気がする」をデータで疑う
senleaf24
0
150
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
130
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
240
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.1k
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
320
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
260
Speed Design
sergeychernyshev
33
1.6k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
200
My Coaching Mixtape
mlcsv
0
96
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Mobile First: as difficult as doing things right
swwweet
225
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
680
WENDY [Excerpt]
tessaabrams
9
37k
What's in a price? How to price your products and services
michaelherold
247
13k
Site-Speed That Sticks
csswizardry
13
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!