Rails vs Phoenix

Channels, use the right tool for the job (asset pipieline, more in the DB, GNU gettext), changesets, explicitness, Phoenix is not your application, raw performance while pretaining general pleasure, View <-> Template distinction

What do you miss from Rails?

Eco system. Not only gems (something good & stable devise-ish comes to mind), but also integrations for bug monitoring, application performance monitoring and all that. Easy integrations for useful services e.g. relating to payment etc. - in general we found everything we needed though (PostGIS, JWT & friends)

Where are they similar?

Overall MVC structure (although that seems to change) and a focus on developer happiness and productivity and largely a nice community.

Where do they differ the most?

Phoenix is not your application vs. holy monorail of all the things that even inlines perfectly fine library functionality (timecop). Also to the point where Phoenix is more a normal elixir/mix project whereas Rails is… a Rails project.

When would you use/recommend either?

Basically I’d wanna check if:

  • is my team up for using Phoenix? Do people want to? Have we had previous experience? Are people ok with doing some FP?
  • how big is the project (if not much previous phoenix experience I’d tend to hesitate to bet on it)
  • are the libraries in the eco system that I need from what I see from the general feature set
  • does the application call for websockets/long polling?
  • how much traffic will the application be under?
  • is it viable to onboard people and be a bit less productive in the beginning?
  • Who will maintain the project? (e.g. for client work)
  • is this a project we will work on for long or is it a quick one off (I tend to say that I think you can still build things a bit faster in rails in the beginning, but I feel like in the long term phoenix becomes faster due to more explicitness it’s easier to understand and extend)

Anything else you’d like to share?

Thanks for Elixir and Phoenix. It’s a joy for me and I love it very much although we should avoid the “it’s better than everything else!!!”.

Just gave a talk at Rubyconf.pt about Elixr and Phoenix - people loved it and were very interested :slight_smile:


These tasks are more complex in Elixir, b/c a typical application consists from dozens independent apps. But there is a plenty of projects that provide some opportunities in these areas:


Having suggested coherence in place of devise; what is recommended to fill the authorisation role of pundit?


For those interested in auth, have a look at this thread :slight_smile:

1 Like

It appeals to me that here is a web server technology that will spread it’s workload across multiple cores working concurrently and do so implicitly without a special rewrite. Low power multicore CPUs (e.g. Octacore ARM) offer high throughput at very low cost. This massively reduces the need to crank up multiple instances as workload rises (in the way cloud providers love to do). This is about Elixir/ BEAM more than Phoenix but they are inextricably linked.

The other comment is that with Rails: background jobs need extra plumbing and often extra external processes that have to be configured and coordinated at every turn. Phoenix by contrast appears to encompass such capabilities without fuss.


We now have a thread (missing libraries and tools) setup to do exactly that.

I don’t think that way of pundit (too implicit) is acceptable in FP point of view.
Though you could give a try to https://github.com/cpjk/canary (inspired by cancancan)

Hey there :slight_smile:

Yes I know a lot of these projects but I still find them… lacking. Plugsnag for instance doesn’t handle channels and has some other problems which is why we wrote bugsnex. Appsignal just added very rudimentary support for channels, before there was none. newrelic.ex is fairly new and I haven’t had a look at it yet etc. - I know the ecosystem is moving forward but it’s still a stopping point for me sometimes as some of the solutions are also not as battle tested yet. E.g. as you point out in the README the older newrelic agents suffered from some problems.

All that said, I see it moving in the right direction and also heard whispers of other performance monitoring services adopting Elixir/Phoenix :slight_smile:

I agree. These projects provide only part of possible features, but the current situation is much better than a year ago… So it’s in our hands :slight_smile:

ha definitely! Even than ~ 7 months ago (when we started our Phoenix project) and hearing also how companies want to support it all around. Was happy to see in the missing libraries and tools that someone is already working on PayPal integration!


Thank you for the recommendation. My experience of cancancan was that it was great for smaller projects; however with larger projects it was not so good; mostly in terms of runtime overhead.

Rails has a joy in the wealth of GEMs available but it can be a major task to work out which, if any will be suited to a project and actually go the distance.

canada is based on protocols, so quite fast, the only slow part might be what you do for the checking, but even that is done concurrently (unlike in ruby). :slight_smile:


I don’t know if you found it already, but the lib you are searching for is named bodyguard.

1 Like

Thank you kindly sir - much appreciated.

1 Like

Haven’t read this yet, but it might help folk who’d like to compare the two:


Cool link, but holy hell that popup ad on their page that appeared after a minute needs to die, hate hate hate hate those things…


I also like this post by Rafał Radziszewski in response to this answer in a Quora session with DHH:

(Jump to the last paragraph if you’re feeling lazy)

Short answer: yes, it’s definitely reasonable assumption.

Long answer:

