SlideShare a Scribd company logo
{
Erlang and gen_fsm
@dieswaytoofast
(V.P. Ubiquiti Networks)
Finite State Machines - Why the fear?
The Business
Finite State Machines - Why the fear?
The Metrics
 Phone Calls per Second
The Metrics
 Phone Calls per Second
The Metrics
x 1000
 Simultaneous Phone Calls
The Metrics
 Simultaneous Phone Calls
The Metrics
x 10,000
 HTTP API requests
The Metrics
 HTTP API requests
The Metrics
x ∞
 Self-hosted (kinda)
 Voice Response
Call Handling
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
 Call Routing
Call Handling
dial_in
Check
Blacklist
get_endpoint conference Play Error
Hangupauto_attendant
dial_in_fml conference
init
Check node
Check
Blacklist
Cancelled Blacklisted Next Endpoint Collections Unknown
Move node
Auto Attendant FML Voicemail FaxConference
 Self-hosted (kinda)
Bet the farm moment
Finite State Machines - Why the fear?
ERLANG!!!
 Concurrency
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
 Fault identification
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
 Fault identification
 Code upgrade
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
 Fault identification
 Code upgrade
 Stable Storage
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
Erlang
Concurrency Hell
My Blue Heaven My Blue Heaven
Erlang
Concurrency Hell
My Blue Heaven
Deep Problems
My Blue Heaven
Deep Problems
 gen_server
Behaviours
 gen_server
 gen_tcp
Behaviours
 gen_server
 gen_tcp
 gen_event
Behaviours
 gen_server
 gen_tcp
 gen_event
 gen_fsm
Behaviours
 gen_server
 gen_tcp
 gen_event
 gen_fsm
 …
Behaviours
 gen_server
 gen_tcp
 gen_event
 gen_fsm
 …
Behaviours
 A System has States
Finite State Machines
asleepStart
out of
bed
Coffee!!
 A System has States
 States transition
Finite State Machines
asleepStart
out of
bed
Coffee!!
 A System has States
 States transition
 Transitions are Atomic
Finite State Machines
asleepStart
out of
bed
Coffee!!
NOTHING HERE
 A System has States
 States transition
 Transitions are Atomic
 Events at Entry and Exit
Finite State Machines
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
Finite State Machines - Why the fear?
asleepStart
out of
bed
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
asleepStart
out of
bed
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
HUH?
Finite State Machines - Why the fear?
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
W
00t!
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
 Everything is an FSM
Finite State Machines
 Everything is an FSM
Finite State Machines
COM
PLEXITY?
 Everything is an FSM
Finite State Machines
ENCAPSULATION!
 Voice Response
Finite State Machines
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
 Voice Response
Finite State Machines
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
 Voice Response
Finite State Machines
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
ENCAPSULATION!
Encapsulation
Concurrency Hell
My Blue Heaven
Deep Problems
My Blue Heaven
Deep Problems
 Call Routing
Finite State Machines
dial_in
Check
Blacklist
get_endpoint conference Play Error
Hangupauto_attendant
dial_in_fml conference
init
Check node
Check
Blacklist
Cancelled Blacklisted Next Endpoint Collections Unknown
Move node
Auto Attendant FML Voicemail FaxConference
 Templates are your friend
 So are BIG sheets of paper
 Think “Real World”
The Bottom Line
Finite State Machines - Why the fear?

More Related Content

PDF
Open Source Automotive Development
PDF
UNIDADES BÁSICAS DE LA FÍSICA
DOCX
Brain drain
PPSX
Say a little prayer
DOC
Libro analisis y diseño estructurado (completo)
PDF
Catalogo1 fernando
PPSX
La barra de dibujo
PPTX
Material didáctico
Open Source Automotive Development
UNIDADES BÁSICAS DE LA FÍSICA
Brain drain
Say a little prayer
Libro analisis y diseño estructurado (completo)
Catalogo1 fernando
La barra de dibujo
Material didáctico

Viewers also liked (16)

PPTX
Temática del blog
PDF
Marlon ernesto
PPTX
Emprendimiento pg 59
PDF
Capítulo 4 libro zacatollan una hist... copia
PDF
NUBE ELECTRÓNICA
PDF
Untitled presentation
PDF
Presentacion enviroo institucional_abril2012
PPTX
Precio
PDF
Mito ediporeyequipo2
DOCX
La guitarra
PDF
ORACIONES AL PADRE
PPTX
web 1.0 vs web 2.0
PDF
12 errores con hijos
PDF
Curso comunicación y marketing
PPTX
Clase demostrativa
PPS
Kiss and say.....pps by d.
Temática del blog
Marlon ernesto
Emprendimiento pg 59
Capítulo 4 libro zacatollan una hist... copia
NUBE ELECTRÓNICA
Untitled presentation
Presentacion enviroo institucional_abril2012
Precio
Mito ediporeyequipo2
La guitarra
ORACIONES AL PADRE
web 1.0 vs web 2.0
12 errores con hijos
Curso comunicación y marketing
Clase demostrativa
Kiss and say.....pps by d.
Ad

More from OSCON Byrum (20)

PDF
OSCON 2013 - Planning an OpenStack Cloud - Tom Fifield
PDF
Protecting Open Innovation with the Defensive Patent License
PDF
Using Cascalog to build an app with City of Palo Alto Open Data
PPTX
How we built our community using Github - Uri Cohen
PDF
The Vanishing Pattern: from iterators to generators in Python
PDF
Distributed Coordination with Python
PDF
An overview of open source in East Asia (China, Japan, Korea)
PPTX
Oscon 2013 Jesse Anderson
PDF
US Patriot Act OSCON2012 David Mertz
PPTX
OSCON 2012 US Patriot Act Implications for Cloud Computing - Diane Mueller, A...
PPTX
Big Data for each one of us
KEY
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
PDF
Declarative web data visualization using ClojureScript
PDF
Using and Building Open Source in Google Corporate Engineering - Justin McWil...
PDF
A Look at the Network: Searching for Truth in Distributed Applications
PPT
Life After Sharding: Monitoring and Management of a Complex Data Cloud
PPT
Faster! Faster! Accelerate your business with blazing prototypes
PDF
Comparing open source private cloud platforms
PDF
State of the Art Web Mapping with Open Source
PDF
Building an Ecosystem of FLOSS to Educate Students with Disabilities
OSCON 2013 - Planning an OpenStack Cloud - Tom Fifield
Protecting Open Innovation with the Defensive Patent License
Using Cascalog to build an app with City of Palo Alto Open Data
How we built our community using Github - Uri Cohen
The Vanishing Pattern: from iterators to generators in Python
Distributed Coordination with Python
An overview of open source in East Asia (China, Japan, Korea)
Oscon 2013 Jesse Anderson
US Patriot Act OSCON2012 David Mertz
OSCON 2012 US Patriot Act Implications for Cloud Computing - Diane Mueller, A...
Big Data for each one of us
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
Declarative web data visualization using ClojureScript
Using and Building Open Source in Google Corporate Engineering - Justin McWil...
A Look at the Network: Searching for Truth in Distributed Applications
Life After Sharding: Monitoring and Management of a Complex Data Cloud
Faster! Faster! Accelerate your business with blazing prototypes
Comparing open source private cloud platforms
State of the Art Web Mapping with Open Source
Building an Ecosystem of FLOSS to Educate Students with Disabilities
Ad

Recently uploaded (20)

PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Modernizing your data center with Dell and AMD
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Advanced IT Governance
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Modernizing your data center with Dell and AMD
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
GamePlan Trading System Review: Professional Trader's Honest Take
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Advanced IT Governance
Diabetes mellitus diagnosis method based random forest with bat algorithm

Finite State Machines - Why the fear?

Editor's Notes

  • #3: So, I started a phone company. It was a great thing. Phones make people happy, right?
  • #4: Yeah. Kids. Don’t do this at home. Don’t start a phone company.
  • #5: But I did. Hosted phone services for SMBs. Vonage for small businesses. In the cloud. Awesome
  • #8: 3 orders of magnitude
  • #10: 4 orders of magnitude
  • #12: Infinity!
  • #13: Houston – we have a problem
  • #14: Consider the simplest case of handling a call
  • #15: It actually gets a lot more complex
  • #16: And eventually, a *lot* more complex
  • #17: To put it differently,It was a “bet the farm” moment
  • #18: And it basically involved a lot of beer
  • #19: And we rewrote the whole damn thing in Erlang. WhyErlang? Well, Fault Tolerance, basicallyAnd oh, I’m not putting Kirk up there. That’s too obvious.
  • #20: The Six Essential Characteristics of a Fault Tolerant System
  • #21: The Six Essential Characteristics of a Fault Tolerant System
  • #22: The Six Essential Characteristics of a Fault Tolerant System
  • #23: The Six Essential Characteristics of a Fault Tolerant System
  • #24: The Six Essential Characteristics of a Fault Tolerant System
  • #25: The Six Essential Characteristics of a Fault Tolerant System
  • #26: ‘Distributed’ problems mean you spend a huge chunk of your time dealing with theadminstrivia of distribution.With erlang you get that for free!
  • #27: Ok, not really true. You still have to deal with ‘deep problems’ (hard core parallelization issues, etc.)But you’d have to deal with that anyhow!
  • #28: Implement the server part of a client/server relationship
  • #29: Talk to tcp over sockets
  • #30: Event handling
  • #31: Finite state machines
  • #32: And a bunch more (gen_udp, gen_utp!, etc.)
  • #33: But, we’re talking about Finite State Machines
  • #34: Lets talk about FSMs
  • #42: Putting this into practice, here is some code
  • #43: A system has states
  • #44: When certain events show up
  • #45: You do something
  • #46: And transition to the next state
  • #47: Wait, WHUT? Where did the “events” come from?
  • #48: I’m glad you asked  more code
  • #49: And thusly an event is sent
  • #50: Voila, an ErlangFSM
  • #51: 2.0 is anightmare; Stick w/ 1.0
  • #52: A system has states
  • #53: Events and transitions
  • #54: The code
  • #55: The states
  • #57: When you receive an event
  • #58: try to do something
  • #59: If it works go to the next state
  • #61: If it fails, go to a differen state
  • #62: Thusly
  • #63: And now for the events
  • #68: But wait! What if you walk out partway?
  • #69: So, a wee bit triclyhere -
  • #70: We have a timeout
  • #71: And it tells you where to go after the timeout
  • #72: And, you’re done.
  • #73: Lets look at this as a ‘real world” thingy
  • #74: But, you say, BUT, what about the complexity of dealing with FSMs? They’re big! And unweildy!
  • #75: Nah. They aren’t. Not in Erlang
  • #76: Remember this? It was a PITA? Actually, a small part of a PITA?
  • #77: But each one is tightly encapsulated, and clean.It’s the Erlang Way
  • #78: But each one is tightly encapsulated, and clean.It’s the Erlang Way
  • #79: My fanciful slides are actually real. This actually happens.
  • #80: And it’s the same for everything else I showed. FSMs of FSMs.
  • #81: An FSM of FSMs of FSMsBuilding these out “correctly”, in real time, is (was!) trivial
  • #82: “Real World”  Business Rules can help. (VM,syncrhonziation)