This document discusses Erlang concepts and how to think like an Erlanger. It provides examples of modeling systems like Game of Life and a stock exchange using Erlang's processes, message passing, and failure handling capabilities. Key points include: spawning many short-lived processes to model discrete entities, using protocols to define interactions, monitoring processes to restart them after failures, and transaction logs to ensure consistency after crashes. The document emphasizes focusing on interactions through messaging and designing systems to fail gracefully through Erlang's primitives.
30. Supervising Cells
The Erlang supervisor will restart with
the original args…
all state and history is lost
Fix:
monitor all cells
step them forward to current time
37. Re-cap
A process per cell
Short-lived processes for small tasks
Focus on the protocols between processes
Supervisor to restart
Monitoring manager process to get
restarted cells up-to-speed
39. The Trigger…
Erlang-Questions on using ETS for sell
and buy orders:
http://erlang.org/pipermail/erlang-
questions/2014-February/077969.html
Painful…
41. Basic Erlang Idea
One process per buy/sell intention
Processes to negotiate deals
by exchanging messages
42. Communication
Use gproc as pub-sub mechanism to
announce buy and sell intentions
All buyers listen to sell intention
All sellers listen to buy intentions
53. What Can Go Wrong?
1. Buyer dies
3. Buyer dies
2. Seller dies
1 & 2 can be fixed
by timing out
Danger!!
Seller has closed the
deal on his side
Simple re-start
leaves the buyer
at 3@5
55. Transaction Log Per
Process
Just replay back to the last state
Issues:
Messages cannot be replayed
Must ask partner about their view on
the status of the deal
56. Ledger
Create Ledger process that tracks all
completed deals
Each buyer and seller get a unique
OfferID when started
59. Tools
Lots of processes!!
Spawn short-lived processes for small
things
Supervisors
Link and monitor
gproc for registering and pub/sub
Timeouts
Transaction logs (ledgers)
60. Food for Thought
What can I only do in Erlang?
http://erlang.org/pipermail/erlang-
questions/2014-November/
081570.html
You can avoid writing your
own service framework.
Craig Everett
61. Testing
Async protocols are nasty
Use EQC - Property Based Testing
Focus on one process
Mock the calls to others
WIP in repo!
65. Learning Erlang
ESL training courses
Learn You Some Erlang
http://learnyousomeerlang.com/
Use the erlang-questions mailing list
Do it hands-on
Give it time to sink in!!!
66. Elixir
Built on top of the Erlang VM
More Ruby-like syntax
Hygienic macros - easy to do DSLs
Better support for data handling
But… you still have to learn the Erlang
programming model
67. Key building blocks
Share nothing processes
Message passing
Fail fast approach
Link/monitor concept
You can deal with failures in a sensible
manner because you have a language for
them.