finite state machines - why the fear?
DESCRIPTION
Finite State Machines are overlooked at best, ignored at worst, and virtually always dismissed. This is tragic since FSMs are not just about Door Locks (the most commonly used example). On the contrary, these FSMs are invaluable in clearly defining communication protocols – ranging from low-level web-services through complex telephony application to reliable interactions between loosely-coupled systems. Properly using them can significantly enhance the stability and reliability of your systems. Join me as I take you through a crash-course in FSMs, using erlang’s gen_fsm behavior as the background, and hopefully leaving you with a better appreciation of both FSM and erlang in the process.TRANSCRIPT
![Page 1: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/1.jpg)
{
Erlang and gen_fsm
@dieswaytoofast (V.P. Ubiquiti Networks)
![Page 2: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/2.jpg)
![Page 3: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/3.jpg)
The Business
![Page 4: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/4.jpg)
![Page 5: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/5.jpg)
The Metrics
![Page 6: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/6.jpg)
Phone Calls per Second
The Metrics
![Page 7: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/7.jpg)
Phone Calls per Second
The Metrics
![Page 8: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/8.jpg)
Simultaneous Phone Calls
The Metrics
![Page 9: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/9.jpg)
Simultaneous Phone Calls
The Metrics
![Page 10: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/10.jpg)
HTTP API requests
The Metrics
![Page 11: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/11.jpg)
HTTP API requests
The Metrics
![Page 12: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/12.jpg)
Self-hosted (kinda)
![Page 13: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/13.jpg)
Voice Response
Call Handling
![Page 14: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/14.jpg)
Call Routing
Call Handling
![Page 15: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/15.jpg)
![Page 16: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/16.jpg)
Self-hosted (kinda)
Bet the farm moment
![Page 17: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/17.jpg)
![Page 18: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/18.jpg)
![Page 19: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/19.jpg)
Concurrency
The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf
![Page 20: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/20.jpg)
Concurrency
Error encapsulation
The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf
![Page 21: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/21.jpg)
Concurrency
Error encapsulation
Fault detection
The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf
![Page 22: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/22.jpg)
Concurrency
Error encapsulation
Fault detection
Fault identification
The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf
![Page 23: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/23.jpg)
Concurrency
Error encapsulation
Fault detection
Fault identification
Code upgrade
The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf
![Page 24: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/24.jpg)
Concurrency
Error encapsulation
Fault detection
Fault identification
Code upgrade
Stable Storage
The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf
![Page 25: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/25.jpg)
Erlang
![Page 26: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/26.jpg)
Erlang
![Page 27: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/27.jpg)
gen_server
Behaviours
![Page 28: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/28.jpg)
gen_server
gen_tcp
Behaviours
![Page 29: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/29.jpg)
gen_server
gen_tcp
gen_event
Behaviours
![Page 30: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/30.jpg)
gen_server
gen_tcp
gen_event
gen_fsm
Behaviours
![Page 31: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/31.jpg)
gen_server
gen_tcp
gen_event
gen_fsm
…
Behaviours
![Page 32: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/32.jpg)
gen_server
gen_tcp
gen_event
gen_fsm
…
Behaviours
![Page 33: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/33.jpg)
A System has States
Finite State Machines
![Page 34: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/34.jpg)
![Page 35: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/35.jpg)
A System has States
States transition
Finite State Machines
![Page 36: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/36.jpg)
![Page 37: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/37.jpg)
A System has States
States transition
Transitions are Atomic
Finite State Machines
![Page 38: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/38.jpg)
![Page 39: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/39.jpg)
A System has States
States transition
Transitions are Atomic
Events at Entry and Exit
Finite State Machines
![Page 40: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/40.jpg)
![Page 41: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/41.jpg)
![Page 42: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/42.jpg)
![Page 43: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/43.jpg)
![Page 44: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/44.jpg)
![Page 45: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/45.jpg)
![Page 46: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/46.jpg)
![Page 47: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/47.jpg)
![Page 48: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/48.jpg)
![Page 49: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/49.jpg)
![Page 50: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/50.jpg)
![Page 51: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/51.jpg)
![Page 52: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/52.jpg)
![Page 53: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/53.jpg)
![Page 54: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/54.jpg)
![Page 55: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/55.jpg)
![Page 56: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/56.jpg)
![Page 57: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/57.jpg)
![Page 58: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/58.jpg)
![Page 59: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/59.jpg)
![Page 60: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/60.jpg)
![Page 61: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/61.jpg)
![Page 62: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/62.jpg)
![Page 63: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/63.jpg)
![Page 64: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/64.jpg)
![Page 65: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/65.jpg)
![Page 66: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/66.jpg)
![Page 67: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/67.jpg)
![Page 68: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/68.jpg)
![Page 69: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/69.jpg)
![Page 70: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/70.jpg)
![Page 71: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/71.jpg)
![Page 72: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/72.jpg)
Everything is an FSM
Finite State Machines
![Page 73: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/73.jpg)
Everything is an FSM
Finite State Machines
![Page 74: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/74.jpg)
Everything is an FSM
Finite State Machines
![Page 75: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/75.jpg)
Voice Response
Finite State Machines
![Page 76: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/76.jpg)
Voice Response
Finite State Machines
![Page 77: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/77.jpg)
Voice Response
Finite State Machines
![Page 78: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/78.jpg)
Encapsulation
![Page 79: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/79.jpg)
Call Routing
Finite State Machines
![Page 80: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/80.jpg)
![Page 81: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/81.jpg)
Templates are your friend
So are BIG sheets of paper
Think “Real World”
The Bottom Line
![Page 82: Finite State Machines - Why the fear?](https://reader038.vdocument.in/reader038/viewer/2022103110/5482155ab4af9f21758b456d/html5/thumbnails/82.jpg)