The main thing about Elixir is that it’s not like Ruby at all. When I was about to start using the language, I had the opportunity to talk to Jose Valim (language creator) on a conference and I asked him what his advice was to start with. At the time I was a RoR dev with a year of software house experience and a few projects on production already done. He told me: “you must remember, that it looks like Ruby, but it’s not Ruby at all”. Though simple, it was the best advice I have ever received.

First of all, Elixir is functional. Not getting into formal definitions and stuff, what it means is you’re going to write code in much different way that before. No longer will you iterate over array changing it elements one by one and then return the same array. No longer will you mutate state of object(struct). No longer will you create hierarchies and inherit stuff. What this means is many ways you used to solve problems will be no longer available to you.

Personally, it was not that hard for me, because as it turned out, I started to do quite a lot of things in functional way in Ruby before. For me, it was quite often simpler and more “natural” solution, but I know quite a lot of people who had issues with that - depends on how your brain is wired I guess.

Second thing is, you’re going to need to learn new ways of doing stuff. Pattern matching, map, filter, streams. Grokking the fact that “=” is now pattern matching, not assignment and the consequences of that. Getting used to tuples and structs. Using modules as main code entity. The list goes on and on.

Third thing is getting to know Beam VM. This means understanding Elixir model of concurrency, grokking processes, understanding how to use GenServers. This is fun, but might take you a while to process. Most of the people are not used to thinking of your code in terms of different processes and async operations. I know I wasn’t. To this day I do not consider myself proficient in that area.

So the question you have in your mind now is probably along this lines: “why bother”? Why would you spend so much time relearning your basic problem solving skills instead of being productive in what you already know?

In my case, the answer is: it is SIMPLER. Yeah, really! Once you start grokking this thing, it will time and time again prove to be easier to do stuff. You want to know why some function does not behave in a way you think it should? You check the source of the FUNCTION. You do not care about state, you do not care about previous operations. You just check the function.

You debug stuff? It’s easy to see what’s going on in any given state. Variables are immutable, so you know for sure what is the state of one for a given set of starting parameters. You just need to add breakpoints along the way to see where it stops behaving like you wanted and the error is likely to be easy to spot.

You decide that you want to refactor? Cool, because it’s just functions. You can move them around and fix namespacing. There is no state you need to be worrying about.

Finally, you want some concurrency? You’re welcome. Adding messaging feature to your app is a day’s work, and that’s only because frontend takes some time usually. It’s so simple. The same for adding some temporal storage and many other features. Finally, you can keep state in isolated areas, that you make as simple as possible and about which it is quite easy to reason. Actor model is a sensible solution. Concurrency is fun, instead of terrifying.

And when we get to frameworks and libraries - Phoenix is simple too. No monkey patching. No over-abstracted functions nobody understands without spending an hour staring. No hidden state and no gotchas. Just a bunch of functions tied together, that’s how simple it is.

So yeah, I believe more people will move to Elixir. Not because it’s more performant (though it is and it means that you have longer run before you actually need to start optimizing), not because VM has nice features (though it has, hot-deploys possibility being one of them), not because you can actually write efficient concurrent code (though you can and using one of top industry solutions). I believe people will move, because it’s actually simpler. Simpler in a good way, like Unix is in many ways simple. And simpler means less time for wondering “what the f*** is going on here” and more time for actually writing cool stuff. [/quote]


Assuming one is building a fairly vanilla, server-generated HTML web application, what does Phoenix do better than Rails? Where could Phoenix use some improvement? I’ll start:

Things I love about Elixir/Phoenix when compared to Rails:

  • The explicit nature of FP seems to improve code clarity. This is most noticeable when I modify old code or review someone else’s code.
  • Plug is more user-friendly than Rack. Pipelines allow for a zen-like simplicity of request processing.
  • Speed. I don’t care so much about getting every last ms out of response times. I do care about lowering server costs without sacrificing productivity, and I think Phoenix gets this right.
  • Community. The Ruby/Rails community is great, but I don’t think it’s as great as the Elixir community :smile:

Things I don’t love about Elixir/Phoenix when compared to Rails:

  • Deployment. I would love to have Heroku-like deployment that’s compatible with all the OTP goodness.
  • Libraries. Elixir has a lot. Ruby has a metric tonne. :slight_smile:
  • Books, blogs, and searchable knowledge. Ruby/Rails has more of it, by virtue of its popularity and age.
  • Initial development speed. I have more initial productivity with Rails, but maybe that’s just due to familiarity.
  • But mostly deployment.

Could you be more specific about what you think is missing in terms of deployment? Maybe it’s already there :slight_smile:

Rails (and AR) is better because: more magic. If you know it, you can make stuff incredibly fast.

But, do you remember you first days with Rails, trying to understand why is it working? I do remember that nightmare.

So, Phoenix (and Ecto) is better because: less magic. It is way more readable and easier to learn. Few more lines won’t kill you, and could make all the stuff clearer.