Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Distributed Elixir
Search
Maciej Kaszubowski
July 07, 2018
Programming
0
95
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
340
Our three years with Elixir
mkaszubowski
0
190
Concurrency Basics for Elixir
mkaszubowski
0
97
Software Architecture
mkaszubowski
0
110
Let it crash - fault tolerance in Elixir/OTP
mkaszubowski
0
380
CRDTs - The science behind Phoenix Presence
mkaszubowski
2
240
Other Decks in Programming
See All in Programming
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
0
2.8k
Jakarta EE meets AI
ivargrimstad
0
790
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
120
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.1k
AWS AppSyncを用いた GraphQL APIの開発について - NIFTY Tech Talk #22
niftycorp
PRO
0
100
初めてDefinitelyTypedにPRを出した話
syumai
0
470
layerx_20241129.pdf
kyoheig3
1
170
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
120
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
6.7k
Full stack testing :: basic to basic
up1
1
770
Discord Bot with AI -for English learners-
xin9le
0
100
Thoughts and experiences on Rust and TypeScript
unvalley
2
200
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.3k
Code Reviewing Like a Champion
maltzj
520
39k
RailsConf 2023
tenderlove
29
910
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
760
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Building Adaptive Systems
keathley
38
2.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
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