SlideShare a Scribd company logo
Concurrency in
Elixir with OTP
Presented for
Code & Supply
You down with
OTP?
You down with
OTP?
Yeah you know me!
Open
Telecom
Platform
W hat is OTP?
Open
Telecom
Platform
W hat is OTP?
Open source project
Developed by Ericsson, opened in 1998
18 years proven
https://github.com/erlang/otp
Open
Telecom
Platform
W hat is OTP?
Fault tolerant
Distributed
Concurrent
Open
Telecom
Platform
W hat is OTP?
Design principles for writing concurrent
applications in Erlang
Libraries
Concurrency in Elixir with OTP
History
xgen
Integrates Elixir, Mix and OTP
Merged into Elixir
Available in Elixir 0.13.3 and higher
https://github.com/josevalim/xgen
Components
Application
Agents
Tasks
Supervisors
GenServers
GenEvents
Concurrency
Starts Supervisors
Application
# mix.exs
def application do
[mod: { CatFeed, [] }]
end
# lib/cat_feed.ex
defmodule CatFeed do
use Application
def start(_type, _args) do
CatFeed.Supervisor.start_link
end
end
Supervises processes
Supervisor
# lib/cat_feed/supervisor.ex
defmodule CatFeed.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok)
end
def init(:ok) do
children = [ worker(CatFeed.FeederLady) ]
supervise children, strategy :one_for_one
end
end
Supervises processes
Supervisor
# lib/cat_feed/supervisor.ex
defmodule CatFeed.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok)
end
def init(:ok) do
children = [ worker(CatFeed.FeederLady) ]
supervise children, strategy :one_for_one
end
end
one_for_one
If a child process terminates, only that process is
restarted.
Restart Strategies
one_for_one
If a child process terminates, only that process is
restarted.
Restart Strategies
one_for_one
If a child process terminates, only that process is
restarted.
Restart Strategies
rest_for_one
Restarts all processes started after one that failed
Restart Strategies
rest_for_one
Restarts all processes started after one that failed
Restart Strategies
rest_for_one
Restarts all processes started after one that failed
Restart Strategies
one_for_all
Restarts all processes if any fail
Restart Strategies
one_for_all
Restarts all processes if any fail
Restart Strategies
one_for_all
Restarts all processes if any fail
Restart Strategies
Handles state and does things
GenServer
# lib/cat_feed/feeder_lady.ex
defmodule CatFeed.FeederLady do
use Server
# some stuff here …
def handle_call({:fill, bowl}, _from, state) do
{:reply, CatFeed.BowlAgent.put(bowl, :food, state), state}
# or
HashDict.put(bowl, key, value)
end
end
Specialized for storing state
Agent
# lib/cat_feed/bowl_agent.ex
defmodule CatFeed.BowlAgent do
def start_link do # set initial state
Agent.start_link(fn -> HashDict.new end)
end
def get(bucket, key) do # get state
Agent.get(bucket, &HashDict.get(&1, key))
end
def put(bowl, key, value) do # update state
Agent.update(bowl, &HashDict.put(&1, key, value))
end
end
Concurrency in Elixir with OTP
Handled in supervisor
BEAM processes
Spread across machines seamlessly
Concurrency
# lib/cat_feed/supervisor.ex
defmodule CatFeed.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok)
end
def init(:ok) do
children = [ worker(CatFeed.FeederLady) ]
supervise children, strategy :one_for_one
end
end
Concurrency
# lib/cat_feed/supervisor.ex
defmodule CatFeed.Supervisor do
use Supervisor
# def start_link do // folded
def init(:ok) do
children = [
worker(CatFeed.FeederLady),
worker(CatFeed.FeederLady),
CatFeed.Supervisor.start_link
]
supervise children, strategy :one_for_one
end
end
Concurrency
Recap
OTP
Based on Erlang OTP
Supervision tree
Restart strategies
State managed by select entities
Concurrency in
Elixir with OTP
Presented for
Code & Supply
http://codeandsupply.co
@justinxreese

More Related Content

PDF
Elixir and OTP
PDF
Introducing Elixir and OTP at the Erlang BASH
PDF
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
PDF
Elixir
PDF
Introduction to Elixir
PDF
Bootstrap |> Elixir - Easy fun for busy developers
PDF
Concurrency, Robustness & Elixir SoCraTes 2015
PDF
Hello elixir (and otp)
Elixir and OTP
Introducing Elixir and OTP at the Erlang BASH
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir
Introduction to Elixir
Bootstrap |> Elixir - Easy fun for busy developers
Concurrency, Robustness & Elixir SoCraTes 2015
Hello elixir (and otp)

What's hot (20)

