SlideShare a Scribd company logo
Elixir & Phoenix
Functional |> Concurrent |> Pragmatic |> Fun
Who am I?
• Jared Smith
• Software Engineer at One Month
• @sublimecoder
• www.sublimecoding.com
Lets get started
First lets talk about Erlang
• Elixir runs on the Erlang VM
• Many of the standard lib function calls in Elixir
call Erlang functions directly.
• Elixir piggy backs on the Erlang ecosystem
Why Erlang VM?
• 30 year old battle tested VM
• Highly available, fault tolerant, and distributed
History of Erlang
• Developed by Ericsson
• Used and developed for Telecommunications
• In fact its standard library is the OTP (Open
Telecom Platform)
Telecommunications
• High availability is king
• Remote Telecom switches need to run for years
sometimes with out being disturbed
Built with Erlang
• 50 person engineering team
• managing 900 million users.
• Up to 2 million active users per server.
https://blog.whatsapp.com/196/1-million-is-so-2011
2 Million Active Users?
• Intel Xeon CPU x5675 @ 3.07GHz

24 Cores - 96GB Ram
• Using only 40% of the CPU/Memory
https://blog.whatsapp.com/196/1-million-is-so-2011
So Erlang is pretty awesome
• Wouldn’t it be nice if we could harness this
power?
• Why isn’t everyone using Erlang?
Elixir
• Elixir utilizes much of the power of Erlang
• While giving us a much nicer syntax and api to
work with.
History of Elixir
• Created by Josè Valím - (Joe-zay Val-eem)
• First released in 2012
Elixir’s Strengths
• Concurrency
• Meta-programming Capability
• Transformation of data as a core ideal
Plus it has Ruby like syntax
Pipe Operator
• The following code is valid elixir.
• With the pipe operator we can write our code this
way instead. Keeping us out of nested function
hell.
Pattern Matching
• Pattern matching is a core part of Erlang and
Elixir
What is Pattern Matching?
• Make left side look like the right side
• a = 99
• [a,b,c] = [1,2,3]
• [head | tail] = [1,2,3]
Immutability
• Once you set a value 

it can never change.
Immutability
You’re already familiar with
immutability you just don’t know it.
• a = 99
• We all know 99 is always 99.
• integers are immutable values, even in Ruby.
• You’d be upset if someone monkey patched 99
to be 3 right?
Why is Immutability a good
thing?
• Immutability provides a contract that each piece
of information has one source of truth.
• Concurrency is a natural side effect of
immutability.
Does this mean I can never
change a variable once I set it?
• The short answer is no, you can reassign
variables as much as you like.
• Erlang would not be so kind, but Elixir we have
this luxury.
So how is it immutable if I
can change things?
• You can change things, elixir will just copy the
values you don’t change, but the original
reference stays intact.
• The original reference can then be used in part
or in whole later in the application.
Isn’t this inefficient?
• At first glance it would seem that way, but the
opposite is true.
• Won’t all the old reference values balloon elixirs
memory?
• Yes this means you could have thousands of
unused variables floating in memory
Concurrency
Concurrency fixes
everything
• Because the data is immutable we can rely on it
always being a certain value
• which means we can make our programs
concurrent and not worry.
• Elixir uses its concurrency to help with garbage
collections. Each process gets it own heap
allocated and that heap is garbage collected or
reclaimed as needed for that individual process.
Concurrency
• Elixir will eat as many cores/computers as you
can throw at it.
• It treats each core as though it were a computer
on the network with near zero latency.
Intro to elixir and phoenix
Phoenix Framework
Productive |> Reliable |> Fast
Phoenix Framework
• Created by Chris McCord
• Release 1.0 August 28th 2015
Intro to elixir and phoenix
Phoenix Framework
• It’s not rails for Elixir
• It has been influence heavily by rails as well as
many other frameworks.
• Focus on API and web sockets
Speed
• Web request response time is often measured in
micro seconds and not milliseconds.
Benchmarks
• Recently benchmarked 2 million+ web socket
connections
• With 2 - 3 second broadcast times to all 2 million
connections
Benchmarks
https://github.com/mroth/phoenix-showdown
iMac Intel Core i7 (4.0 GHz 4 Cores) 32 GB RAM
https://github.com/mroth/phoenix-showdown
2.8 Ghz, 10 core Intel® Xeon 128 GB RAM
Easy Startup
• mix phoenix.new ./app/path/my_app
• mix ecto.create && mix ecto.migrate
• mix phoenix.server
Directory Structure
Web Dir Structure
Mix
• Mix is essentially bundler and rake combined
• Additionally mix is your test runner.
• It’s included with Elixir
Rails like Generators
• mix phoenix.gen.html Post posts title body:text
• mix phoenix.gen.json User users name:string
• mix phoenix.gen.model User users name:string
Concurrency
• Async processing with out the need for
DelayedJob or Resque/sidekiq
• We can write code that looks like this.
Isolated & Concurrent
• Crashes are isolated
• Data is isolated 

