30

I'm going to develop a collaborative site, and one of the features will be collaborative editing with realtime changes. i.e. when two or more users are editing the same doc, they can see each other changes as soon as they happen. I have some experience with Ruby on Rails, so I was thinking about using EventMachine, but with all this hype around Node.js, I am know considering using it instead. So, what would be the main benefits of using Node.js instead of EventMachine?

tl;dr What are the main differences between EventMachine and Node.js (besides the language)?

Pablo B.
  • 1,813
  • 1
  • 17
  • 27

5 Answers5

72

EventMachine has nothing to do with Rails apart from them both being written in the same language. You can get EventMachine as bare as Node.js; all you have to do is not add libraries to your project. In my experience the EventMachine libraries (like em-http) are much nicer than anything for Node. And you can use fibers instead of callbacks to avoid callback hell. Complete exception handling is pretty much impossible in Node because of all the callbacks. Plus Ruby is a nicer, more complete language than Javascript.

Phil Kulak
  • 5,882
  • 8
  • 40
  • 46
  • 7
    If you use Deferreds and Promises in Node.js (as is very common), you can use exception handling in asynchronous code very nicely. See for example https://github.com/kriskowal/q – edwin Jan 14 '13 at 12:11
  • 3
    @Phill Kulak, I wonder, would your answer be the same by 2014? – scaryguy Oct 09 '14 at 11:33
  • 3
    @scaryguy Well, I think EM is a dumpster fire at this point, so probably not! – Phil Kulak Oct 09 '14 at 14:38
  • @PhilKulak Why? People keep stating things like this about EM as fact but never explain why EM isn't good. I think Node.js is great but I still prefer EM with Ruby and find it to be just as capable(if not more so). – Ravenstine Oct 24 '15 at 16:44
21

