SlideShare a Scribd company logo
Elixir Elevated!
The Ups and Downs of OTP
Greg Vaughn!
gvaughn@gmail.com!
twitter: @gregvaughn, github/irc: gvaughn
Student of Elixir and OTP!
Hobbying with Elixir almost 13 months!
Texan!
Professional Programmer of 20 years!
Across 6 languages!
Employed by LivingSocial
Student of Elixir and OTP!
Hobbying with Elixir almost 13 months!
Texan!
Professional Programmer of 20 years!
Across 6 languages!
Employed by LivingSocial
LivingSocial is Hiring!
OTP is …
OTP is …
Mature / Battle Tested for 16 (18?) years
OTP is …
Mature / Battle Tested for 16 (18?) years
Microservices
OTP is …
Mature / Battle Tested for 16 (18?) years
Microservices
Object Oriented (NOT class oriented)
OTP is …
Mature / Battle Tested for 16 (18?) years
Microservices
Object Oriented (NOT class oriented)
Actor
OTP is …
Mature / Battle Tested for 16 (18?) years
Microservices
Object Oriented (NOT class oriented)
Actor
Framework (Hollywood Principle)
OTP is …
Mature / Battle Tested for 16 (18?) years
Microservices
Object Oriented (NOT class oriented)
Actor
Framework (Hollywood Principle)
Design Patterns
OTP is …
Mature / Battle Tested for 16 (18?) years
Microservices
Object Oriented (NOT class oriented)
Actor
Framework (Hollywood Principle)
Design Patterns
Robust
object oriented
OOP to me means only messaging, local
retention and protection and !
hiding of state-process, and extreme
late-binding of all things. — Alan Kay
object oriented
OOP to me means only messaging, local
retention and protection and !
hiding of state-process, and extreme
late-binding of all things. — Alan Kay
functional
a style of building the structure and elements of
computer programs that treats computation as
the evaluation of mathematical functions and
avoids state and mutable data. — Wikipedia
object oriented
OOP to me means only messaging, local
retention and protection and !
hiding of state-process, and extreme
late-binding of all things. — Alan Kay
functional
a style of building the structure and elements of
computer programs that treats computation as
the evaluation of mathematical functions and
avoids state and mutable data. — Wikipedia
concurrent
The conceptually simultaneous
execution of more than one sequential
program on a computer or network of
computers. — McGraw-Hill Sci & Tech
Dictionary
object oriented functional
concurrent
actors
Behaviours: Don’t call us, we’ll call you
defmodule MyCallback do
use GenServer
end
iex> {:ok, pid} = GenServer.start(MyCallback, [])
Behaviours: Don’t call us, we’ll call you
defmodule MyCallback do
use GenServer
end
iex> {:ok, pid} = GenServer.start(MyCallback, [])
defmodule GenServer do
defmacro __using__(_) do
    quote do
      @behaviour :gen_server
!
      def init(args), do: {:ok, args}
!
     def handle_cast(msg, state), do: {:stop, {:bad_cast, msg}, state}
!
      def handle_call(msg, _from, state), do: {:stop, {:bad_call, msg}, state}
!
      def handle_info(_msg, state), do: {:noreply, state}
!
      def terminate(_reason, _state), do: :ok
!
      def code_change(_old, state, _extra), do: {:ok, state}
!
      defoverridable [init: 1, handle_call: 3, handle_info: 2,
                      handle_cast: 2, terminate: 2, code_change: 3]
    end
  end
