Phoenix as a Meteor alternative

Lately, some of us discovered Phoenix, the framework, written in Elixir(Erlang). Why is it great?

Among pros - it is fast, battle-proven, has support for multiple databases, has channels for real-time streaming. Since some of us already moved our apps to using React, we may consider switching to Phoenix.

The framework was mentioned in some forum topics, so lets discuss it here. I personally want more tutorials or videos, how to make a great real-time app using channels + webpack + React, something to feel like Meteor (autoupdate on new/updated/deleted) items, etc.

It anyone has experience with this framework, please share with the rest of us.

18 Likes

This is a great discussion topic, it will also help the Meteor community to enhance its skills and find maybe some good patterns in Phoenix and apply them in Meteor.

I just read a little about Phoenix and I like the fact that it is made for full featured web apps like Rails and is not just a small specific framework for specific things. It can be used to handle very big apps from A to Z and is made for people like us, who want a full featured framework like Meteor.

Iā€™d love to build web apps with Phoenix like I do with Meteor, meaning using a simple Pub/Sub mechanism, simple authentication and easy building. I donā€™t really care about isomorphism, in fact, I prefer when things are better separated, I always use Meteor with methods and never use Allow-deny (I deny everything and control that in the methods).

4 Likes

There certainly is no lack of information on Phoenix/Elixir. New videos and tutorials seem to come out on almost a daily basis. The documentation is excellent, including detailing how to easily replace Brunch with Webpack.

There are a handful of React/Phoenix integration videos and a slew of blogs. However they havenā€™t appeared to settle on Redux from what I can tell, itā€™s mix and match.

In terms of just getting a feel for Elixir, I would suggest searching for any related Dave Thomas or Jose Valim videos.

Here is a playlist from an Elixir conference in October. One thing that caught my interest was the ā€˜Whatā€™s next for Phoenixā€™ video. In it they discuss how GraphQL is highly parallelizable and a perfect fit for Elixir. :smile:

1 Like

I remember @SkinnyGeek1010 mentioning this.

1 Like

I think this is super important for the health of the Meteor community. Elixir and Phoenix are popular because the theyā€™re borrowing ideas from other places. This inspired me to write a blog post (just flipped it to live after reading this) on how Meteor can improve itā€™s quality and cohesiveness by borrowing some of these features.


I'm also finishing up a server side router framework based on Phoenix's 'user experience'. However it's just for restful routes: [27th comment on this thread](https://forums.meteor.com/t/use-functional-programming-to-simplify-your-meteor-code/9915/27)
I'm also finishing up a solution that will dig me out of an upcoming scaling issue for a client app. I'm bypassing Meteor's oplog issue by using Phoenix to handle realtime needs (albeit my use case is fairly simple so it works out well).

It ends up working like @ccorcos 's any/db package where you can use minimongo as a cache so the client listens to an ā€˜on msg:newā€™ event and stores the response.

Itā€™s not quite ready as far as benchmarks and documentation but iā€™ll have that and a blog post soon. The bottleneck in the setup is how fast Meteor can server the html page (which is a better problem to have!)

// upset into minimongo on new message
channel.on("new_msg", doc => {
  Chats.upsert(doc._id, doc);
})

channel.join()
// prime minimongo with last 20 chats on join
.receive("ok", resp => {
  resp.initialChats.forEach(doc => {
    Chats.insert(doc);
  });
})

and then only a few lines of code in phoenix (itā€™s only handling publication logic). Pubsub can be authorized with the loginToken and a simple function to retrieve the user doc of that token.

  def handle_in("new_msg", payload, socket) do
    # run model validations
    changeset = Chat.changeset(%Chat{_id: payload["_id"]}, payload)
    {status, result} = Repo.insert(changeset);

    if status == :ok do
      # send to all users sub to lobby
      broadcast! socket, "new_msg", result
      # don't return anything to browser that 'called'
      {:noreply, socket}
    else
      {:noreply, socket}
    end
  end

[quote="jacobin, post:3, topic:13519"] One thing that caught my interest was the 'What's next for Phoenix' video. In it they discuss how GraphQL is highly parallelizable and a perfect fit for Elixir. :smile: [/quote]

Itā€™s interesting they have a roadmap and discuss future plans :smile:

4 Likes

Very interesting article, Iā€™m so tempted to learn Elixir/Phoenix while still using Meteor on the side.

2 Likes

Iā€™m so tempted to learn Elixir/Phoenix while still using Meteor on the side

If you do itā€™ll help you write better JavaScript, guaranteed.


I forgot to add this, hereā€™s a diagram from this talk on how Meteor realtime works:
Phoenix - a framework for the modern web - Chris Mccord on Vimeo

2 Likes

What do you suggest me to read : Programming Elixir or Elixir in action ?
Elixir in action is more recent and I always liked the books from Mannings (I read Meteor and Express in action).
Programming Elixir is older (october 2014) but people seems to say that the author is a very talented developer.

1 Like

Where do I find Elixir LiveData DDP module?

I would go with Programming Elixir first and then if youā€™re still interested and want to take a deeper dive, Elixir in Action as well. Iā€™ve read the first and the first half is one of my favorite books of all time. He does an awesome job of making you ā€˜think differentā€™.

Phoenix also has an ebook in beta thatā€™s really good!

Are you referring to the one I was working on? If so I donā€™t think thereā€™s going to be an easy way to hook it up directly to Meteor publications. For now iā€™m skipping the middleman and just having the Meteor browser client connect directly to phoenix like in the github repo:

https://github.com/AdamBrodzinski/meteor_elixir

