/learn-phoenix-framework

:fire: Learn to use a productive web framework that does not compromise speed, reliability and maintainability! :rocket:

Primary LanguageElixir

Learn Phoenix (Web App) Framework

phoenix framework logo

Learn how to use Phoenix Framework to have fun building real-time web/mobile apps
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
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).
But if we go by what is "popular" we would still be riding horses (and carts) to work and no progress would be made.

Phoenix is like having a jetpack (with unlimited free environmentally-friendly fuel!!);
it gets you (your app) to where you need to be so much faster!

Seriously, once you deploy your first Phoenix app you will feel like you're freakin' Iron Man Person! iron-man-flying 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!
check them out: https://github.com/dwyl/learn-elixir#why

What?

A web application framework without compromise!

Metaphor

You can spend years (and mountains of money) "performance tuning" an "old banger" attempting to make it go faster ... car-mod-fail See more car mod fails at: http://www.ridelust.com/30-custom-cars-from-around-the-world and/or http://www.bobatoo.co.uk/blog/the-10-worst-car-modifications-ever/

Or... just get the best car that was built for speed, safety and environmental friendliness and stop wasting your time on the past!

model-s-photo

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 "optimsing" 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.

### (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!

Performance Highlights

  • considerably lower latency and request response time than anything else! (thanks to Erlang's lightweight processes and ultra-efficient network/message handling)
  • 4x more requests-per-second than the equivalent Node.js (Express.js) App.
  • 9x more throughput than a Python 2.7 based app. (blocking really sucks!)
  • 10x - 100x more requests handled than Ruby-on-Rails (depending on the type of app!)
  • Similar performance to Go on a single server, but a much simpler multi-server concurrency model, so horizontal scaling across multiple data centers ("availability zones") is much easier! (Erlang manages the resources for multiple servers/processors as a single app "fleet" and delegates requests/processing to them across clusters/zones!)

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!
Read more: http://www.phoenixframework.org

How?

Assumptions / Pre-Requisites?

Developer Checklist?

Elixir

You cannot build a Phoenix App without knowing Elixir.
So if you are new to Elixir, "star" (bookmark) this repo
and then go to: github.com/dwyl/learn-elixir

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

  • types of data
  • atoms
  • pattern matching
  • maps
  • function definitions
  • modules

Node.js

Phoenix uses Node.js (specifically http://brunch.io) to compile assets like JavaScript and CSS files.
Simply ensure you have Node.js installed.
You don't need to know how to use Node to use Phoenix.

"Hello World" Example (5 Mins)

TODO: add a basic but practical tutorial here ... help wanted

### Next?

Familiarize yourself with: http://www.phoenixframework.org/docs/up-and-running

Meanwhile, we recommend that people buy (or borrow) the book:
phoenix
see: https://pragprog.com/book/phoenix/programming-phoenix
it's written by @chrismccord who created Phoenix.
(i.e: it's the obvious choice for how to learn Phoenix!)




Who?

Many people/teams/companies are already using Erlang/Elixir and Phoenix and seeing phenomenal results!
Including: Pinterest, Groupon (Fave), Lonely Planet, Brightcove ... See: https://github.com/doomspork/elixir-companies

Who Should Learn Phoenix?

help wanted augmenting this section ... discuss: dwyl#14

Resources

Video Intro by José Valim (Creator of Elixir)

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

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




Our Top 10 Reasons Why Phoenix

"Phoenix provides the productivity of Ruby-on-Rails
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! Having welcomming people who will
  • help you when you get stuck, patiently explaining things
  • answer questions (both "noob" and "advanced") and
  • openly discuss your ideas for improvements.

1. Phoenix uses the **Elixir** programming language which means your app is compiled and run on the ***Erlang Virtual Machine*** "BEAM".
Erlang is a battle-tested highly fault-tolerant VM used by _many_ telecommunications companies
  1. 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!!)
    see: http://www.phoenixframework.org/docs/channels

  2. 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!!)

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

  4. 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!

  5. Testability due to functional programming of all controllers!

  6. Easy Deployment: http://www.phoenixframework.org/docs/heroku

  7. 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!!

  8. 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?!
Please Share your thoughts in this thread: dwyl#13




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,
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
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.
This includes several client projects and internal dwyl apps/tools.

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

  • Elixir is a nicer language than JavaScript. #LessIsMore #LessButBetter #SmallIsBeautiful #SyntaxMatters
  • JS can be functional, whereas Elixir is (always) Functional! The distinction makes all the difference!
    With "functional" programming, the programs are a lot easier to think about while you are writing/maintaining them!
  • Elixir uses the Erlang VM which is way more efficient/powerful than "V8"
  • The Erlang VM scales much easier to multi-core multi-server multi-data-center than Node.js
    (or pretty much anything else for that matter!!)

For our new projects we need multi-data-center fault-tolerance!
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
to people that need simple apps that scale and are easy to maintain.
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.
They are simple, efficient and scale really well!
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!
(We used both of these for periods in our "journey" and can speak on the advantages of each of them!)

There is "nothing wrong" with using Rails or Django.
We think there are still plenty of use-cases for both frameworks.
We just know that it's (a lot) easier to build "real-time"
with Phoenix because "Channels" (WebSockets) are baked in,
and the Elixir/Erlang concurrency is a whole different ballgame!
Erlang (and thus Phoenix) can handle millions of concurrent users on a single server,
whereas a Rails/Django server can only handle a few thousand (at best!)
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,
which means we can connect millions of (IoT) devices ... For IoT Erlang is (unquestionably) the Answer!
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?
If you can have a Tesla for the "price" of a Ford Focus, why wouldn't you?!?
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.
But ask any of the core team at GitHub if (given the chance to start over) they would chose Rails
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.
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",
but Phoenix is made to scale by default because Erlang (was) invented (to) scale!

Why NOT Use Go?

Read: https://www.reddit.com/r/elixir/comments/3c8yfz/how_does_go_compare_to_elixir
(help wanted expanding this answer...)

Why NOT Use Scala and 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
Scala is a good programming language and everyone should learn it! https://www.scala-lang.org/what-is-scala.html

We have used Play a few times (before we adopted Node.js) and really liked it!
But Scala is a "kitchen sink" (multi-paradigm) programming language that allows people to use "all of Java" ...
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 maintain that Play/Scala still has plenty of valid use-cases.
  • Elixir is way simpler than Scala.
  • The Erlang VM is way better at concurrency than the JVM.
  • We love the fact that all data is immutable in Elixir.
  • We love how few resources it takes to run a Phoenix app (e.g on a Raspberry Pi!!)

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!
Tell us: https://github.com/dwyl/learn-phoenix-web-development/issues

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