…
end
defmodule MyCallback do
use GenServer
@initial_state %{}
!
def start_link do
GenServer.start_link(__MODULE__, @initial_state)
end
!
def init(arg) do
state = arg
{:ok, state}
end
!
def do_it(pid, param) do
GenServer.call(pid, {:do_it, param})
end
!
def handle_call({:do_it, param}, _from, state) do
payload = get_payload(param, state)
new_state = update_state(param, state)
{:reply, payload, new_state}
end
!
defp get_payload(param, state), do: “I DONE DID IT!”
!
defp update_state(param, state), do: state
end
defmodule MyCallback do
use GenServer
@initial_state %{}
!
def start_link do
GenServer.start_link(__MODULE__, @initial_state)
end
!
def init(arg) do
state = arg
{:ok, state}
end
!
def do_it(pid, param) do
GenServer.call(pid, {:do_it, param})
end
!
def handle_call({:do_it, param}, _from, state) do
payload = get_payload(param, state)
new_state = update_state(param, state)
{:reply, payload, new_state}
end
!
defp get_payload(param, state), do: “I DONE DID IT!”
!
defp update_state(param, state), do: state
end
defmodule MyCallback do
use GenServer
@initial_state %{}
!
def start_link do
GenServer.start_link(__MODULE__, @initial_state)
end
!
def init(arg) do
state = arg
{:ok, state}
end
!
def do_it(pid, param) do
GenServer.call(pid, {:do_it, param})
end
!
def handle_call({:do_it, param}, _from, state) do
payload = get_payload(param, state)
new_state = update_state(param, state)
{:reply, payload, new_state}
end
!
defp get_payload(param, state), do: “I DONE DID IT!”
!
defp update_state(param, state), do: state
end
defmodule MyCallback do
use GenServer
@initial_state %{}
!
def start_link do
GenServer.start_link(__MODULE__, @initial_state)
end
!
def init(arg) do
state = arg
{:ok, state}
end
!
def do_it(pid, param) do
GenServer.call(pid, {:do_it, param})
end
!
def handle_call({:do_it, param}, _from, state) do
payload = get_payload(param, state)
new_state = update_state(param, state)
{:reply, payload, new_state}
end
!
defp get_payload(param, state), do: “I DONE DID IT!”
!
defp update_state(param, state), do: state
end
defmodule MyCallback do
use GenServer
@initial_state %{}
!
def start_link do
GenServer.start_link(__MODULE__, @initial_state)
end
!
def init(arg) do
state = arg
{:ok, state}
end
!
def do_it(pid, param) do
GenServer.call(pid, {:do_it, param})
end
!
def handle_call({:do_it, param}, _from, state) do
payload = get_payload(param, state)
new_state = update_state(param, state)
{:reply, payload, new_state}
end
!
defp get_payload(param, state), do: “I DONE DID IT!”
!
defp update_state(param, state), do: state
end
ClientProcess
ServerProcess
Elevators 101
A rider on any floor presses the up or down button!
An elevator car arrives!
Rider enters and presses a destination floor button
rider
hall!
signal
hall!
signal
car
carrider
floor hail
retrieve
arrival
arrival
go to
A rider on any floor presses the up or down button!
An elevator car arrives!
Rider enters and presses a destination floor button
rider
hall!
signal
hall!
signal
car
carrider
floor hail
retrieve
arrival
arrival
go to
Hail
struct
Show Me The Code
Let It Fail … and Respond
Separation of Concerns!
Think Long and Hard about
Failure Response!
BEAM (not OS) Processes!
Finer Grained Control
Prepare to Fail
Car!
Supervisor
Car 1 Car n…
one_for_one
Prepare to Fail
Car!
Supervisor
Car 1 Car n…
one_for_one
Hall!
Signal
Prepare to Fail
Car!
Supervisor
Car 1 Car n…
one_for_one
Gen!
Event
Hall!
Signal
Prepare to Fail
Car!
Supervisor
Car 1 Car n…
one_for_one
Gen!
Event
Hall!
Signal
Bank!
Supervisor
rest_for_one
Prepare to Fail
Gen!
Event
HS
Bank A!
Supervisor
CS
Gen!
Event
HS
Bank B!
Supervisor
CS
Elevator!
Supervisor
one_for_one
Prepare to Fail
Gen!
Event
HS
Bank A!
Supervisor
CS
Gen!
Event
HS
Bank B!
Supervisor
CS
Elevator!
Supervisor
one_for_one
Gen
Event
Gen
Event
Don’t Trip
defmodule MySupervisor do
use Supervisor
!
def init(…) do
workers = worker(MyCallback, [p1, p2, [name: :myc]], [id: :mine])
supervise(workers, strategy: one_for_one)
end
end
!
defmodule MyCallback do
use GenServer
!
def start_link(p1, p2, opts  [])
GenServer.start_link(__MODULE__, [p1, p2], opts)
end
!
def init([p1, p2]) do
{:ok, %{p1: p1, p2: p2}}
end
end
Don’t Trip
defmodule MySupervisor do
use Supervisor
!
def init(…) do
workers = worker(MyCallback, [p1, p2, [name: :myc]], [id: :mine])
supervise(workers, strategy: one_for_one)
end
end
!
defmodule MyCallback do
use GenServer
!
def start_link(p1, p2, opts  [])
GenServer.start_link(__MODULE__, [p1, p2], opts)
end
!
def init([p1, p2]) do
{:ok, %{p1: p1, p2: p2}}
end
end
apply: list of params
Don’t Trip
defmodule MySupervisor do
use Supervisor
!
def init(…) do
workers = worker(MyCallback, [p1, p2, [name: :myc]], [id: :mine])
supervise(workers, strategy: one_for_one)
end
end
!
defmodule MyCallback do
use GenServer
!
def start_link(p1, p2, opts  [])
GenServer.start_link(__MODULE__, [p1, p2], opts)
end
!
def init([p1, p2]) do
{:ok, %{p1: p1, p2: p2}}
end
end
apply: list of params
single term for init/1
Trip-less Convention?
defmodule MySupervisor do
use Supervisor
!
def init(…) do
workers = worker(MyCallback, [{p1, p2}, name: :myc], [id: :mine])
supervise(workers, strategy: one_for_one)
end
end
!
defmodule MyCallback do
use GenServer
!
def start_link(init_params, opts  [])
GenServer.start_link(__MODULE__, init_params, opts)
end
!
def init({p1, p2}) do
{:ok, %{p1: p1, p2: p2}}
end
end
Show Me The Code
Takeaways
Behaviours vs. Callback Modules!
Watch your initialization steps!
Watch parameter and return value contracts!
Supervisors and Strategies!
Config
Thank you
Elixir Elevated!
The Ups and Downs of OTP!
!
Greg Vaughn!
!
gvaughn@gmail.com!
twitter: @gregvaughn!
github/irc: gvaughn
http://github.com/gvaughn/elixir_elevated/tree/elixirconf2014

