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
92
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
240
Modular Design in Elixir (ElixirConf EU 2019)
mkaszubowski
2
550
The Big Ball of Nouns
mkaszubowski
0
86
Modular Design in Elixir
mkaszubowski
1
330
Our three years with Elixir
mkaszubowski
0
180
Concurrency Basics for Elixir
mkaszubowski
0
93
Software Architecture
mkaszubowski
0
110
Let it crash - fault tolerance in Elixir/OTP
mkaszubowski
0
360
CRDTs - The science behind Phoenix Presence
mkaszubowski
2
240
Other Decks in Programming
See All in Programming
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.4k
Identifying User Idenity
moro
6
8k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
280
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
160
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
macOS でできる リアルタイム動画像処理
biacco42
7
2k
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
330
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How to train your dragon (web standard)
notwaldorf
88
5.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
We Have a Design System, Now What?
morganepeng
50
7.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Fireside Chat
paigeccino
32
3k
Producing Creativity
orderedlist
PRO
341
39k
Speed Design
sergeychernyshev
24
570
Building Adaptive Systems
keathley
38
2.2k
Ruby is Unlike a Banana
tanoku
96
11k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
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