Intro to elixir and phoenix

Jared Smith
Jared SmithSoftware Engineer at InsideTrack
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
1 of 56

Recommended

Everything you always wanted to know about Redis but were afraid to ask by
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askCarlos Abalde
26.9K views73 slides
PostgreSQL and JDBC: striving for high performance by
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performanceVladimir Sitnikov
7.1K views61 slides
The InnoDB Storage Engine for MySQL by
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
13.4K views55 slides
[db tech showcase Tokyo 2015] E27: Neo4jグラフデータベース by クリエーションライン株式会社 李昌桓 by
[db tech showcase Tokyo 2015] E27: Neo4jグラフデータベース by クリエーションライン株式会社 李昌桓[db tech showcase Tokyo 2015] E27: Neo4jグラフデータベース by クリエーションライン株式会社 李昌桓
[db tech showcase Tokyo 2015] E27: Neo4jグラフデータベース by クリエーションライン株式会社 李昌桓Insight Technology, Inc.
10K views66 slides
片手間MySQLチューニング戦略 by
片手間MySQLチューニング戦略片手間MySQLチューニング戦略
片手間MySQLチューニング戦略yoku0825
21.2K views78 slides
[B23] PostgreSQLのインデックス・チューニング by Tomonari Katsumata by
[B23] PostgreSQLのインデックス・チューニング by Tomonari Katsumata[B23] PostgreSQLのインデックス・チューニング by Tomonari Katsumata
[B23] PostgreSQLのインデックス・チューニング by Tomonari KatsumataInsight Technology, Inc.
9.4K views33 slides

More Related Content

What's hot

My SYSAUX tablespace is full - please help by
My SYSAUX tablespace is full - please helpMy SYSAUX tablespace is full - please help
My SYSAUX tablespace is full - please helpMarkus Flechtner
641 views49 slides
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2 by
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder
12.6K views21 slides
Teradata utilities-fast export by
Teradata utilities-fast exportTeradata utilities-fast export
Teradata utilities-fast exportSatti Kumar
9.9K views11 slides
Redis introduction by
Redis introductionRedis introduction
Redis introductionFederico Daniel Colombo Gennarelli
5.9K views22 slides
Using Redis at Facebook by
Using Redis at FacebookUsing Redis at Facebook
Using Redis at FacebookRedis Labs
2.7K views11 slides
Using The Mysql Binary Log As A Change Stream by
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamLuís Soares
433 views122 slides

What's hot(20)

My SYSAUX tablespace is full - please help by Markus Flechtner
My SYSAUX tablespace is full - please helpMy SYSAUX tablespace is full - please help
My SYSAUX tablespace is full - please help
Markus Flechtner641 views
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2 by Tanel Poder
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder12.6K views
Teradata utilities-fast export by Satti Kumar
Teradata utilities-fast exportTeradata utilities-fast export
Teradata utilities-fast export
Satti Kumar9.9K views
Using Redis at Facebook by Redis Labs
Using Redis at FacebookUsing Redis at Facebook
Using Redis at Facebook
Redis Labs2.7K views
Using The Mysql Binary Log As A Change Stream by Luís Soares
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change Stream
Luís Soares433 views
An Introduction to REDIS NoSQL database by Ali MasudianPour
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
Ali MasudianPour5.4K views
MongoDBのアレをアレする by Akihiro Kuwano
MongoDBのアレをアレするMongoDBのアレをアレする
MongoDBのアレをアレする
Akihiro Kuwano14.5K views
Tanel Poder Oracle Scripts and Tools (2010) by Tanel Poder
Tanel Poder Oracle Scripts and Tools (2010)Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder46.2K views
Mongo dbを知ろう by CROOZ, inc.
Mongo dbを知ろうMongo dbを知ろう
Mongo dbを知ろう
CROOZ, inc.29.9K views
關於測試,我說的其實是...... by hugo lu
關於測試,我說的其實是......關於測試,我說的其實是......
關於測試,我說的其實是......
hugo lu8.6K views
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell by Miguel Araújo
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL ShellMySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
Miguel Araújo857 views
MySQL Parallel Replication: inventory, use-case and limitations by Jean-François Gagné
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
MariaDB: in-depth (hands on training in Seoul) by Colin Charles
MariaDB: in-depth (hands on training in Seoul)MariaDB: in-depth (hands on training in Seoul)
MariaDB: in-depth (hands on training in Seoul)
Colin Charles9.2K views
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD... by InfluxData
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxData414 views
Evolution of MySQL Parallel Replication by Mydbops
Evolution of MySQL Parallel Replication Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication
Mydbops1.3K views
Under the Hood of a Shard-per-Core Database Architecture by ScyllaDB
Under the Hood of a Shard-per-Core Database ArchitectureUnder the Hood of a Shard-per-Core Database Architecture
Under the Hood of a Shard-per-Core Database Architecture
ScyllaDB1.3K views

Similar to Intro to elixir and phoenix

