Phoenix as a Meteor alternative

@jacobin @kaiyes Just an update. I spent a bunch of time working on a new React Starter Template (Purely client side - no backend). https://github.com/ryanswapp/react-starter-template This template is ready to go for production.

I’ve decided to start a tutorial site that I’m currently building so you can plan on that popping up in the next couple of weeks. It’ll focus on Meteor, React, and Phoenix development. Some of the videos I’m planning will discuss my new boilerplate and how its setup. In addition, I’ll show how to build the template for production and deploy it to S3 or Github pages as a static site that talks to a Phoenix API hosted on Heroku.

6 Likes

I know you use webpack but thought I would mention that Phoenix 1.1.2 was released two days ago, which includes the new Brunch with npm support.

2 Likes

Ya I saw that! Had to upgrade to Node 5.4 to create a new app (which is good). Do you know if Brunch creates client bundles for you? Or is it like Grunt/Gulp where you have to run your code through Browserify?

I’m really comfortable with Webpack now and it is amazing so I don’t think I’ll be switching any time soon. I also don’t think Brunch supports hot code reloading?

That said, if I build an app without a React frontend I’ll most likely just use Brunch

Have a look here on how to use react with the new version of brunch in phoenix: https://medium.com/@diamondgfx/phoenix-v1-1-2-and-react-js-3dbd195a880a#.sbaj68qi4

1 Like

Ya it looks pretty straightforward. The only problem is that the vast majority of the react ecosystem uses webpack so all the tools are designed around webpack. :frowning: I used to not be a big fan of webpack but now I love it! Tough learning curve for sure, but it’s a great build tool.

@ryanswapp There is a new phoenix react example that’s been brewing the past couple weeks. It’s a Trello clone. The blog is up to 4 parts now. Hopefully it has some ideas for you to use.

Elixir.
Phoenix
Ecto
PostgreSQL

Webpack
Sass
React
React router
Redux
ES6/ES7 JavaScript

2 Likes

That’s pretty cool. I hadn’t seen that. Thanks for sharing!

What a nice discussion! I followed Meteor when it was still < 1.0. This was when I was first leaning web development and It was the first web framework I liked, before I tried Django but the experience repelled me.

I ended not using Meteor because one of my basic needs was to serve JSON and this is/was difficult (maybe the situation has changed since). I finally when with Dart because I liked the idea of sharing code between client and server (I don’t think like this anymore). Ended up ditching Dart in favor of Elixir after investigating about scalability for a month (contendors where Go, Scala, C#).

Phoenix is a really nice framework that takes a lot of the good things that Ruby brought to the scene. Here are some remarks about Meteor vs Elixir/Phoenix.

Meteor

Pros

  1. Dead simple realtime with database pub/sub to live updates. This problem is hard to tackle and you have to create a lot of infrastructure to do it elsewhere.
  2. Easy to get started. Client and server on the same project.
  3. Lots of libraries.

Cons

  1. Diverges a lot from standard web dev, e.g. creating a REST API is not easy.
  2. Too much magic. This magic gets you started easily but can bite you later.
  3. If scalability becomes a problem you might have reached a dead end. Meteor is too opinionated.

Elixir/Poenix

Pros

  1. Scales
  2. Phoenix is an excellent framework for general web development.
  3. FP is an excellent paradigm.
  4. No JavaScript! Well, at least not on the server. People here favor using Elm on the frontend a lot, so even better.
  5. Fault tolerance and all the OTP goodies.

Cons

  1. If you want all the magic Meteor does with its pub/sub and automatic update system you are going to miss it.
  2. Starting isn’t as easy. Meteor is excellent for total newbies to web dev to get something up and running.
6 Likes

Any chance you got to do this? Very much interested in the possibilities of this “marriage”

Ya I did build a little app that used Rethink changefeeds with Phoenix channels! I never ended up writing a post mostly because I’ve been swamped with school and work (in addition to being a bit burnt out). In order for changefeeds and channels to be useful you’d need to write some type of abstraction layer that interprets the changefeed output as its not as straightforward as it seems. I know Peter Hamilton (the RethinkDB driver author) has done some work in this area so I’ll need to check out what he’s done and revisit my example app before I publish anything. Thanks for the reminder though! I need to play with that stuff a little more…

4 Likes

There was a related Erlang Factory talk recently.

1 Like

For those who only compare Meteor with phoenix , beware, there is another alternative.

2 Likes

@ramstein74 this is really interesting! I think the main draw for Erlang/Elixir for me is not using JavaScript, not having the micro package issue (1000 deps in a small project), and the error handling philosophy.

But that looks pretty neat for JavaScript though :thumbsup:

3 Likes

There is also a nice article, which shows, how to use react (+ redux, + router), phoenix and have react server-side rendering :wink:

2 Likes

So why not use Firebase, Redux, and RiotJS. Small and relatively cheap. RiotJS makes it easy to cross compile whatever to JS (if it has a cross compiler of course).

Interest to see where you have got. Looking at using React+Redux+Phoenix

kind of interested in using RethinkDB, however, one thing occurs to me, for reactivity, it seems elixir is in a good position to do notifications in between your data layer and clients.

2 Likes

@keithnicholas I actually haven’t spent a ton of time on RethinkDB as of late. I’ve been doing a bit of elixir but mainly messing with OTP and trying to understand it more deeply. I think React/Redux + Phoenix (RRP) is awesome! Elm + Phoenix (EP) would be cool but I’m just not familiar enough with Elm to feel like I could be productive. Still too many unknowns. I’d say give RRP a shot!

You’re right that Phoenix is in a good position to efficiently communicate between the client and server! I love that about Phoenix. It also sounds like since this is the case you may be thinking of using another database? I’d say use whatever you want! You can make anything close to real time (although RethinkDB makes it a lot simpler).

Another thing to consider is how you’ll structure your app. There has been a lot of talk recently about having a main elixir app and then using phoenix as a separate application merely as an interface to the web. Here is a great talk about it https://www.youtube.com/watch?v=lDKCSheBc-8 I think this is probably how you should structure your app if you are building anything serious. I’m not sure how familiar you are with OTP so this may be more or less confusing. If you are less comfortable I’d recommend Elixir in Action. It’s an excellent book!

One more thing and I’ll shut up (this stuff just gets me excited). I’d highly recommend using GraphQL instead of REST. There is an excellent elixir graphql library called Absinthe http://absinthe-graphql.org/ There is a nice tutorial on their website to help you get started (you may already be all over this but figured I’d mention it). Also, here is an example app if you want to see what it looks like https://github.com/ryanswapp/react-redux-phoenix-graphql-example

Let me know if you have any questions. :slight_smile:

8 Likes

I’m going to be using this in the near future for a prod app. Currently i’m just long polling to get things going but it’s pretty nice to subscribe to a change feed and have Phoenix push down updates. On the client you just dispatch a single update action in the Phoenix channel callback and the whole UI updates :grinning:

2 Likes

Awesome new tutorial covering Phoenix, React & Redux by Sam Corcos: https://www.learnphoenix.io/

2 Likes

This framework is cool :smile: i already use it on production and its really really fast but i still use meteor on some of my projects that’s not need scalability