(GC is per process, no global pauses)
• Load Balances on IO and CPU - Efficient on a
multicore
Garbage Collection
• No triggering massive garbage collection
• GC per process / end of process life cycle
• Ensuring top 10 percent of requests are not vastly
slower than any other request
Request Pipeline
• Just a series of function calls that transform
data.
• connection 

|> endpoint

|> router

|> pipelines

|> controller
Request Pipeline
• Phoenix makes it easy to add middleware or
plugs to this pipeline. We could easily add
authentication to this.
• connection 

|> endpoint

|> router

|> pipelines

|> authenticate_user

|> controller
Explicitness Over Magic
• Phoenix Removes a lot of the confusion and
“magic” found in rails and replaces it with
explicit calls.
• Models, Controllers and Views are singular
named by convention.
Phoenix Router
Phoenix Router
Phoenix Router
Phoenix Controllers
Phoenix Model
Phoenix View
Phoenix Template
Learn More
• Elixir-Lang on Slack 

https://elixir-slackin.herokuapp.com/
• #elixir-lang on Freenode IRC
• http://www.phoenixframework.org
• http://elixir-lang.org/
• https://github.com/h4cc/awesome-elixir

More Related Content

What's hot (20)

PDF
From Generator to Fiber the Road to Coroutine in PHP
Albert Chen
 
PDF
Long running processes in DDD
Bernd Ruecker
 
PDF
Getting started with SIP Express Media Server SIP app server and SBC - workshop
stefansayer
 
PDF
Intellectual Highway/貞末様 講演資料
直久 住川
 
PDF
twMVC#44 讓我們用 k6 來進行壓測吧
twMVC
 
PDF
Redmineのバージョンアップに追従していくための一工夫
Go Maeda
 
PPTX
Enterprise private network
Khuzaima Shahid
 
PDF
Wordpress Plugin Development Short Tutorial
Christos Zigkolis
 
PDF
GraphQLはどんな時に使うか
Yutaka Tachibana
 
PDF
DockerからKubernetesへのシフト
masaki nakayama
 
PPTX
Async js
Alexandr Skachkov
 
PDF
How to Define and Share your Event APIs using AsyncAPI and Event API Products...
HostedbyConfluent
 
PPTX
MicrometerとPrometheusによる LINEファミリーアプリのモニタリング
LINE Corporation
 
PPTX
Introduction to WebRTC
Art Matsak
 
PPTX
WatchOS Architecture
Avinash Gautam
 
PPTX
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
 
PDF
続・モジュール / Introduction to C++ modules (part 2)
TetsuroMatsumura
 
PDF
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
HungWei Chiu
 
PPT
Automated Testing With Watir
Timothy Fisher
 
PDF
PHPの今とこれから2022
Rui Hirokawa
 
From Generator to Fiber the Road to Coroutine in PHP
Albert Chen
 
Long running processes in DDD
Bernd Ruecker
 