Actors and Threads by
Actors and ThreadsActors and Threads
Actors and Threadsmperham
16K views46 slides
Elixir by
ElixirElixir
ElixirFuat Buğra AYDIN
110 views38 slides
Scalable game-servers-tgc by
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgcAshkan Saeedi Mazdeh
330 views43 slides
Repeating History...On Purpose...with Elixir by
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirBarry Jones
2.4K views57 slides
C# Async/Await Explained by
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await ExplainedJeremy Likness
7.1K views34 slides
Scaling tappsi by
Scaling tappsiScaling tappsi
Scaling tappsiÓscar Andrés López
1.1K views37 slides

Similar to Intro to elixir and phoenix(20)

Actors and Threads by mperham
Actors and ThreadsActors and Threads
Actors and Threads
mperham16K views
Repeating History...On Purpose...with Elixir by Barry Jones
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
Barry Jones2.4K views
Concurrency & Parallel Programming by Ramazan AYYILDIZ
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
Ramazan AYYILDIZ1.1K views
VoltDB and Erlang - Tech planet 2012 by Eonblast
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
Eonblast4.4K views
Erlang factory SF 2011 "Erlang and the big switch in social games" by Paolo Negri
Erlang factory SF 2011 "Erlang and the big switch in social games"Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"
Paolo Negri1.3K views
Erlang, the big switch in social games by Wooga
Erlang, the big switch in social gamesErlang, the big switch in social games
Erlang, the big switch in social games
Wooga7.4K views
Xen and-the-art-of-rails-deployment2640 by Newlink
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink265 views
Xen and-the-art-of-rails-deployment2640 by LLC NewLink
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
LLC NewLink444 views
Xen and-the-art-of-rails-deployment2640 by Newlink
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink298 views
Xen and-the-art-of-rails-deployment2640 by Newlink
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink259 views
Xen and-the-art-of-rails-deployment2640 by Newlink
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink315 views
The economies of scaling software - Abdel Remani by jaxconf
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
jaxconf346 views

Recently uploaded

Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
224 views7 slides
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023BookNet Canada
44 views19 slides
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
139 views15 slides
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...ShapeBlue
108 views12 slides
Optimizing Communication to Optimize Human Behavior - LCBM by
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBMYaman Kumar
38 views49 slides
"Package management in monorepos", Zoltan Kochan by
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan KochanFwdays
34 views18 slides

Recently uploaded(20)

Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue224 views
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
Optimizing Communication to Optimize Human Behavior - LCBM by Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 views
"Package management in monorepos", Zoltan Kochan by Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays34 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue152 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue137 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue178 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue129 views
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software184 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue225 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li91 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc176 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri39 views

Intro to elixir and phoenix

  • 1. Elixir & Phoenix Functional |> Concurrent |> Pragmatic |> Fun
  • 2. Who am I? • Jared Smith • Software Engineer at One Month • @sublimecoder • www.sublimecoding.com
  • 4. 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
  • 5. Why Erlang VM? • 30 year old battle tested VM • Highly available, fault tolerant, and distributed
  • 6. History of Erlang • Developed by Ericsson • Used and developed for Telecommunications • In fact its standard library is the OTP (Open Telecom Platform)
  • 7. Telecommunications • High availability is king • Remote Telecom switches need to run for years sometimes with out being disturbed
  • 8. 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
  • 9. 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
  • 10. So Erlang is pretty awesome • Wouldn’t it be nice if we could harness this power? • Why isn’t everyone using Erlang?
  • 11. Elixir • Elixir utilizes much of the power of Erlang • While giving us a much nicer syntax and api to work with.
  • 12. History of Elixir • Created by Josè Valím - (Joe-zay Val-eem) • First released in 2012
  • 13. Elixir’s Strengths • Concurrency • Meta-programming Capability • Transformation of data as a core ideal
  • 14. Plus it has Ruby like syntax
  • 15. 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.
  • 16. Pattern Matching • Pattern matching is a core part of Erlang and Elixir
  • 17. 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]
  • 18. Immutability • Once you set a value 
 it can never change.
  • 20. 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?
  • 21. 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.
  • 22. 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.
  • 23. 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.
  • 24. 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
  • 26. 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.
  • 27. 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.
  • 30. Phoenix Framework • Created by Chris McCord • Release 1.0 August 28th 2015
  • 32. 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
  • 33. Speed • Web request response time is often measured in micro seconds and not milliseconds.
  • 34. Benchmarks • Recently benchmarked 2 million+ web socket connections • With 2 - 3 second broadcast times to all 2 million connections
  • 38. Easy Startup • mix phoenix.new ./app/path/my_app • mix ecto.create && mix ecto.migrate • mix phoenix.server
  • 41. Mix • Mix is essentially bundler and rake combined • Additionally mix is your test runner. • It’s included with Elixir
  • 42. 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
  • 43. Concurrency • Async processing with out the need for DelayedJob or Resque/sidekiq • We can write code that looks like this.
  • 44. 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
  • 45. 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
  • 46. Request Pipeline • Just a series of function calls that transform data. • connection 
 |> endpoint
 |> router
 |> pipelines
 |> controller
  • 47. 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
  • 48. 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.
  • 56. 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