Node.js vs Ruby on Rails: Which Is the Best for Web Development?
Node.js vs Ruby on Rails: Which Is the Best for Web Development?
If you're looking to switch to one of these backend frameworks, read on to get an overview of each and how they stack up to each other.
Join the DZone community and get the full member experience.Join For Free
Bugsnag monitors application stability, so you can make data-driven decisions on whether you should be building new features, or fixing bugs. Learn more.
Hi, guys, in this article we’re going to compare Node.js versus Ruby on Rails for web development. The main reason I wrote this article is that our team is 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 the facts and statistics. We’re going to take a look at some of the advantages and some of the disadvantages of both Node.js and Ruby on Rails for server-side technologies. Before we begin, I'd like to 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, but what I'm going to compare is the two server-side technologies and web stacks. Now let’s get clear on 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 Node.js if it makes you feel better to replace Node.js with something like Express or some other Node based frameworks. Anyway, we compare backend structures and stacks, not the individual technology. Our team has worked with both technologies and some of us like both technologies. I’m not promoting one 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 has been around a little longer and has 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 has 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 the 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 has 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. 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 create errors and issues. It’s not restricting in the sense that you can't create what you want, but just the way that you’re going to get there. If you do it the right way it’ll most likely be the easiest path.
Rails also has a really good database migration functionality. They allow us to do things like create and edit tables and columns in our database without having to manually go in and add or 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 to 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, with some basic configuration and a couple of 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 stuff right out of the box.
There are some pros and cons to the Ruby language but for the most part, it’s well respected and 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 soem of the big 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. 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 how the Rails framework works. You may know about the Ruby language, about the syntax or the structure of their application, but 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 is that Rails isn’t as popular as Node.js. At this time, Node.js is on the cutting edge of web development and the excitement for Rails has really gone down. 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 was five years ago, Rails or Ruby would be one of top three languages to learn. But these days it’s just not as popular. So I briefly mentioned earlier that the core Rails framework has some really good documentation and examples, allowing you to learn 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 backend services to Scala and Java due to some scaling issues. But they used Rails for a long time and I'm pretty sure they still use it in other aspects of their platform, such as their partnership with Shopify. Additionally, Basecamp, which is a project management solution, has said that Rails is the heart and soul of their project. The software that runs GitHub was built on Rails. Soundcloud and Hulu, which is a popular streaming service, were built on Rails. From the beginning, Groupon and LivingSocial, SlideShare, and Urban Dictionary have used Rails in their developemtn.
- 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 until 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, and they have reported at least a decent rise in productivity.
Node.js, 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 a bundler and have to kind of manage them on your own. 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 my experience.
- Sucks for CPU intensive tasks.
- Newer technology.
- Callback hell.
- Too modular.
So we looked at the positives 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, will 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, etc.
Another complaint 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.
Rails is very strict, so it’s harder to write bad code. Since Node is asynchronous you are going to be dealing with a lot of callback functions and they often can bubble up and get into what’s called callback hell. There are solutions to this, such as async utilities and using promises. There are a few things that you can do to prevent this. This personally doesn’t bother me but I know that some developers that aren’t used to asynchronous programming have a problem with a lot of callbacks.
As you can see both of these backend options have their pros and cons, but they’re both fantastic technologies. Everything should always be evaluated on a case-by-case basis rather than just saying one is better than the other in all situations.
Published at DZone with permission of Darya Kuritsyna . See the original article here.
Opinions expressed by DZone contributors are their own.