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

Viewers also liked

otp-sms-two-factor-authentication
otp-sms-two-factor-authenticationotp-sms-two-factor-authentication
otp-sms-two-factor-authentication
Nikos Ioannou 123RF.com
 
QCon - 一次 Clojure Web 编程实战
QCon - 一次 Clojure Web 编程实战QCon - 一次 Clojure Web 编程实战
QCon - 一次 Clojure Web 编程实战
dennis zhuang
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks
 
Java 与 CPU 高速缓存
Java 与 CPU 高速缓存Java 与 CPU 高速缓存
Java 与 CPU 高速缓存
dennis zhuang
 
Elixir
ElixirElixir
Phoenix demysitify, with fun
Phoenix demysitify, with funPhoenix demysitify, with fun
Phoenix demysitify, with fun
Tai An Su
 
Concurrency in Elixir with OTP
Concurrency in Elixir with OTPConcurrency in Elixir with OTP
Concurrency in Elixir with OTP
Justin Reese
 
Let It Crash (@pavlobaron)
Let It Crash (@pavlobaron)Let It Crash (@pavlobaron)
Let It Crash (@pavlobaron)
Pavlo Baron
 
Elixir introd
Elixir introdElixir introd
Elixir introd
dennis zhuang
 
Introducing Elixir the easy way
Introducing Elixir the easy wayIntroducing Elixir the easy way
Introducing Elixir the easy way
Tobias Pfeiffer
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Simple Two Factor Authentication
Simple Two Factor AuthenticationSimple Two Factor Authentication
Simple Two Factor Authentication
John Congdon
 
Erlang scheduler
Erlang schedulerErlang scheduler
Erlang scheduler
dennis zhuang
 
Bottleneck in Elixir Application - Alexey Osipenko
 Bottleneck in Elixir Application - Alexey Osipenko  Bottleneck in Elixir Application - Alexey Osipenko
Bottleneck in Elixir Application - Alexey Osipenko
Elixir Club
 
Elixir basics
Elixir basicsElixir basics
Elixir basics
Ruben Amortegui
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
Zvi Avraham
 
1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP
Jordi Llonch
 
Node.jsエンジニア Erlangに入門するの巻
Node.jsエンジニア Erlangに入門するの巻Node.jsエンジニア Erlangに入門するの巻
Node.jsエンジニア Erlangに入門するの巻
Recruit Technologies
 
Erlang OTP
Erlang OTPErlang OTP
Erlang OTP
Zvi Avraham
 
Learn Elixir at Manchester Lambda Lounge
Learn Elixir at Manchester Lambda LoungeLearn Elixir at Manchester Lambda Lounge
Learn Elixir at Manchester Lambda Lounge
Chi-chi Ekweozor
 

Viewers also liked (20)

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

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

Rails OO views
Rails OO viewsRails OO views
Rails OO views
Elia Schito
 
Ultimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examplesUltimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examples
Alan Arentsen
 
Elixir/OTP for PHP developers
Elixir/OTP for PHP developersElixir/OTP for PHP developers
Elixir/OTP for PHP developers
Ignacio Martín
 
High Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptHigh Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScript
Leonardo Borges
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
 
Advanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentAdvanced Topics in Continuous Deployment
Advanced Topics in Continuous Deployment
Mike Brittain
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTP
Mustafa TURAN
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichDC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
SmartLogic
 
Achievement Unlocked: Drive development, increase velocity, and write blissfu...
Achievement Unlocked: Drive development, increase velocity, and write blissfu...Achievement Unlocked: Drive development, increase velocity, and write blissfu...
Achievement Unlocked: Drive development, increase velocity, and write blissfu...
All Things Open
 
iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기
Wanbok Choi
 
Goodparts
GoodpartsGoodparts
Goodparts
damonjablons
 
Let it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTPLet it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTP
Maciej Kaszubowski
 
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
ElixirConf 2019 - Your Guide to Understand the Initial Commit of a Phoenix Pr...
Jorge Bejar
 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
Gautam Rege
 
N Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React NativeN Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React Native
Anton Kulyk
 
Erlang FTW!
Erlang FTW!Erlang FTW!
Design Patterns Summer Course 2010-2011 - Session#1
Design Patterns Summer Course 2010-2011 - Session#1Design Patterns Summer Course 2010-2011 - Session#1
Design Patterns Summer Course 2010-2011 - Session#1
Muhamad Hesham
 
SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
Jens-Christian Fischer
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
sunng87
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
Ruslan Shevchenko
 

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

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

Recently uploaded

Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 

Recently uploaded (20)

Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 

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