More Related Content

PPTX
200 Days of Code, Beginner Track, Month 5
PPT
You promise?
PPTX
PDF
Don't Be STUPID, Grasp SOLID - DrupalCon Prague
PDF
Gtg12
PDF
Excellent
PDF
Elixir and OTP
200 Days of Code, Beginner Track, Month 5
You promise?
Don't Be STUPID, Grasp SOLID - DrupalCon Prague
Gtg12
Excellent
Elixir and OTP

Viewers also liked (20)

PDF
otp-sms-two-factor-authentication
PPTX
QCon - 一次 Clojure Web 编程实战
PDF
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PDF
Java 与 CPU 高速缓存
PDF
PDF
Phoenix demysitify, with fun
PDF
Concurrency in Elixir with OTP
PPT
Let It Crash (@pavlobaron)
PDF
Elixir introd
PDF
Introducing Elixir the easy way
PDF
Elixir & Phoenix – fast, concurrent and explicit
PPT
Simple Two Factor Authentication
PDF
Erlang scheduler
PDF
Bottleneck in Elixir Application - Alexey Osipenko
ODP
Elixir basics
PDF
Erlang - Concurrent Language for Concurrent World
PDF
1 hour dive into Erlang/OTP
PDF
Node.jsエンジニア Erlangに入門するの巻
PPT
Erlang OTP
PDF
Learn Elixir at Manchester Lambda Lounge
otp-sms-two-factor-authentication
QCon - 一次 Clojure Web 编程实战
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
Java 与 CPU 高速缓存
Phoenix demysitify, with fun
Concurrency in Elixir with OTP
Let It Crash (@pavlobaron)
Elixir introd
Introducing Elixir the easy way
Elixir & Phoenix – fast, concurrent and explicit
Simple Two Factor Authentication
Erlang scheduler
Bottleneck in Elixir Application - Alexey Osipenko
Elixir basics
Erlang - Concurrent Language for Concurrent World
1 hour dive into Erlang/OTP
Node.jsエンジニア Erlangに入門するの巻
Erlang OTP
Learn Elixir at Manchester Lambda Lounge
Ad

