Digital Solutions Blog

Dsg Subscribe Mail Web

Blogs (Digital Solutions Blog) (Digital Solutions Blog)

Node.js: Hype or Valuable Platform?

Robin Nagpal
1 Year Ago

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. It's one of the most talked about technologies these days, but is it just hype or does it have real value? ‘Value’ is of course very contextual and a subjective term. The technology's perceived evaluation is different for different business models and situations. There are many ‘cool’ technologies in the software community these days which are suitable for only very specific situations. After learning about these technologies, developers sometimes try to force-fit these technologies into not so suitable situations. To understand if Node.js is one of these technologies or not, let's explore some of the use cases and see the relevance of Node.js in these cases.

Scaling to One Million Requests

One million requests doesn’t mean one million online users. The number of users are generally much less, as multiple requests are required to serve just one user. Serving a high volume of requests is not a very uncommon scenario these days.  If you have to develop a software solution that can handle these many requests, which language you should use? Java, .Net, Ruby, php, Python?  Along with the language, which technology stack/framework will you use to build the application? 

All of these languages approach the scalability problem in a similar way, i.e. by applying the common technique of using a new thread to serve a new request.  Memory usage is generally directly proportionate to the number of threads used, which limits the number of threads that can be used in a server. In order to scale we first try to find the maximum number of threads that can be used by a server at a given time. And then based on this number, we determine how many servers should be added behind a load balancer.  

Hardware is cheap these days, so can an addition of more servers be a cause for concern ?  Yes, it is a cause for concern since with the increase in the number of servers comes additional cost of maintenance, cost of code deployment, and the cost of isolated testing and verification on each of these servers. More servers means more overhead cost, thus requiring a new team for managing the deployment and verification on these servers.  Scaling horizontally (adding more servers) can appear to be a cheap solution considering just the hardware, but in reality it is not an efficient one. 

Node.js takes a completely different approach for serving incoming requests. It uses single thread and an event loop for processing all the requests. If we are doing many network or database calls, like the way we do in most of our web applications these days, then this approach proves to be a really efficient one. In Node.js whenever we make a network/DB call, we pass a callback function, which is called when we get the result. The event loop monitors if the result is available, and whenever it is available, it uses the same thread to process that callback function. Meanwhile the thread can be used for serving other requests or doing other queued up tasks. There are a plenty of benchmarks which prove that Node.js’s approach is much more efficient for developing an application which has a lot of I/O. It can help in reducing the number of servers by a big factor. Having a single thread can be inefficient if we are doing a lot of computation, as that thread will be busy doing that computation and will not be able to serve other requests. Bearing in mind all of this, it does makes sense to consider Node.js as one of the first choices for developing applications that need to be scaled for huge number of users.

Developing Interactive Web Applications

Interactive websites these days are client heavy and require a lot of client side Javascript code. This demands good javascript developers who can write unit tests, write integration tests, analyze code coverage, run static analysis, etc.   Along with these skills, we need developers who are experts in writing server side code. Finding good client and server side developers is one of the biggest challenges that managers face and can prevent projects from being completed on time.

This situation can be less challenging if just one type of developer can write both server and client side code, or more interestingly if both the client side and server side code can be written in the same language. Node.js enables us to write both the client side and the server side code in Javascript.

l understand that writing server side code these days is more about using existing libraries and frameworks and not reinventing the wheel by writing your own code to achieve the same purpose. This is a very important consideration while deciding for a server side technology. Node.js modules/libraries, though not the most mature and diverse ones, do provide modules for some of the common web application requirements. Considering the omnipresence of Javascript, Node.js can be a really cost effective solution for making these interactive web applications.

Microservices 

All the major organizations are moving away from a heavy monolithic software approach and adopting a more distributed one - dividing the software into thin vertical layers, and exposing services for each of these layers. Each of these services should be capable of being deployed separately in lightweight containers. Since the whole software is divided into different services, a large number of containers are required for deploying  all of these services. 

One of the Node.js modules, ‘express’ makes it very easy to write and deploy these services. Using Node.js library, ‘http’ or module ‘express’, it’s very easy to create a simple http server and then expose these services through it.  These services are capable of running by themselves and don’t need a container, thus making Node.js an ideal solution for some of these cases.

Conclusion

Use cases mentioned above are some of the very common use cases, and Node.js proves to be a promising alternative for writing applications for one of these cases. But, just like any other technology, Node.js has its own set of disadvantages such as a paradigm shift for developers to write even driven code rather than normal sequential code, modules of node.js are not mature, lesser IDE support etc. But looking at the advantages, these disadvantages are minor for many cases. I would recommend that before deciding on technology for the above cases, do consider Node.js as a possible alternative.

Form

Talk To Our Experts