I tend towards the "use what you know" (even if it's a heavier architecture). Because of that, I don't see it being quite as simple as "EventMachine vs NodeJS." Mainly, the difference can be summarized as this:

  • NodeJS is a framework/language that was written to handle event based programming in JavaScript. That is its driving force. It's not an after thought, or a third party mechanism. It's baked right in to the language. You create callbacks/events because that's how the language is built. It's not a third party plug in, and doesn't alter your workflow.
  • EventMachine is a gem in Ruby that gives developers access to some of the goodness of the event based programming model. It's heavily used and well tested, but not baked directly in to the language. Both are locked to one CPU, but with event programming at Nodes core, it still has a leg up. Ruby wasn't written with concurrency in mind.

That said, technical problems can be overcome. The more important questions (from my view) that should guide your decision are these:

  • What will your production environment look like? Do you have complete control over the server? Can you host it however you want? Or will it be on a shared system to start with, and then you have to expand on that?
  • Do all the developers on your team have the ability to learn a new language very fast? How fast will they be able to understand an event-based language like JavaScript for the middle tier?
  • Do you need all of the architecture that Rails gives you (full Testing framework, scaffolding, models, controllers, etc)? Or is that overkill?

There are quite a few technical differences between the two. One is a language, one is a framework. Really, how heavy of a stack you want to run? How much learning will your developers have to do? Do you want a full stack the gives you a lot of niceties, that you may not use, or do you want a bare bones set up that runs extremely fast and concurrent, even though you may have to write extra boiler plate code and learn a new lanugage?

While Rails is not as heavy as some web application architectures, you're still going to need more processor power than you would to handle a similar amount of throughput in NodeJS. Assuming quality code for both systems. Bad code written on either stack is going to prevent the stack from shining. It really comes down to- Do you really want to learn a whole new way of doing things, or utilize your current understanding of Ruby to get things off the ground fast?

I know it's not really a definitive answer, but I hope this helps guide you to a decision!

Christopher WJ Rueber
  • 2,101
  • 15
  • 21
  • Thanks. So, if I understood well, the main (dis)advantage of EventMachine is Rails? So, if I don't need Rails or if I need something lighter then I should go with Node.js? – Pablo B. Apr 04 '11 at 18:33
  • 3
    Yup. That's how I would make the decision. They're both perfectly acceptable eventing mechanisms (though eventing is at the core of Node.js because that's how the language is actually written), it's a question of how much architecture you want built up around those systems. – Christopher WJ Rueber Apr 04 '11 at 18:47
  • Nice, I'll give Node.js a try if it doesn't suit my needs I can always go back to EM. – Pablo B. Apr 04 '11 at 18:52
  • 21
    How does a ruby library directly require a ruby framework? You can use event machine separately from rails easily. I don't understand this answer at all. Javascript isn't event based, but you can use it for event based programming. This answer contains erroneous information. – SpaceGhost Dec 10 '11 at 21:15
  • @SpaceGhost - "How does a ruby library directly require a ruby framework?" what does that mean? It doesn't make sense. Obviously you can use Event Machine separately. Each language has different eventing mechanisms. JavaScript simply allows you to pass functions around as objects, and call them when certain events happen. This is extremely common in JavaScript, making it a natural choice for eventing. The mechanism for eventing being of less interest than how the techniques are applied. – Christopher WJ Rueber Dec 13 '11 at 20:21
  • @ChrisRueber, I meant that for Pablo. But for the eventing, javascript can be used for eventing, but it isn't and event driven programming language. – SpaceGhost Dec 13 '11 at 21:01
  • 2
    I agree with SpaceGhost here. Javascript can be used for eventing, but is not an event driven language. Additionally, @Chris Rueber, you mention passing functions around in JavaScript as if it is an advantage to using Node.js, but Ruby also supports functions as first class citizens so this is true of both. – bigtunacan Dec 07 '12 at 17:16
  • 1
    bigtunacan's assertion is inaccurate. You can pass around lambda's and proc's, but they aren't first class citizens as he asserts. See this post for more details: http://stackoverflow.com/questions/2602340/methods-in-ruby-objects-or-not – Christopher WJ Rueber Dec 08 '12 at 15:41
  • @ChrisRueber Why do you assume the OP will want to use Rails with EM? Might he not want to use Ruby since it's part of Rails and he already knows it from that experience? Might he use another Ruby framework? Wouldn't using EM follow your advice of using what you know? Which is a language: EM or Node? And finally can you prove your statement "While Rails is not as heavy as some web application architectures, you're still going to need more processor power than you would to handle a similar amount of throughput in NodeJS." with any serious evidence beyond another useless to-do app benchmark? –  Sep 18 '13 at 19:12
  • @TomDworzanski See the tags on the question. He may not have said it in the question, but it's implied. – Christopher WJ Rueber Sep 18 '13 at 19:44
  • @ChrisRueber I saw the tags. Please see the question. Also, please see my other questions. –  Sep 18 '13 at 19:49
8

One thing worth mentioning is the production story. EM, like most Rack stuff, has plenty of testing and monitoring tools available that are well tested, whereas Node.js falls well short in this respect.

At the time of writing, it seems almost impossible to get clear metrics from Node to answer questions like 'Do I need to scale'. There are options starting to form out there from the likes of Joyent, and always the roll-your-own argument, but nothing anywhere near tools such as NewRelic.

Node.js is very good from a performance / configurability point of view, but personally I wouldn't host it in production just yet.

Neil Middleton
  • 21,690
  • 17
  • 76
  • 129
3

Node.js

You get far better control low level control over what's going in. You can include general libraries to build on top of node.js to tweak your level of abstraction to your own liking. For example you can use connect or express depending on whether you want a view engine written for you. You can use socket.io or now depending on how much you want your client-server connection abstracted. You can opt to include any of numerous MVC libraries or write your own.

Event-Machine

An asynchronous IO library just like node.js

It comes down to a Ruby vs JavaScript preference, how much flexibility you want with abstractions or lack of abstractions and whether you want to use node as your actual web server.

Raynos
  • 156,883
  • 55
  • 337
  • 385
  • 5
    No, you don't get the entire RoR stack, you don't know what you're talking about. Ruby on Rails is a web framework build with Ruby, EventMachine is an asynchronous library built with Ruby. The only thing they have in common is Ruby. EventMachine and Node.js are similar. – alessioalex Aug 24 '11 at 08:32
  • 7
    @alessioalex you are correct, I didn't know what I was talking about. – Raynos Aug 24 '11 at 09:11
-2

a detailed view at confusion has already been proposed... just a personal view

[] node.js will be better, if you are ready to learn and experiment more than you think because:

  • it's thread mechanism is awesome (inspired from that of 'erlang')

  • you can build a purpose specific server (easily) which will be real productive

AbhishekKr
  • 292
  • 2
  • 10