Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Elixir and Phoenix

Introduction to Elixir and Phoenix

Introduction and overview to Elixir and Phoenix

Karmen Blake

November 20, 2019
Tweet

More Decks by Karmen Blake

Other Decks in Programming

Transcript

  1. 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. 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. 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. 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. 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
  6. 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.
  7. ELIXIR ▸What Erlang provides: scalable, fault- tolerant, functional ▸Ruby-like syntax

    (not semantics) ▸Extensible/DSLs ▸Tooling/ecosystem ▸package management, testing, iex (repl)
  8. 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
  9. 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
  10. 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
  11. 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.
  12. 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.
  13. 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
  14. CITATIONS ▸ https://en.wikipedia.org/wiki/Erlang_(programming_language) ▸ https://www.erlang.org ▸ https://elixir-lang.org ▸ https://www.meetup.com/rubymeetup/events/14908915/ ▸

    https://pragprog.com/book/phoenix14/programming-phoenix-1-4 ▸ https://twitter.com/chris_mccord/status/659430661942550528 ▸ https://dockyard.com/blog/2018/12/12/phoenix-liveview- interactive-real-time-apps-no-need-to-write-javascript