Phoenix as a Meteor alternative


#1

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.


A way to be a better programmer in 2016
React Router vs Flow Router
Apollo Tutorial and general stability
Meteor in Front, Phoenix in Back
:vertical_traffic_light: TRANSMISSION #1: a weekly show w/Sashko broadcasting the latest from Meteor Forums
#2

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


#3

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:


#4

I remember @SkinnyGeek1010 mentioning this.


#5

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:


#6

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


#7

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:
https://vimeo.com/131633172


#8

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.


#9

Where do I find Elixir LiveData DDP module?


#10

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


#11

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.


#12

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.


#13

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!


#14

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.


#15

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


#16

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


#17

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


#18


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.


#19

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


#20

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