PPTX
PDF
PDF
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
PDF
Elixir and Phoenix for Rubyists
PPTX
Elixir introduction
PDF
effective_r27
PDF
Phoenix for Rails Devs
PDF
Actor Clustering with Docker Containers and Akka.Net in F#
PDF
Concurrecny inf sharp
PDF
fg.workshop: Software vulnerability
PDF
Basic buffer overflow part1
ODP
Intro To Spring Python
PDF
Recipes to build Code Generators for Non-Xtext Models with Xtend
PDF
Effective Java with Groovy - How Language Influences Adoption of Good Practices
PDF
What To Expect From PHP7
PDF
Akka Futures and Akka Remoting
PDF
Using Jenkins for Continuous Integration of Perl components OSD2011
PDF
OTP application (with gen server child) - simple example
PDF
Tame cloud complexity with F# powered DSLs (build stuff)
PDF
React Native One Day
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
Elixir and Phoenix for Rubyists
Elixir introduction
effective_r27
Phoenix for Rails Devs
Actor Clustering with Docker Containers and Akka.Net in F#
Concurrecny inf sharp
fg.workshop: Software vulnerability
Basic buffer overflow part1
Intro To Spring Python
Recipes to build Code Generators for Non-Xtext Models with Xtend
Effective Java with Groovy - How Language Influences Adoption of Good Practices
What To Expect From PHP7
Akka Futures and Akka Remoting
Using Jenkins for Continuous Integration of Perl components OSD2011
OTP application (with gen server child) - simple example
Tame cloud complexity with F# powered DSLs (build stuff)
React Native One Day
Ad

Viewers also liked (18)

PDF
東京Node学園#8 Let It Crash!?
PDF
Distributed Erlang Systems In Operation
KEY
Erlang vs. Java
PPT
Let It Crash (@pavlobaron)
PDF
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
KEY
Intro to Erlang
PDF
1 hour dive into Erlang/OTP
PDF
Node.jsエンジニア Erlangに入門するの巻
PDF
Erlang - Concurrent Language for Concurrent World
PPT
Erlang OTP
PDF
Intro To Erlang
PPTX
リアルタイムサーバー 〜Erlang/OTPで作るPubSubサーバー〜
PDF
Erlang/OTP in Riak
PDF
Let it crash! The Erlang Approach to Building Reliable Services
PPTX
Imprementation of realtime_networkgame
PPTX
地獄のElixir(目黒スタートアップ勉強会)
PDF
ニコニコ生放送の配信基盤改善
KEY
NoSQL Databases: Why, what and when
東京Node学園#8 Let It Crash!?
Distributed Erlang Systems In Operation
Erlang vs. Java
Let It Crash (@pavlobaron)
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Intro to Erlang
1 hour dive into Erlang/OTP
Node.jsエンジニア Erlangに入門するの巻
Erlang - Concurrent Language for Concurrent World
Erlang OTP
Intro To Erlang
リアルタイムサーバー 〜Erlang/OTPで作るPubSubサーバー〜
Erlang/OTP in Riak
Let it crash! The Erlang Approach to Building Reliable Services
Imprementation of realtime_networkgame
地獄のElixir(目黒スタートアップ勉強会)
ニコニコ生放送の配信基盤改善
NoSQL Databases: Why, what and when
Ad

Similar to Concurrency in Elixir with OTP (20)

PDF
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
PDF
Elixir/OTP for PHP developers
PDF
Elixir par
PDF
Elixir concurrency 101
PDF
Scaling Ruby with Evented I/O - Ruby underground
PDF
"Elixir of Life" - Dev In Santos
PDF
Building communication platforms for the IoT
PDF
Using OTP and gen_server Effectively
PDF
Re-Design with Elixir/OTP
PDF
Ecto and Phoenix: Doing Web With Elixir
PDF
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
PDF
Elixir Programming Language 101
PDF
Dataflow: Declarative concurrency in Ruby
PDF
GenServer in action
PDF
GenServer in Action – Yurii Bodarev
PDF
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
ODP
Elixir otp-basics
KEY
ErLounge SF/Bay: 2010.01.12 Christian Westbrook / CoTweet
PPTX
Repeating History...On Purpose...with Elixir
ODP
Concurrent programming
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
Elixir/OTP for PHP developers
Elixir par
Elixir concurrency 101
Scaling Ruby with Evented I/O - Ruby underground
"Elixir of Life" - Dev In Santos
Building communication platforms for the IoT
Using OTP and gen_server Effectively
Re-Design with Elixir/OTP
Ecto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Elixir Programming Language 101
Dataflow: Declarative concurrency in Ruby
GenServer in action
GenServer in Action – Yurii Bodarev
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
Elixir otp-basics
ErLounge SF/Bay: 2010.01.12 Christian Westbrook / CoTweet
Repeating History...On Purpose...with Elixir
Concurrent programming

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
AI in Product Development-omnex systems
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administraation Chapter 3
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PDF
top salesforce developer skills in 2025.pdf
Understanding Forklifts - TECH EHS Solution
AI in Product Development-omnex systems
How Creative Agencies Leverage Project Management Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Reimagine Home Health with the Power of Agentic AI​
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Digital Strategies for Manufacturing Companies
PTS Company Brochure 2025 (1).pdf.......
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Operating system designcfffgfgggggggvggggggggg
System and Network Administraation Chapter 3
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
top salesforce developer skills in 2025.pdf

Concurrency in Elixir with OTP