Phoenix Framework (Elixir)
A productive web framework that does not compromise speed and maintainability
Svein Fidjestøl
Webstep Fokus
January 2016
Intel Haswell-E
2015
?✓
Timeline
1986: Erlang 2012: Elixir 2015: Phoenix Framework
2015: 3 GHz, 8(16) Cores2002: 3 GHz, 1 Core1986: 0.016 GHz, 1 Core
Elixir
Modern programming language
Erlang Virtual Machine (BEAM)
Erlang compatible
Battle-tested concurrency and distribution model
IEx: Interactive Shell
Mix: Build and package management tool
Elixir
2012: R&D project at Plataformatec (Brazil). First public release.
2014: Version 1.0.0. Some real-world usage of Elixir in production systems.
2016: Version 1.2.0
Elixir
In Python
" ".join(map(str.capitalize, "hello_there_world".split("_")))
In Elixir
"hello_there_world"
|> String.split("_")
|> Enum.map(&String.capitalize/1)
|> Enum.join(" ")
using the pipeline operator: |>
Elixir
In C#
"hello_there_world"
.Split('_')
.Select(x => textInfo.ToTitleCase(x))
.Aggregate((a, b) => a + " " + b);
or
string.Join(" ",
"hello_there_world"
.Split('_')
.Select(x => textInfo.ToTitleCase(x)))
Erlang
Used in 50 % of all telecom switches
Erlang Virtual Machine (BEAM)
Massively Scalable
High Availability
Actor Model
Unfamiliar syntax -- Erlang started life as a modified Prolog, and this shows.
Erlang
1986: Proprietary Language (Ericsson)
1995: OTP (“Open Telecom Platform”)
1998: Erlang/OTP Open Sourced
2008: Facebook Chat
2010: WhatsApp
Other: RabbitMQ, CouchDB, Riak, Yahoo delicious.com, Pinterest, Amazon SimpleDB
Erlang
Functions are defined basically by a mathematical formula
area({square, Side}) -> Side * Side;
area({circle, Radius}) -> math:pi() * Radius * Radius.
“square” and “circle” are atoms since they start with a lowercase letter
“Side” and “Radius” are variables since they start with an uppercase letter
Erlang
Decode TCP segments:
decode(<< SourcePort:16, DestinationPort:16,
SequenceNumber:32,
AckNumber:32,
DataOffset:4, _Reserved:4, Flags:8,
WindowSize:16,
Checksum:16, UrgentPointer:16,
Payload/binary>>) when DataOffset>4
“SourcePort:16”: 16 is the number of bits to be matched to the variable SourcePort
“when DataOffset>4”: Guard expression, can use simple tests and variable comparisons
Erlang
Quicksort
qsort([]) -> [];
qsort([X|Xs]) ->
qsort([Y || Y <- Xs, Y =< X]) ++ [X] ++ qsort([Y || Y <- Xs, Y > X]).
Elixir
DEMO
Phoenix Framework
Web Framework for Elixir, inspired by Ruby on Rails
MVC (Model - View - Controller)
Optimized for “Developer joy” and productivity
Massively better performance than RoR (and concurrency actually works!)
Plug
Ecto
Channels (Sockets), PubSub, etc.
Phoenix Framework
2014: First appeared
2015: Version 1.0
2016: Version 1.1
Phoenix Framework
Linux, OS X, Windows
PostgreSQL, MySql, SQL Server
Works great on all combinations
Easy to get started
Easily deployed to Heroku
Efficient! Can even run on a Raspberry PI 2:
540 requests per second on a $35 piece of hardware using on average 90% CPU and only 16 MB RAM
Plug
Pipeline
Authentication
Other Request Headers
Logging
Ecto
ORM mapper, without the “O”
Familiar syntax
Type safe
query = from w in Weather,
where: w.prcp > 0 or is_nil(w.prcp),
select: w
Framework dependencies
node.js (optional, for development)
PostgreSQL (default)
SQL Server also works fine using the TDS Adapter for Ecto
Framework dependencies
Erlang
fs
ranch
poolboy
decimal
poison
cowlib
cowboy
Framework dependencies
Elixir
plug
ecto
Client side
brunch.io (Optional, asset management)
One convenient package
Don’t have to worry about dependencies
Mix build system (Elixir dependencies)
Hex package manager (Erlang dependencies)
Code editor: e.g. Atom with language-elixir plugin
Phoenix Framework
DEMO
Deployment
Linux / Mac / Windows
Heroku
Elixir buildpack for Heroku
Real world use
Bleacher Report: http://bleacherreport.com/
Second largest sport website in the world
80 million unique users per month
Far above 100,000 requests per minute
Highly personalized content
Previously used Ruby on Rails
Performance issues, needed lots of caching layers
Phoenix allows a real-time strategy instead of caching
Real world use
High-level benefits
Scalability
Fault-tolerance
Functional
Meta-programming
Specific benefits
List manipulation
Highly personalized real-time lists
Questions?

Introduction to Phoenix Framework (Elixir) 2016-01-07