Getting started with SIP Express Media Server SIP app server and SBC - workshop
stefansayer
 
Intellectual Highway/貞末様 講演資料
直久 住川
 
twMVC#44 讓我們用 k6 來進行壓測吧
twMVC
 
Redmineのバージョンアップに追従していくための一工夫
Go Maeda
 
Enterprise private network
Khuzaima Shahid
 
Wordpress Plugin Development Short Tutorial
Christos Zigkolis
 
GraphQLはどんな時に使うか
Yutaka Tachibana
 
DockerからKubernetesへのシフト
masaki nakayama
 
How to Define and Share your Event APIs using AsyncAPI and Event API Products...
HostedbyConfluent
 
MicrometerとPrometheusによる LINEファミリーアプリのモニタリング
LINE Corporation
 
Introduction to WebRTC
Art Matsak
 
WatchOS Architecture
Avinash Gautam
 
続・モジュール / Introduction to C++ modules (part 2)
TetsuroMatsumura
 
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
HungWei Chiu
 
Automated Testing With Watir
Timothy Fisher
 
PHPの今とこれから2022
Rui Hirokawa
 

Similar to Intro to elixir and phoenix (20)

KEY
Actors and Threads
mperham
 
PPTX
Elixir
Fuat Buğra AYDIN
 
PPTX
Scalable game-servers-tgc
Ashkan Saeedi Mazdeh
 
PPTX
Repeating History...On Purpose...with Elixir
Barry Jones
 
PPTX
C# Async/Await Explained
Jeremy Likness
 
PDF
Scaling tappsi
Óscar Andrés López
 
PPTX
From Ruby to Elixir
Maksym Pugach
 
PPTX
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
PDF
VoltDB and Erlang - Tech planet 2012
Eonblast
 
PDF
Erlang factory SF 2011 "Erlang and the big switch in social games"
Paolo Negri
 
PDF
Erlang, the big switch in social games
Wooga
 
PPTX
Scheduling Thread
MuhammadBilal187526
 
PPT
The Economies of Scaling Software
Abdelmonaim Remani
 
PDF
Xen and-the-art-of-rails-deployment2640
Newlink
 
PDF
Xen and-the-art-of-rails-deployment2640
Newlink
 
PDF
Xen and-the-art-of-rails-deployment2640
Newlink
 
PDF
Xen and-the-art-of-rails-deployment2640
Newlink
 
PDF
Xen and-the-art-of-rails-deployment2640
LLC NewLink
 
PPT
The economies of scaling software - Abdel Remani
jaxconf
 
PDF
Erlang/Elixir and OTP
Benjamin Cates
 
Actors and Threads
mperham
 
Scalable game-servers-tgc
Ashkan Saeedi Mazdeh
 
Repeating History...On Purpose...with Elixir
Barry Jones
 
C# Async/Await Explained
Jeremy Likness
 
Scaling tappsi
Óscar Andrés López
 
From Ruby to Elixir
Maksym Pugach
 
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
VoltDB and Erlang - Tech planet 2012
Eonblast
 
Erlang factory SF 2011 "Erlang and the big switch in social games"
Paolo Negri
 
Erlang, the big switch in social games
Wooga
 
Scheduling Thread
MuhammadBilal187526
 
The Economies of Scaling Software
Abdelmonaim Remani
 
Xen and-the-art-of-rails-deployment2640
Newlink
 
Xen and-the-art-of-rails-deployment2640
Newlink
 
Xen and-the-art-of-rails-deployment2640
Newlink
 
Xen and-the-art-of-rails-deployment2640
Newlink
 
Xen and-the-art-of-rails-deployment2640
LLC NewLink
 
The economies of scaling software - Abdel Remani
jaxconf
 
Erlang/Elixir and OTP
Benjamin Cates
 
Ad

Recently uploaded (20)

DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
July Patch Tuesday
Ivanti
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
July Patch Tuesday
Ivanti
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Biography of Daniel Podor.pdf
Daniel Podor
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Ad

Intro to elixir and phoenix