Introduction to Elixir and Phoenix

Introduction to Elixir and Phoenix

Introduction and overview to Elixir and Phoenix


Karmen Blake

November 20, 2019


  1. 2.

    ME ▸Crafting code since 2000 ▸Blessed to work for silicon

    valley startups, consultancies, agencies, corporations ▸Instructor at Spokane Community College, 2000-2007, teaching computer science and web development
  2. 5.

    RE: CODING JOURNEY ▸College (late 90s): BASIC, Pascal, C++ ▸Early

    days (2000-2005) - Java and PHP ▸Then… Lots of Ruby (2005 - present) ▸Taught at SCC (converted curricula from Java) ▸Blog posts, presentations, interviews ▸High paying jobs ▸Still a joy to develop in
  3. 7.

    ERLANG ▸I read “Programming Erlang: Software for a Concurrent World”

    by the late Joe Armstrong, 2007 ▸Created in 1986 at Ericsson ▸“…used to build massively scalable soft real-time systems with requirements on high availability.” ▸“…telecoms, banking, e-commerce, computer telephony and instant messaging”
  4. 8.

    ERLANG ▸1998 Ericsson announced the AXD301 switch, containing for a

    million lines of Erlang and reported to achieve a high availability of nine “9”s. ▸Cisco reports that 90% of all internet traffic goes through Erlang controlled nodes ▸Scalable, fault-tolerant, functional (immutable data, functions, pattern matching, tail recursive, etc.)
  5. 9.
  6. 10.

    ERLANG AT APPLE (2011-2012) ▸Wrote API web services in Erlang

    ▸Used Riak database (written in Erlang) cluster as an internal asset CDN ▸Used CouchDB to deliver real-time web applications
  7. 11.
  8. 13.

    ELIXIR ▸Created by Jose Valim in 2011 ▸“…dynamic, functional language

    designed for building scalable and maintainable applications.” ▸“…leverages the Erlang VM (BEAM), known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and embedded software domain.
  9. 14.

    ELIXIR ▸What Erlang provides: scalable, fault- tolerant, functional ▸Ruby-like syntax

    (not semantics) ▸Extensible/DSLs ▸Tooling/ecosystem ▸package management, testing, iex (repl)
  10. 16.
  11. 17.
  12. 20.

    THINGS YOU’LL RECOGNIZE ▸Resourceful Routing ▸Controllers (request/response, JSON apis) ▸Views

    (presenters, helpers) ▸Templates - markup, db-backed forms, error display, partials, etc. ▸Tasks (ie. Rake, called Mix in Phoenix) - running generators, etc. ▸Console (REPL for code and database tinkering) ▸Database layer (Ecto) ▸Testing ▸Easy Heroku deployments
  13. 21.

    QUICK NOTE ON TEMPLATES… THEY ARE FAST! ▸Phoenix templates are

    compiled into functions ▸Use linked-lists to build templates vs string concatenation (as most other web frameworks do) ▸Consumes much less memory
  14. 22.

    OOOOHHHH AAAAAHHHHH ▸Presence - register information on a topic and

    replicate it transparently across a cluster. Common use-case is users currently online (uses conflict- free replicated data type CRDT) ▸Contexts - standard way to define domains that cleanly separate concepts from technical implementation. ie. Accounts (users, authentication, etc.) ▸Channels - soft real-time communication between millions of connected clients (ie. chat room, breaking news, vehicle map tracking, multiplayer games, etc.). Think ActionCable but can actually scale ;p ▸Umbrella - put code in organized apps that enforce domain code to stay away from web interactions - ie. web, db, domains “Phoenix is not your app” ▸Pub/Sub - Pubnub, services
  15. 23.

    PHOENIX LEVERAGING ELIXIR/ERLANG (OTP) ▸ETS/Genservers - Think Redis. Available right

    in the VM ▸Tasks - Asynchronous background work (Sidekiq). Available right in the VM ▸Supervisors - Architect a self-healing system that can recover when unexpected things happen. “Let it crash!”. Available right in the VM. Think Akka.
  16. 24.
  17. 25.

    WHAT IS LIVEVIEW? ‣ Phoenix LiveView is an exciting new

    way to build interactive, real-time web applications in Elixir, writing little or no custom JavaScript. ‣ LiveView, built on Phoenix’s excellent websocket report, harnesses the Erlang VM’s ability to run millions of tiny, isolated, stateful processes. ‣ LiveView simplifies development by keeping the view logic server-side, yet achieves stunningly fast updates and low latency.
  18. 26.

    SPIKES ▸Work: ▸Real-time Phoenix dashboard displaying Trello board info, bug

    counts, Zoom conference room info, Github PRs ▸LiveView app for Zoom conference room and participant information
  19. 29.

    CITATIONS ▸ ▸ ▸ ▸ ▸ ▸ ▸ interactive-real-time-apps-no-need-to-write-javascript