Definitely donā€™t read Elixir in Action until you are more at an intermediate level. Iā€™d say start reading Programming Elixir and then start working on exercism problems. Once you are comfortable with Elixir, start reading Programming Phoenix. Thatā€™s a pretty good path to get started.

1 Like

Dave Thomas has half a dozen Elixir related videos on youtube. Every one is eye opening. He has a great sense of humor and makes functional programming quite approachable for those with an imperative background.

2 Likes

Iā€™ve spent a good amount of time with Elixir and Phoenix over the last few months and all I can say is that it is awesome! It feels like they have done everything right. Here are some things I like about it:

  1. You can use any database with it!! It defaults to Postgres but its database management tool Ecto officially supports MySql, Mongo, etcā€¦

  2. Testing is a first class citizen. In Meteor we have all struggled with testing. It is super hard to do in the current state of Meteor. However, in Phoenix, itā€™s dead simple. The Elixir/Phoenix team comes from Ruby land where testing is top priority and it shows with the current state of the Elixir ecosystem.

  3. This may seem silly, but coming from Meteor I really like that Phoenix has a built in Router. WE SHOULDNā€™T BE ARGUING ABOUT WHICH ROUTER PACKAGE TO USE. This should be a convention.

  4. Elixir is functional! Itā€™s hard to describe how much better functional programming is than object oriented programming when it comes to web development. Phoenix is just a bunch of functions that transform a request one function after another until a response comes out at the end. IT IS SUPER SIMPLE. Phoenix doesnā€™t feel like magic on top of Elixir. Itā€™s really easy to grasp.

  5. Phoenix is fast and powerful! It beats out virtually any other framework out there (including Java and Go frameworks). Check this out https://gist.github.com/omnibs/e5e72b31e6bd25caf39a Phoenix has actually gotten faster since those benchmarks as well.

  6. Elixir is pretty Erlang. Erlang is battle tested. If you build with Phoenix you wonā€™t have to think about scaling. The Elixir package management server runs on a free heroku instanceā€¦ Just think about that.

  7. Phoenix makes real time programming dead simple. Phoenix is built for real time web apps and makes a good companion to React or another frontend framework.

  8. It is easy to augment or extend. Because Phoenix is just a bunch of functions that transform a request it is easy to add more functions or remove functions. You have total control.

  9. You can drop in any kind of frontend build system you want. It defaults to Brunch (a super easy build system) but you can drop in webpack, gulp, whatever with no problems.

There are tons of reasons why Elixir/Phoenix are great but Iā€™m tired of typing so let me know if you have any other questions!

19 Likes

Is there an Atmosphere equivalent? Where is the go-to place for Elixir and Erlang libraries? Iā€™ve seen the above but Iā€™m sure there must be more. Iā€™ve seen reference to ā€˜thousands of erlang librariesā€™ mentioned.

Yup. The package manager is called Hex. http://hex.pm is the website

1 Like

Thanks, I just bought Programming Elixir !

You really converted me guys haha, Iā€™m young and always learning new stuff, I discovered web development with JavaEE and Srping, then used Grails (Groovy) (which is one of the best framework I ever used).

I never really liked Javascript because I find that all what I learned in my Software engineering education was useless and that a lot of the people in the community donā€™t have the basics in computer science. But I didnā€™t have a choice since it is (was :stuck_out_tongue: ) all about Node.js, so I jumped in the train, used a little bit of express but then discovered Meteor and felt in love with it because of the ā€˜ā€˜structureā€™ā€™ it gives. But I was still trying to use my old habits and never really embraced javascript as a language, I just force myself to love it.

Now I will probably focus on Elixir if I like it, I prefer to learn something more specific and ā€˜ā€˜future proofā€™ā€™ than knowing a technology that everyone can use without understanding the core concepts of computer sciences.

(Of course, I will still use Meteor for small personal projects, and If I feel that the project needs to be more serious or needs to scale, then Iā€™ll use Elixisr/Phoenix or mix both !)

I feel like I just discovered the light haha :smiley: (btw, Iā€™m 22).

2 Likes

So if I want to exclusively use React with Phoenix, would I ignore Phoenix template related stuff and just focus on channels?

1 Like


http://blog.brng.us/2015-08-04-using-reflux-to-broker-events-with-react-and-phoenix.html

Iā€™ve seen a number of examples which still use a template to render the React components into. I believe @ryanswapp did this as well when I checked his boilerplate.

Like everything else though, in Phoenix a template is just a function. I imagine you can remove it from the pipeline in the router and use JSON for your application protocol, but you still need some way to send the html down to the browser.

Iā€™ve been using the Meteor framework for work over the last year. While itā€™s nice to work in and gives you a lot out of the box, ultimately there are fundamental flaws in the design that become too tedious and limiting in the long run.

https://rhythnic.wordpress.com/tag/react-js/

p.s. I happened upon this blog of someone who switched from meteor to a PRRR stack. Phoenix/Rethink/React/Reflux. Interesting read.

1 Like

OK, thereā€™s plenty of ā€œwhy Phoenix is a better choice than Meteorā€ arguments above. But what would be nice to get is - what are advantages of using Meteor over Phoenix? I can think of the most obvious one being ā€œusing the same language everywhereā€. Which is a bit sad actually because this language is Javascript, but hey, itā€™s still one to rule them all.

So after getting to know Phoenix and its ecosystem, can you think of other things? What are the reasons to stay with Meteor in your opinion other than ā€œMDG guys are niceā€.

3 Likes

It would be great if someone familiar with both frameworks( Meteor and phoenix) list down some advantages of phoenix over meteor.