duo disco - doing the erlang dance
DESCRIPTION
Introducing Erlang and Zotonic through the use case of the Duo Disco appTRANSCRIPT
Doing the Erlang danceA case study
Arjan Scherpenisse@acscherp
Who am I?● Wide range of interests
● Polyglot programmer
● Contributor to Open Source Software
● Doing things differently...
Where others use … , I use … ● Mac → Linux
● iOS → Android
● Textmate Sublime Text → Emacs
● … → Erlang!
Introducing:
Do the DuoDisco!● Mark Meeuwenoord, Klasien van de Zandschulp,
James Bryan Graves
● It’s fun. Profit comes later
1. Download app
2. Join disco
3. Dance
4. Find partner → score!
5. goto 3
DuoDisco Architecture● Table: player
○ id
○ name
○ status (“waiting”, “playing”, “loading”, etc)
○ connected (true / false)
○ connected_to (player id FK)
○ current_song_id
Disco architecture issues● Race Condition Paradise
○ Connection drops
○ Connection latency
○ Subtle client differences
● These bugs never happen while you’re
developing
● Player A → Player B, Player B → Player C○ Debugging nightmare..
So what about that Erlang thing?● A language, VM and runtime system
● Fault tolerant
● Concurrent
● Functional
● In use by major players
Erlang: Fault Tolerance● Systems will error
● “Let it crash”○ Only program the happy path
● You will be restarted ○ by your supervisor
○ with a clean slate
Erlang: Concurrence● Processes (“Actors”) are cheap
● Processes communicate
● Processes contain state
Erlang: It’s Functional● Assign-once
● Pattern matching
● No loops○ use (tail)recursion
○ list comprehensions, map/reduce
● It has a WEIRD SYNTAX? ?F()(*$#)(*#○ I had to say it somewhere
○ Look at Elixir, it rocks. http://elixir-lang.org/
Erlang + Web = Zotonic● “The Django of Erlang”
● Web development framework○ Built-in web server; CMS
○ Opinionated & extensible
● Great performance out-of-the-box
● Easy to use data model○ Semantic web “everything is a thing”
Back in the Disco… ● 3 clients, iOS, Android & HTML
● Backend: Erlang + Zotonic (obviously...)
● JSON over WebSockets
● REST for login / discovery
● Zotonic manages data model ○ (media files, multiple disco’s)
DuoDisco refactoring● Model it the Erlang way
● Every player is a process
● “Room” processes for connected players
● One match-making process ○ Uses process registry for querying processes
DuoDisco findings● First try-out at Extrapool Festival 2 wks ago
● No more weird bugs!
● Lessons learned
○ Think (a bit) before you code
○ Use the right tool for the job
○ Dare to iterate and start over
Linkshttp://erlang.org/ - the Erlang language
http://zotonic.com/ - The web framework
http://duodisco.nl/ - Duo Disco app info
http://elixir-lang.org/ - Erlang with different syntax
Thanks! Questions?Contact:
● http://twitter.com/acscherp
● http://miraclethings.nl/
● http://github.com/arjan
● buy me a beer :p