Home

Awesome

Learn Phoenix (Web App) Framework

phoenix framework logo

Learn how to use Phoenix Framework to have fun building real-time web/mobile apps <br /> that are fast for "end-users", reliable, scalable, maintainable and (easily) extensible!

Why?

As web/mobile app developers we need to leverage the work that other (really smart) people have done <br /> instead of constantly building things "from scratch" all the time; that is why we use frameworks to build our apps!

See: "Top 10 Reasons Why Phoenix" (further down this page!)

There are many frameworks to choose from (a few "popular" ones are mentioned below in the "Questions" section). <br /> But if we go by what is "popular" we would still be riding horses (and carts) everywhere and no progress would be made. <br />

<!-- Phoenix is like having a [***jetpack***](https://youtu.be/H0ftAwlAB9o) (_with **unlimited free environmentally-friendly fuel**_!!); <br /> it gets you (_your app_) to where you need to be ***so much faster***! <br /> _Seriously_, once you _deploy_ your first Phoenix app _**you will feel** like you're **freakin' Iron** ~~Man~~ **Person**!_ ![iron-man-flying](https://cloud.githubusercontent.com/assets/194400/22628358/9ca42c58-ebca-11e6-8729-bc0103284312.jpg) You won't want to "_walk_" anywhere (_use a lesser means of web development_) _ever again_! -->

Note: all the reasons "Why" for Elixir also apply to Phoenix! <br /> check them out: https://github.com/dwyl/learn-elixir#why <br />

What?

A web application framework without compromise! <br />

Developer Joy

The biggest "constraint" in any technology project is people. An "Entrepreneur"/"Founder" or "Product Owner" can have all the good ideas in the world, if they are unable to convert idea into reality, it's meaningless.

<!-- commenting this out because I think it's too "hyperbolic" ... ### Metaphor You can spend ages (_and **mountains** of **money**_) "***performance tuning***" an ["_old banger_"](https://en.wikipedia.org/wiki/Decrepit_car) _trying_ to make it **go _faster_**<sup>1</sup> ... ![car-mod-fail](https://cloud.githubusercontent.com/assets/194400/22628288/41afc3d0-ebc9-11e6-98f3-67a1bc3a1411.png "Click image to enlarge for full glory!") ***Or***... _get_ the [**_best_ car**](http://www.cnbc.com/2015/08/27/teslas-p85d-is-the-best-car-consumer-reports-has-ever-tested.html) built for speed, safety and environmental friendliness and ***stop wasting time*** on the past! ![model-s-photo](https://cloud.githubusercontent.com/assets/194400/22628333/e8a107ee-ebc9-11e6-9140-6be11cdddd87.jpg "Tesla Model S") <br /> <small>_**Note**: with Phoenix, you're getting a [Tesla Model S P100D](https://www.tesla.com/en_GB/blog/new-tesla-model-s-now-quickest-production-car-world) for the "price" of a Ford Fiesta! A **logical** choice, **right**_? </small> Just like there is an _entire industry_ involved in "_tuning_" distinctly "_average_" cars (_that weren't made for high performance!_) there's a similar one for "_optimizing_" slow web applications. Organizations end up spending _way_ more time and money (_"engineering" consultants and server resources_!) trying to make their "_old tech_" scale or serve more (_concurrent_) users, than they would simply making smarter tech choices (_and avoiding ["sunk cost bias"](http://www.lifehack.org/articles/communication/how-the-sunk-cost-fallacy-makes-you-act-stupid.html)_). <sup>1: car mod fails: [ridelust.com/30-custom-cars-from-around-the-world](http://www.ridelust.com/30-custom-cars-from-around-the-world) and [bobatoo.co.uk/blog/the-10-worst-car-modifications-ever](http://www.bobatoo.co.uk/blog/the-10-worst-car-modifications-ever) </sup> -->

(Should I Care About) Benchmarks?

Obviously, you should run your own benchmarks on your own hardware/cloud and make informed decisions based on the requirements of your app/product, but ... when we read the stats for how many concurrent users a Phoenix App can handle (with live WebSocket connections) we were blown away! It means we can build our real-time app(s) with 90% fewer resources.

Performance Highlights

All of this means that you spend considerably less money on Hardware/Cloud infrastructure so your app/company can gain a competitive advantage on cost.

If you are in the fortunate position to be considering using something way better for your next project, look no further than Phoenix! <br /> Read more: http://www.phoenixframework.org

Who?

Many people/teams/companies are already using Erlang/Elixir and Phoenix and seeing phenomenal results! <br /> Including: Adobe, BBC, Spotify, Pinterest, Discord (Gamer Chat App), Groupon (Fave), Lonely Planet, Brightcove, Slack ... <br /> See: https://github.com/doomspork/elixir-companies

Who Should Learn Phoenix?

Who Should NOT Learn Phoenix?

<!-- > `help wanted` augmenting this section ... discuss: https://github.com/dwyl/learn-phoenix-framework/issues/14 -->

How?

Assumptions / Pre-Requisites?

Elixir

You cannot build a Phoenix App without knowing Elixir. <br /> If you are new to Elixir, "star" (bookmark) this repo (so you can return to it tomorrow)<br /> and then go to: github.com/dwyl/learn-elixir learn elixir until you feel like you understand the syntax, then come back and learn Phoenix!

Specifically you should focus on learning the Elixir "Basics":

Node.js

Phoenix uses Node.js to compile assets like JavaScript and CSS files (using Webpack). <br /> Simply ensure you have Node.js installed. https://nodejs.org <br /> You don't need to know Node to use Phoenix.

Installation

If you've already learned some Elixir and installed Node.js, then the first step to getting started with Phoenix is installation!

The Phoenix documentation is amazing, so we recommend following the official phoenix installation instructions!

You'll also need to install PostgreSQL, there is a tutorial of how to do so linked in the Phoenix installation guide linked above, but you can also check out our learn-postgresql repo for instructions, and raise an issue if you have any trouble!

While a basic understanding of JavaScript can be useful at times, you don't need to know how to use Node to use Phoenix.

If you're curious why they chose Brunch.io over "alternatives", <br /> the short answer is: Simplicity & Speed! see: http://brunch.io/docs/why-brunch <br /> Note: Phoenix v1.4 (unreleased at the time of writing) uses WebPack for asset compilation, see: CHANGELOG.md

<!-- update this once v1.4 is released! -->

Next?

Familiarize yourself with the "Up and Running" (official) guide: https://hexdocs.pm/phoenix/up_and_running.html#content up-and-running

Practical Examples?

Once you have phoenix installed and followed the official "up and running" guide, <br /> come back and try these beginner-friendly examples:

Book?

We recommend that people buy (or borrow) @chrismccord's book: "Programming Phoenix"<br /> see: https://pragprog.com/book/phoenix14/programming-phoenix-1-4 <br /> phoenix-book-screenshot <br /> The authors are individually impressive and collectively they comprehenisively cover Phoenix like nobody else can! Chris created Phoenix, José created Elixir and Bruce is ultra-experienced technical author with many successful books to his name! <br /> (i.e: the book is the obvious choice for how to learn Phoenix!)

<br />

Video Intro by José Valim (Creator of Elixir)

Jose Valim - Phoenix a web framework for the new web <br /> https://youtu.be/MD3P7Qan3pw

ElixirConf 2016 - Keynote by José Valim <br /> https://youtu.be/srtMWzyqdp8

<br />

Resources

<br /><br /><br />

Our Top 10 Reasons Why Phoenix

"Phoenix provides the productivity of Ruby-on-Rails <br /> with the concurrency and fault-tolerance of Erlang."

  1. Beyond all the (fantastic) technical benefits, what attracts us to Phoenix is the Great Community of people around the world who are excited about making Phoenix an amazing tool for building web apps! <br /> Having welcomming people who will
  1. Phoenix uses the Elixir programming language which means your app is compiled and run on the Erlang Virtual Machine "BEAM". <br /> Erlang is a battle-tested highly fault-tolerant VM used by many telecommunications companies

  2. WebSockets ("channels") are built-in to the framework which means building apps with "real-time" communication and interaction is much easier than virtually any other framework/platform! (no third-party magic module needed! everything you need is already there ready for you to serve millions of people!!) <br /> see: http://www.phoenixframework.org/docs/channels

  3. Easy asyncrhonisity because all programming in Phoenix (Elixir) is Functional! This means it's really simple to abstract useful functionality like request authentication, logging and processing into "piplines" that are easily human-readable! (no third-party async module required! no "promises", "generators" or "observables" to managed!!)

  4. Security & Resilience Mindset is the default. Encryption (SSL) is easy in Phoenix/Elixir and both mitigation of SQL injection, Cross-site Scripting (XSS) and CSRF protection are built-in (enabled by default) so it's virtually impossible for a "novice" programmer to introduce this type of security bug.

  5. Concise Code cannot be understated! We can write way fewer lines than in the equivalent Node.js/Java/Rails/Go app, this means developers are more productive and there is less code to maintain!

  6. Testability due to functional programming of all controllers!

  7. Easy Deployment: https://hexdocs.pm/phoenix/heroku.html

  8. Zero-downtime Deployment is free! (again because of Erlang). Erlang manages transitioning "live/active" users from the old to new version of your app without them even noticing that it was upgraded/updated!!

  9. Built-in Monitoring/Managment of your app through Erlang supervisors mean that you know exactly how your app is performing, what parts have crashed/restarted and why! This is a feature we pay (a lot) for in other frameworks and here it's free!!

Can you think of another reason why using Phoenix is awesome?! <br /> Please Share your thoughts in this thread: https://github.com/dwyl/learn-phoenix-framework/issues/13

<br /><br /><br />

Questions?

Do I need to learn Elixir before trying/using Phoenix?

Yes. See: https://github.com/dwyl/learn-elixir

Do I Need to know Erlang to use Elixir & Phoenix...?

No. You can start learning/using Elixir today and call Erlang functions when required, <br /> but you don't need to know Erlang before you can use Phoenix!

But Phoenix is not "Mainstream" ... Should I/we use it...?

There are many web application frameworks you/we can choose from: https://en.wikipedia.org/wiki/Comparison_of_web_frameworks <br /> So why would anyone select a framework written in a programming language that is not "mainstream"...?

Why are we not using Hapi.js anymore...?

This is missinformation. We are still using Hapi.js for a number of projects where it is appropriate. <br /> This includes several client projects and internal dwyl apps/tools.

We decided to use Phoenix for our new projects for these simple reasons:

For our new projects we need multi-data-center fault-tolerance! <br /> we get that "for free" by using Erlang -> Elixir -> Phoenix!!

In our opinion Hapi.js is still "the best" Node.js framework and we will continue to use and recommend it <br /> to people that need simple apps that scale and are easy to maintain. <br /> see: https://github.com/dwyl/learn-hapi

Also we still use JavaScript for all our AWS Lambda Micro-Services, that is not going to change. <br /> They are simple, efficient and scale really well! <br /> see: https://github.com/dwyl/learn-aws-lambda

What's "Wrong" with using Rails or Django?

The original "productive" web frameworks were "Ruby-on-Rails" and "Django" (python) back in 2005! <br /> (We used both of these for periods in our "journey" and can speak on the advantages of each of them!) <br />

There is "nothing wrong" with using Rails or Django. <br /> We think there are still plenty of use-cases for both frameworks. <br /> We just know that it's (a lot) easier to build "real-time" <br /> with Phoenix because "Channels" (WebSockets) are baked in, <br /> and the Elixir/Erlang concurrency is a whole different ballgame! <br /> Erlang (and thus Phoenix) can handle millions of concurrent users on a single server,<br /> whereas a Rails/Django server can only handle a few thousand (at best!) <br /> if your app is only serving a few thousand people at once, then you're fine!!

We love the fact that Erlang uses "lighweight long-lived" processes, <br /> which means we can connect millions of (IoT) devices ... For IoT Erlang is (unquestionably) the Answer! <br /> For simpler web apps where you only expect a few users per day, Rails/Django are still viable.

But why compromise if you don't have to? <br /> If you can have a Tesla for the "price" of a Ford Focus, why wouldn't you?!? <br /> Why settle for good when you can easily have/use the best?

But GitHub Still Uses Rails ... Surely GitHub is "Scalable"?

Yes, GitHub is still using Rails for their Web App/Site. <br /> But ask any of the core team at GitHub if (given the chance to start over) they would chose Rails<br /> to build GitHub in 2017, and see how many of them say "yes, of course" (with a straight face...)!

Also, GitHub does a lot of things to Scale Rails in the background. <br /> And many of their newer (client-side) features are written in JavaScript! see: https://github.com/github

Bottom line is: anything can be made to scale using "DevOps", <br /> but Phoenix is made to scale by default because Erlang (was) invented (to) scale!

Why NOT Use Go?

"There are two kinds of programming languages - those that nobody uses and those that everybody's bitching about" ~ Bjarne Stroustrup (creator of C++)

Go is very popular. Largely due to the fact that Google "sponsors" it. <br /> It was meant to simplify (replace) C++ and Java inside Google ... <br /> and for the most part, it has succeeded!

We really like Go. It was our "number two" choice when deciding what programming language <br /> (after Elixir) in our "post JS stack"... The decision to use elixir instead of anything else was easy:

Further Reading:

(help wanted expanding this answer...)

Why NOT Use Scala + Play Framework instead...?

If you are already used to writing Java or deploying to the JVM, the Play Framework is a superb choice: https://www.playframework.com <br /> Scala is a good programming language and everyone should learn it! https://www.scala-lang.org/what-is-scala.html <br />

We have used Play a few times (before we adopted Node.js) and really liked it! <br /> But Scala is a "kitchen sink" (multi-paradigm) programming language that allows people to use "all of Java" ... <br /> We think Scala's "Java Interoperability" means it's "too easy" to allow complexity into your codebase. Specifically "OOP Mutation" ...

So why aren't we (DWYL) using "Play" for new projects any more? Firstly, we transitioned to Hapi.js (Node.js) a few years ago because it was more "lightweight" and allowed us to write tiny programs that used only a few Megs of RAM (where our Play apps were very resource-hungry..! have you ever tried running a Scala app on a "basic" laptop like a Chromebook...?)

Summary of "reasons" for Phoenix instead of Play:

We just think that for our project(s) Erlang's Concurrency model works better and Functional code transforming Immutable data is easier to test and maintain.

If you have evidence that "Scala is Simpler" we would love to hear from you! <br /> Tell us: https://github.com/dwyl/learn-phoenix-web-development/issues

Why not use Haskell?

If you like Functional Programming (FP) so much, why not use Haskell?

Please ask more questions: https://github.com/dwyl/learn-phoenix-framework/issues