Hi, guys, in this article we’re going to compare Node.js versus Ruby on Rails for web development. The main reason I write this article is that our team constantly being asked which language or which framework is best to learn. Anyway, we never give a simple answer because they aren't the clear-cut answer. So I think the next best thing is to look at all facts and statistics. We’re going to take a look at some of the advantages and some of the disadvantages of both Nod.js and Ruby on Rails for server-side technologies. Before we begin I make a couple of points. So we can already hear the critics saying how are you going to compare Node.js that is a runtime to Ruby on Rails that is a framework. I get the argument what I compare are the two server-side technologies and web stacks. Now let’s get clear what’s better to learn right now and what’s better to implement for a business. I’m not saying to compare straight up features of Ruby on Rails to Nod.js. If it makes you feel better to replace Node.js with something like Express or some other node based frameworks. Anyway, we compare back-end structures and stacks, not the individual technology. Our team worked with both technologies and some of us like both technologies. I’m not promoting over the other. It’s also important to understand what works for us may not work for you and vice versa. Also, you should remember that everyone’s brain is different. There is no cookie cutter answer for this question.
Let’s go ahead and get started with looking at some of the similarities between both technologies.
- Popular Server-Side Technologies
- Fairly easy to learn
- High performance
- Used by top websites/applications
- Strong community
- Similar MVC based structure
- Rapid Development
Rails have been around a little longer and have more old timers. But Node is becoming more popular every day. Now MVC or Model-View-Controller is a designed pattern. And Ruby on Rails is hard MVC. You have a folder for your models, your controllers, and your views. MVC is possible with certain frameworks in Node such as Express. However Express is much more flexible in its structure than Rails is. You can just take certain aspects of MVC. It’s not the only structure possible. Node and Rails are used for rapid development and prototyping. Rails has an awesome folding feature and Express as generators and command-line tools as well.
- Consistent structure
- Very opinionated
- Database migrations
- Speed of Development
- Ruby is a great language
- Ruby gems
- Maturity and respected community
First, we are going to take a look at the advantages of Ruby on Rails and then the disadvantages. Going ahead we’ll take a look at Node.js. As I said Rails has a very strong MVC structure. Most Rails applications are going to look very similar in terms of the core files and folders. You have that strong foundation and then you build upon that with gems and custom packages and libraries. In addition, Rails is very opinionated meaning that it makes you adhere to its way of doing things. Rails assumes that you’re going to write code in a certain way and some people may say that’s a little restrictive. But it also makes for easier, much cleaner code and it also makes it harder to have errors and issues. It’s not restructuring in the sense that you can't create what you want but only the way that you’re going to get there. If you do it the right way it’ll most likely be the easiest path. Possible all right with Express or some other Node frameworks. You have a tone of freedom as far as structure. But you also have enough rope to hang yourself in some cases.
Rails has really good database migration functionality. They allow us to do things like creating and editing tables and columns in our database without having to manually go in and add change things. It also gives you a nice little log or path that you can follow to see exactly what’s been done to the structure of your database.
Now with Node. There are some packages or modules for migrations such as DB-migrate which can work really well, but it’s not as in-depth and easy-to-use as the Rails chord migration system. When it comes to prototyping and rapid development there are not too many technologies out there that can beat rails. So some basic configuration and a couple scaffolding commands you have yourself a full functioning crud application. Database migrations are added to that speed. Node.js and Express are fairly good with fast development if you use third-party tools and modules. But Rails has all that staff right out of the box.
There are some pros and cons to the Ruby language but for the most part, it’s well respected, it’s very clean. Ruby is a multi-paradigm language, you can do procedural code functional, but for the most part, it’s object-oriented. Everything can be looked at as an object. RubyGems is a package manager for Ruby on Rails and it’s used to extend the core functionality of the framework. It’s similar to NPM for Node.js. All rails applications have a gem file where you can specify your gems. Then you can run a bundler command to install all of them, similar to NPM install with Node.js.
Another great thing about Ruby on Rails is that it’s been around for a while and it has a very respected and intelligent community. The developers maintaining Ruby on Rails are extremely smart and very passionate about the framework. There’s a ton of resources on the core framework including forums, blog posts and documentation to help you out if you get stuck. Those are advantages of Ruby on Rails.
- Too simple
- Lack of documentation
Let’s talk about some of the disadvantages. Some of the biggest complaints that we've heard about Ruby on Rails is that it’s relatively slow. Node.js and Express are really fast, but it’s really light. Rails is a big framework with a lot of features in its core. As well as some of the lighter frameworks, you also have the factor in the gem and application file dependencies. There’s so much automation and scaffolding that the developer doesn’t really learn very much about. You may know about the Ruby language, about the syntax or the structure of their application. For someone that really understands how Rails works. This is great because of its rapid development. On the other hand, some of the developers really have to go the extra mile to really understand certain things. Rails is also way more difficult for big projects than small applications. It can have some issues with scaling as well.
So another disadvantage, Rails isn’t so popular as Node.js. At this time Node.js is on the cutting edge of web development and the excitement for Rails has really settled at least. In our opinion, if you are looking for a job we would definitely say learn Node and probably Express. More companies are hiring JS developers than any other language. If this way five years ago Rails or Ruby would be one of top three languages to learn. But these days it’s just as popular. So I briefly mentioned earlier that core Rails framework has some really good documentation and examples, learning simple scaffolding commands and database migration. That’s all fine. However when you try to learn more advanced programming and you’re trying to learn about specific gems, sometimes it feels like looking for a Newton needle in a haystack.
Some pretty big names have used or do use Ruby on Rails in their platform. I don't’ think you can get much bigger than Twitter. Also, they have moved a lot of their back-end services to Scala and Java due to some scaling issues. But they get used Rails for a long time and me pretty sure they still use it in other aspects of their platform. Shopify) which is a huge e-commerce solution. They use Rails back-end services. Basecamp which is a project management solution. They have said that Rails is the heart and soul of the Basecamp project. The software that runs GitHub was built on Rails. On Erlang Bloomberg uses Ruby on Rails. They actually have a recent job opening for rails position. Let’s see Soundcloud, Hulu which is a popular streaming service was built on Rails. From the beginning Groupon and LivingSocial, SlideShare, Urban dictionary these are all huge names that have used Rails.
- Extremely popular
- High performance
- Very scalable
- Flexible file structure
- NPM and Modules
Next, Node.js is also asynchronous. This means when a program sends a request to the server, it doesn’t have to wait for the reply. It can continue to execute. Node runs on one single thread as opposed to other languages that send the request. They wait till that request is done, then send the next one and so on. So Node.js is also very scalable and being on a single thread plays a big part in that. Node also works really well with NoSQL databases like MongoDB, which is much more scalable than traditional relational databases like MySQL. Almost all big companies that I read about have shifted to Node.js, they have reported at least a decent rise in productivity.
Node.Js and Express or Happy JS, any of these frameworks have a really flexible file structure. They let you construct your applications as you want. You can Jam everything into a single app JS file. If you wanted to have more of a traditional MVC structure, I think there are both good and bad sides to this. But for the most part, if you know what are you doing and you are a good programmer then flexibility is a good thing. Like Ruby gems Node also has its own package manager called NPM or Node package manager. The biggest difference between NPM and Ruby gems is the way that dependencies are managed. With Ruby, dependencies are installed globally. So you have to use bundler and have to kind of manage them on your own. When NPM actually takes care of all that for your modules. They get put into the Node modules folder. Then those modules can also have their own Node modules folder with their own dependencies. NPM modules also seem to have better documentation at least in many experiences.
- Sucks for CPU intensive tasks
- Newer technology
- Callback hell
- Too modular
So we looked at the positives the pros and advantages of Node.js. Now let’s look at some disadvantages. As good as Node is for many crud style applications. It absolutely sucks for applications that are CPU intensive. The reason for this is that whenever it does something that takes a while such as CPU operation. It'll queue all the incoming requests because it runs on a single thread. Something like apache which has more available threads. It’ll divvy up that CPU time between them. And only IO operations are parallel because they’re executed asynchronously. An example of a CPU intensive task is something like 3d rendering, video encoding, scientific modeling, sorting things like that.
Another complained about Node is that it can be a little inconsistent. Some feel that the API keeps changing at frequent intervals. It’s sometimes not very backward compatible. Not only that, but the structure of an Express application, in general, is very free and flexible. Sometimes it can give developers enough rope to hang themselves.
Frameworks like Express and Happy JS are very light. This can be a plus, but this also means that any extra functionality needs to come from third-party modules. For instance, templating you have all kinds of options with Node and Express bug handlebars. But you need to install them separately unlike Rails, which you can use as third-party template engines. But it doesn’t have embedded Ruby by default. Expresses and as full-featured is Ruby on Rails which it makes it hard to compare, just Express to Ruby on Rails. That’s why I called Node.js versus Rails.
Some big names that have used Node.js are Linkedin, which is right up there with Twitter and Facebook. They actually switch from Ruby on Rails to Node.js quite some time ago. They switched mostly for scaling reasons because Node happens to scale better in most situations.
As you can see both of these back-end options have their pros and cons, but they’re both fantastic technologies. Everything should always evaluate on a case-by-case basis rather than just saying one is better than the other in all situations.