Similar to Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014 (20)

PDF
Rails OO views
PPTX
Ultimate Node.js countdown: the coolest Application Express examples
PDF
Elixir/OTP for PHP developers
PDF
High Performance web apps in Om, React and ClojureScript
PDF
Functional Reactive Programming / Compositional Event Systems
PDF
Advanced Topics in Continuous Deployment
PDF
Re-Design with Elixir/OTP
PDF
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
PDF
Achievement Unlocked: Drive development, increase velocity, and write blissfu...
PDF
iOS 개발자의 Flutter 체험기
PPT
Goodparts
PDF
Let it crash - fault tolerance in Elixir/OTP
PDF
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
PDF
RubyConf Portugal 2014 - Why ruby must go!
PDF
N Things You Don't Want to Repeat in React Native
PPTX
PPTX
Design Patterns Summer Course 2010-2011 - Session#1
KEY
SOLID Ruby, SOLID Rails
ODP
Clojure: Practical functional approach on JVM
PDF
Why scala is not my ideal language and what I can do with this
Rails OO views
Ultimate Node.js countdown: the coolest Application Express examples
Elixir/OTP for PHP developers
High Performance web apps in Om, React and ClojureScript
Functional Reactive Programming / Compositional Event Systems
Advanced Topics in Continuous Deployment
Re-Design with Elixir/OTP
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
Achievement Unlocked: Drive development, increase velocity, and write blissfu...
iOS 개발자의 Flutter 체험기
Goodparts
Let it crash - fault tolerance in Elixir/OTP
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
RubyConf Portugal 2014 - Why ruby must go!
N Things You Don't Want to Repeat in React Native
Design Patterns Summer Course 2010-2011 - Session#1
SOLID Ruby, SOLID Rails
Clojure: Practical functional approach on JVM
Why scala is not my ideal language and what I can do with this
Ad

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
history of c programming in notes for students .pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Introduction to Artificial Intelligence
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Transform Your Business with a Software ERP System
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
top salesforce developer skills in 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
history of c programming in notes for students .pptx
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Wondershare Filmora 15 Crack With Activation Key [2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Introduction to Artificial Intelligence
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Transform Your Business with a Software ERP System
Navsoft: AI-Powered Business Solutions & Custom Software Development
Operating system designcfffgfgggggggvggggggggg
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014

  • 1. Elixir Elevated! The Ups and Downs of OTP Greg Vaughn! gvaughn@gmail.com! twitter: @gregvaughn, github/irc: gvaughn
  • 2. Student of Elixir and OTP! Hobbying with Elixir almost 13 months! Texan! Professional Programmer of 20 years! Across 6 languages! Employed by LivingSocial
  • 3. Student of Elixir and OTP! Hobbying with Elixir almost 13 months! Texan! Professional Programmer of 20 years! Across 6 languages! Employed by LivingSocial LivingSocial is Hiring!
  • 5. OTP is … Mature / Battle Tested for 16 (18?) years
  • 6. OTP is … Mature / Battle Tested for 16 (18?) years Microservices
  • 7. OTP is … Mature / Battle Tested for 16 (18?) years Microservices Object Oriented (NOT class oriented)
  • 8. OTP is … Mature / Battle Tested for 16 (18?) years Microservices Object Oriented (NOT class oriented) Actor
  • 9. OTP is … Mature / Battle Tested for 16 (18?) years Microservices Object Oriented (NOT class oriented) Actor Framework (Hollywood Principle)
  • 10. OTP is … Mature / Battle Tested for 16 (18?) years Microservices Object Oriented (NOT class oriented) Actor Framework (Hollywood Principle) Design Patterns
  • 11. OTP is … Mature / Battle Tested for 16 (18?) years Microservices Object Oriented (NOT class oriented) Actor Framework (Hollywood Principle) Design Patterns Robust
  • 12. object oriented OOP to me means only messaging, local retention and protection and ! hiding of state-process, and extreme late-binding of all things. — Alan Kay
  • 13. object oriented OOP to me means only messaging, local retention and protection and ! hiding of state-process, and extreme late-binding of all things. — Alan Kay functional a style of building the structure and elements of computer programs that treats computation as the evaluation of mathematical functions and avoids state and mutable data. — Wikipedia
  • 14. object oriented OOP to me means only messaging, local retention and protection and ! hiding of state-process, and extreme late-binding of all things. — Alan Kay functional a style of building the structure and elements of computer programs that treats computation as the evaluation of mathematical functions and avoids state and mutable data. — Wikipedia concurrent The conceptually simultaneous execution of more than one sequential program on a computer or network of computers. — McGraw-Hill Sci & Tech Dictionary
  • 16. Behaviours: Don’t call us, we’ll call you defmodule MyCallback do use GenServer end iex> {:ok, pid} = GenServer.start(MyCallback, [])
  • 17. Behaviours: Don’t call us, we’ll call you defmodule MyCallback do use GenServer end iex> {:ok, pid} = GenServer.start(MyCallback, []) defmodule GenServer do defmacro __using__(_) do     quote do       @behaviour :gen_server !       def init(args), do: {:ok, args} !      def handle_cast(msg, state), do: {:stop, {:bad_cast, msg}, state} !       def handle_call(msg, _from, state), do: {:stop, {:bad_call, msg}, state} !       def handle_info(_msg, state), do: {:noreply, state} !       def terminate(_reason, _state), do: :ok !       def code_change(_old, state, _extra), do: {:ok, state} !       defoverridable [init: 1, handle_call: 3, handle_info: 2,                       handle_cast: 2, terminate: 2, code_change: 3]     end   end … end
  • 18. defmodule MyCallback do use GenServer @initial_state %{} ! def start_link do GenServer.start_link(__MODULE__, @initial_state) end ! def init(arg) do state = arg {:ok, state} end ! def do_it(pid, param) do GenServer.call(pid, {:do_it, param}) end ! def handle_call({:do_it, param}, _from, state) do payload = get_payload(param, state) new_state = update_state(param, state) {:reply, payload, new_state} end ! defp get_payload(param, state), do: “I DONE DID IT!” ! defp update_state(param, state), do: state end
  • 19. defmodule MyCallback do use GenServer @initial_state %{} ! def start_link do GenServer.start_link(__MODULE__, @initial_state) end ! def init(arg) do state = arg {:ok, state} end ! def do_it(pid, param) do GenServer.call(pid, {:do_it, param}) end ! def handle_call({:do_it, param}, _from, state) do payload = get_payload(param, state) new_state = update_state(param, state) {:reply, payload, new_state} end ! defp get_payload(param, state), do: “I DONE DID IT!” ! defp update_state(param, state), do: state end
  • 20. defmodule MyCallback do use GenServer @initial_state %{} ! def start_link do GenServer.start_link(__MODULE__, @initial_state) end ! def init(arg) do state = arg {:ok, state} end ! def do_it(pid, param) do GenServer.call(pid, {:do_it, param}) end ! def handle_call({:do_it, param}, _from, state) do payload = get_payload(param, state) new_state = update_state(param, state) {:reply, payload, new_state} end ! defp get_payload(param, state), do: “I DONE DID IT!” ! defp update_state(param, state), do: state end
  • 21. defmodule MyCallback do use GenServer @initial_state %{} ! def start_link do GenServer.start_link(__MODULE__, @initial_state) end ! def init(arg) do state = arg {:ok, state} end ! def do_it(pid, param) do GenServer.call(pid, {:do_it, param}) end ! def handle_call({:do_it, param}, _from, state) do payload = get_payload(param, state) new_state = update_state(param, state) {:reply, payload, new_state} end ! defp get_payload(param, state), do: “I DONE DID IT!” ! defp update_state(param, state), do: state end
  • 22. defmodule MyCallback do use GenServer @initial_state %{} ! def start_link do GenServer.start_link(__MODULE__, @initial_state) end ! def init(arg) do state = arg {:ok, state} end ! def do_it(pid, param) do GenServer.call(pid, {:do_it, param}) end ! def handle_call({:do_it, param}, _from, state) do payload = get_payload(param, state) new_state = update_state(param, state) {:reply, payload, new_state} end ! defp get_payload(param, state), do: “I DONE DID IT!” ! defp update_state(param, state), do: state end ClientProcess ServerProcess
  • 24. A rider on any floor presses the up or down button! An elevator car arrives! Rider enters and presses a destination floor button rider hall! signal hall! signal car carrider floor hail retrieve arrival arrival go to
  • 25. A rider on any floor presses the up or down button! An elevator car arrives! Rider enters and presses a destination floor button rider hall! signal hall! signal car carrider floor hail retrieve arrival arrival go to Hail struct
  • 26. Show Me The Code
  • 27. Let It Fail … and Respond Separation of Concerns! Think Long and Hard about Failure Response! BEAM (not OS) Processes! Finer Grained Control
  • 28. Prepare to Fail Car! Supervisor Car 1 Car n… one_for_one
  • 29. Prepare to Fail Car! Supervisor Car 1 Car n… one_for_one Hall! Signal
  • 30. Prepare to Fail Car! Supervisor Car 1 Car n… one_for_one Gen! Event Hall! Signal
  • 31. Prepare to Fail Car! Supervisor Car 1 Car n… one_for_one Gen! Event Hall! Signal Bank! Supervisor rest_for_one
  • 32. Prepare to Fail Gen! Event HS Bank A! Supervisor CS Gen! Event HS Bank B! Supervisor CS Elevator! Supervisor one_for_one
  • 33. Prepare to Fail Gen! Event HS Bank A! Supervisor CS Gen! Event HS Bank B! Supervisor CS Elevator! Supervisor one_for_one Gen Event Gen Event
  • 34. Don’t Trip defmodule MySupervisor do use Supervisor ! def init(…) do workers = worker(MyCallback, [p1, p2, [name: :myc]], [id: :mine]) supervise(workers, strategy: one_for_one) end end ! defmodule MyCallback do use GenServer ! def start_link(p1, p2, opts []) GenServer.start_link(__MODULE__, [p1, p2], opts) end ! def init([p1, p2]) do {:ok, %{p1: p1, p2: p2}} end end
  • 35. Don’t Trip defmodule MySupervisor do use Supervisor ! def init(…) do workers = worker(MyCallback, [p1, p2, [name: :myc]], [id: :mine]) supervise(workers, strategy: one_for_one) end end ! defmodule MyCallback do use GenServer ! def start_link(p1, p2, opts []) GenServer.start_link(__MODULE__, [p1, p2], opts) end ! def init([p1, p2]) do {:ok, %{p1: p1, p2: p2}} end end apply: list of params
  • 36. Don’t Trip defmodule MySupervisor do use Supervisor ! def init(…) do workers = worker(MyCallback, [p1, p2, [name: :myc]], [id: :mine]) supervise(workers, strategy: one_for_one) end end ! defmodule MyCallback do use GenServer ! def start_link(p1, p2, opts []) GenServer.start_link(__MODULE__, [p1, p2], opts) end ! def init([p1, p2]) do {:ok, %{p1: p1, p2: p2}} end end apply: list of params single term for init/1
  • 37. Trip-less Convention? defmodule MySupervisor do use Supervisor ! def init(…) do workers = worker(MyCallback, [{p1, p2}, name: :myc], [id: :mine]) supervise(workers, strategy: one_for_one) end end ! defmodule MyCallback do use GenServer ! def start_link(init_params, opts []) GenServer.start_link(__MODULE__, init_params, opts) end ! def init({p1, p2}) do {:ok, %{p1: p1, p2: p2}} end end
  • 38. Show Me The Code
  • 39. Takeaways Behaviours vs. Callback Modules! Watch your initialization steps! Watch parameter and return value contracts! Supervisors and Strategies! Config
  • 40. Thank you Elixir Elevated! The Ups and Downs of OTP! ! Greg Vaughn! ! gvaughn@gmail.com! twitter: @gregvaughn! github/irc: gvaughn http://github.com/gvaughn/elixir_elevated/tree/elixirconf2014