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
Distributed Elixir
Search
Maciej Kaszubowski
July 07, 2018
Programming
0
93
Distributed Elixir
Presentation about some of the tools for distributed programming in Elixir
Maciej Kaszubowski
July 07, 2018
Tweet
Share
More Decks by Maciej Kaszubowski
See All by Maciej Kaszubowski
Error-free Elixir
mkaszubowski
0
250
Modular Design in Elixir (ElixirConf EU 2019)
mkaszubowski
2
560
The Big Ball of Nouns
mkaszubowski
0
86
Modular Design in Elixir
mkaszubowski
1
330
Our three years with Elixir
mkaszubowski
0
190
Concurrency Basics for Elixir
mkaszubowski
0
96
Software Architecture
mkaszubowski
0
110
Let it crash - fault tolerance in Elixir/OTP
mkaszubowski
0
370
CRDTs - The science behind Phoenix Presence
mkaszubowski
2
240
Other Decks in Programming
See All in Programming
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
最新TCAキャッチアップ
0si43
0
190
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Jakarta EE meets AI
ivargrimstad
0
130
Ethereum_.pdf
nekomatu
0
460
CSC509 Lecture 12
javiergs
PRO
0
160
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
420
A Philosophy of Restraint
colly
203
16k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Music & Morning Musume
bryan
46
6.2k
What's in a price? How to price your products and services
michaelherold
243
12k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Done Done
chrislema
181
16k
Producing Creativity
orderedlist
PRO
341
39k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Transcript
It’s scary out there
Organisational Matters
None
We’re 1 year old!
Summer break (probably)
We’re looking for speakers!
It’s scary out there Distributed Systems in Elixir Poznań Elixir
Meetup #8
None
Pid 1 Pid 2
Pid 1 Pid 2 Node A Node B
The basics
iex --name
[email protected]
--cookie cookie -S mix
Node.connect(:’
[email protected]
')
(DEMO)
#PID<0.94.0>
#PID<0.94.0> node identifier (relative to current node)
#PID<0.94.0> node identifier (relative to current node) 0 =a local
process
#PID<0.94.0> Process id node identifier (relative to current node)
How does it work?
Pid 1 Node A Pid 2 Node B
Pid 1 Node A Pid 2 Node B TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection :erlang.binary_to_term(encode)
send(pid2, msg) Pid 1 Node A receive msg Pid 2
Node B destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection :erlang.binary_to_term(encode)
Distributed Systems?
Distributed Systems? Solved!
Well, not exactly…
Difficulties
Node A Node B
Node A Node B Node C
Node A Node B Node C Node D
None
A lot of messages
us-east-1 us-west-2
8 fallacies of distributed computing
fallacies of distributed computing 1. The network is reliable 2.
Latency is zero 3. Bandwidth is infinite 4. The network is secure 5. Topology doesn’t change 6. The is one administrator 7. Transport cost is zero 8. The network is homogenous
CAP THEOREM
CAP THEOREM us-west-2 us-east-1
CAP THEOREM us-west-2 us-east-1 Set X=5
CAP THEOREM us-west-2 us-east-1 Set X=5 Read X
CAP THEOREM us-west-2 us-east-1 Set X=5 Set X = 7
Consistency or Availability (under network partition)
Consistency or Speed In practice
Guarantees
Pid 1 Pid 2 Pid3 Guarantees m1, m2, m3 m4,
m5, m6 send(pid2, m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6)
Pid 1 Pid 2 Pid3 Guarantees m1, m2, m3 m4,
m5, m6 send(pid2, m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6) Ordering between two processes is preserved
Pid 1 Pid 2 Pid3 Guarantees m4, m5, m6 send(pid2,
m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6) m1, m2, m3 Delivery is not guaranteed
Pid 1 Pid 2 Pid3 Guarantees m1, m2, m3 m4,
m5, m6 send(pid2, m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6) Ordering between different processes is not guaranteed
[m1, m2, m3, m4, m5, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6] []
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6] [] [m1, m3, m2, m4, m5, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6] [] [m1, m3, m2, m4, m5, m6] [M3, M3]
Phoenix Request A User Logged In
Phoenix Request A Phoenix Request B User Logged In User
Logged OUT
Phoenix Request A Phoenix Request B User Logged In User
Logged OUT This Can arrive first
Unfortunately, things tend to work fine locally
The Tools
:global
Pid 1 Node A Node B Pid 2
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Register PId1 as “global”
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Register PId1 as “global” Sure
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Register PId1 as “global” Sure :global.whereis_name(“global”) = pid1
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
:global.register_name(“global”, self()) ?
(DEMO)
:global • single process registration (if everything works OK) •
Favours availability over consistency • Information stored locally (reading is fast) • Registration is blocking (may be slow)
:PG2
Pid1 Pid3 Pid2 [] [] []
Pid1 Pid3 Pid2 :pg2.create(“my_group”) [] [] []
Pid1 Pid3 Pid2 [] [] [] join join :pg2.join(“my_group”, self()
Pid1 Pid3 Pid2 [] [pid1] [] Monitor Monitor :pg2.join(“my_group”, self()
Pid1 Pid3 Pid2 [pid1] [pid1] [pid1] Monitor Monitor :pg2.join(“my_group”, self()
Pid1 Pid3 Pid2 [pid1] [pid1] [pid1]
Pid1 Pid3 Pid2 :pg2.join(“my_group”, self() [pid1] [pid1, pid2] [pid1]
Pid1 Pid3 Pid2 join :pg2.join(“my_group”, self() join [pid1, pid2] [pid1,
pid2] [pid1, pid2]
Pid1 Pid3 Pid2 [pid1] [pid2] [pid1]
Pid1 Pid3 Pid2 [pid1] [pid2] [pid1]
Pid1 Pid3 Pid2 [pid1] [pid2] [pid1]
Pid1 Pid3 Pid2 [pid1, pid2] [pid1, pid2] [pid1, pid2]
It will heal, but the state in inconsistent for some
time
What does it matter?
Node A Pg2 Pg2 Pg2 Node B Node C
Node A Pg2 Pg2 Pg2 Node B Node C Phoenix
Channels
Node A Pg2 Pg2 Pg2 Node B Node C Phoenix
Presence
Node A Pg2 Pg2 Pg2 Node B Node C Phoenix
Channels
:pg2 • Process groups • Favours availability over consistency •
Information stored locally (reading is fast) • Registration is blocking (may be slow)
Strongly consistent Solutions
Strongly consistent Solutions • Consensus - Raft, Paxos, ZAB •
Two-phase commit/THree-phase commit (2PC/3PC) • Read/Write quorums • Single database as a source of truth
Summary
Distributed Systems
Well, not exactly…
Asynchronous messages Distributed systems are all about
Really, there’s no magic
Just asynchronous messages between nodes
Just asynchronous messages between nodes & node failures
Just asynchronous messages between nodes & node failures & Communication
failures
Just asynchronous messages between nodes & node failures & Communication
failures & Network partitions
Tradeoffs Distributed systems are all about
Where to go next
Worth looking at • Riak_core • RAFT • Two-Phase Commit
(2PC) / Three-Phase Commit (3PC) • CRDTs • LASP and Partisan
Free online (click!) Elixir / Erlang
Free PDF (Click!) Distributed Systems
Theory (The hard stuff)
• https://raft.github.io/ (Raft Consensus) • http://learnyousomeerlang.com/distribunomicon • https://www.rgoarchitects.com/Files/fallacies.pdf (Fallacies of
distributed computing) • https://dzone.com/articles/better-explaining-cap-theorem (CAP Theorem) • https://medium.com/learn-elixir/message-order-and-delivery-guarantees-in-elixir- erlang-9350a3ea7541 (Elixir message delivery guarantees) • https://lasp-lang.readme.io/ (LASP) • https://arxiv.org/pdf/1802.02652.pdf (Partisan Paper) • https://bravenewgeek.com/tag/three-phase-commit/ (3PC)
We’re looking for speakers!
Thank You! Poznań Elixir Meetup #8