Node.js for Enterprise applications!! Are you kidding?

 In Miscellaneous

Now a days JavaScript runtime called Node.js which of course is quite promising becoming a popular choice for developing server-side web application. Amid all the popularity, skyrocketing success & all hyped up about using Node.js, still a question remains, can Node.js be used to develop Enterprise grade applications?

Let me start by saying, Node.JS could be an option for enterprises but *not* for enterprise applications. What I meant here, for small or medium size applications having web-facing infrastructures such as mobile apps, apps requiring real-time, two-way connections (e.g. chat, real-time stock quote) & those using micro service architecture (i.e. single responsibility), Node has provided an alternative to many server side frameworks. As we know, advent of IoT & Digital transformation, business is changing rapidly & many startups are popping up. So for responding quickly to some urgent business requirements, without any doubt Node.js model is worth attention because of low resource footprint & to spin up something quickly. But I have my doubts about developing large scale enterprise applications using Node.js.

Let’s first understand what we call an enterprise application. As per Gartner:Enterprise application software includes content, communication, and collaboration software; CRM software; digital and content creation software, ERP software; office suites; project and portfolio management; and SCM software. Typical enterprise applications like CRM, ERP, Accounting & Banking apps are multi-user, multi-machine, multi-component, multi-screen and multi-developer, manipulate massive data & utilize extensive parallel processing, complicated data relations, having complex business rules, handles massive data, distributed computing & transactions, requires heavy integration with other applications. While enterprises are moving towards micro service architecture, there are certain applications (legacy systems, batch applications, SCM) are inherently monolithic & can’t be replaced. Enterprise software is intended to solve an enterprise-wide problem, rather than a departmental problem.

Node.js is not a silver bullet for developing software & definitely not suitable for everything especially large scale, mission critical enterprise applications mainly because of its single threaded architecture, event driven async programming model, limited transaction management support & few other constraints. Let’s discuss some of these limitations in detail to understand why Node.js is unfit for such large enterprise applications:

  • Since Node.js has JavaScript event loop which is single threaded, when it executes long running or high computational intensive tasks (which is quite common in enterprise applications), it queues all the incoming requests to wait for execution. This will result in poor performance. Also it doesn’t scale out to take advantage of the multiple cores commonly present in today’s server-class hardware. So the execution of Node.js on server-class hardware results in heavy utilization of one CPU core, while leaving the other CPU cores underutilized & hence the solution is not scalable enough. Alternatively to scale out, you need offload such CPU intensive tasks to other Node.js servers (node cluster) which is not always advisable as it requires additional hardware & difficulties in maintaining all. So for typical enterprise applications e.g. batch processing where you need multi-threaded execution & requires controlled & cohesive inter thread communication, Node is not suitable.
  • Also everything is asynchronous which hurts. Code consists of callbacks within callbacks within callbacks… It’s a Callback hell.. pretty messy code & very difficult to understand and maintain. There are ways for having better code, managing callback hell but then we are too much relying on having good & disciplined programmers.
  • Node developers generally initialize webserver and run business code in the same process, there is no isolation between application server & business process which other mature servers like Tomcat or Apache HTTP server provides. Also not having any isolation leads server to crash if business code throws some exception.
  • The weakly type nature of JavaScript & so as Node.js makes it easy to leak defects, no compilation phase and no type checking which means code is lot more prone to bad references or null pointer exceptions which gets discovered at runtime. Especially with large enterprise application having a bigger code, having multiple developers working on the same code base, the missing types are more a problem for productivity than an advantage. Actually in weak typed languages the programming discipline must be even stricter than a strongly typed one.
  • The way npm is structured also makes it quite difficult to find trustable packages. As it is open to all, anyone can publish their own modules which makes it harder to spot reliable, stable & mature packages. Not having backed by standard body, using NPM packages is still a risky game. Here is an interesting article on how one developer broke Node.
  • There are few other limitations which will prevent Node.js to be an enterprise application technology stack such as no support for distributed transactions, limited debugging & ide support (StrongLoop debugger works only in couple of browsers), Lack of standard & matured libraries + lack of good IDE seriously impacts development. According to my experience explicitly typed languages are more readable, generates robust code & having good IDE + testing tool support.
  • While Node working on security project and security is a top priority, it is not rock solid against attacks + availability of Node application is questionable which makes Node application for few sectors like financial services, banking & investment is worrisome.

While Node.js has an attractive ecosystem, I am surprised when people are comparing Node.js with solid Java technology stack. I am not a Node.js expert and have never worked on real serious basis; but yes, I am quite familiar with Java stack and hence decided to compare few important features of Node.js with equivalent features/frameworks available within Java Ecosystem.

Single threaded Node.js event loop vs. Servlet 3.0 Async feature:

With servlets 3.0 Async feature, resource intensive execution can be decoupled from the Servlet container thread & delegated to a worker thread. By releasing the initial request processing thread back to container, it will significantly increase the throughput & scalability of webserver. The released container thread can be used to accept and process new incoming request connections. This way the container thread pool is never exhausted even if there are too many concurrent requests.

This approach of having multiple container threads accepting requests concurrently and using worker threads to execute resource intensive tasks asynchronously is far more superior to Node.JS event loop. This design is capable of utilizing multiple CPU cores which are available in latest hardware which obviously gives far better performance than a single threaded model.

Frameworks like Spring MVC 3.2+, Jersey 2.x (JAX-RS 2.0) are based on Servlet 3.0 specification and have adopted its asynchronous model.

Non-Blocking I/O:

JDK 7 onwards, Java also supports buffer oriented, Non-blocking I/O using channels. Basically with the help of NIO, data is read from channels into buffers, and written from buffers into channels. Even Servlet 3.1 which now supports NIO using Read & Write listeners which have callback methods. These methods are invoked only when the content is available to be read or written without blocking.

This has helped web-servers like Tomcat & Jetty tremendously. Now in HTTP 1.1, connections can remain alive (i.e. connections are persistent) between client and webserver between subsequent requests. This means a single TCP connection can be used to send multiple HTTP requests/responses & hence now a large numbers of concurrent users can be served with limited container threads.

Event driven:

As we know, Node.js node achieves much of its speed because of it is single threaded (no context switching), asynchronous event driven & supports non-blocking I/O. But likewise this, Java ecosystem has few options like Spring Reactor, Vert.x & Akka which are promising event driven and non-blocking server frameworks, can utilize multiple CPU cores for achieving high scalability & without complexity of handling threads. Performance wise also, if you ignore the warm up time, absolute performance of Java application is much better. Btw, here is one latest performance test comparison of several web application platforms which clearly shows many Java based frameworks like Servlet, Jersey, Tapestry, Dropwizard etc. are really fast.

Server Push & Bi-directional communication:

In absence of Websocket, I remember using Flex, Long polling, Comet etc. for two way communication; especially for pushing data to browsers. Websocket in now formally introduced in HTML5 & even other technologies/frameworks have adopted it as well. For e.g. based on JSR 356, Servlet 3.1 now provides Websocket support. Spring MVC & Tomcat7 also support web sockets. So in a nutshell both node.js and Java stack are having very similar Websocket implementations.

As we can see JVM world is evolving rapidly, becoming asynchronous, reactive & functional. Also frameworks are getting more matured, providing built-in support to both develop & deploy applications rapidly for e.g. SpringBoot. Thus in comparison with Node.js, JVM ecosystem is unmatched, lots of use-cases have readymade solutions, having vast array of libraries (including many apache projects), and given Java’s rock-solid foundation, proven track record, threading capabilities, matured IDEs & debugging capabilities and lot more. Considering all, I would say Java stack is far more matured and proven to be enterprise friendly.

As per Gartner’s “Bimodal IT” model, organizations now require two separate & coherent groups: one which takes care of the traditional IT operations, running today’s enterprise apps & executes typical enterprise operations (e.g. CRM, ERP, mainframe applications). The other one which explores and develops next-generation applications which require fast turnaround, and rapid changes to transform business ideas into applications. So for latter mode, Node could be an option considering its benefits but even there, for 2nd type of applications, to really deliver value, they need to interact with transactional systems i.e. with type-1 applications. Depending on your requirements, decide the technology stack judiciously rather than following the crowd impulsively.

As concluding remarks, I must say that Node.js can complement existing enterprise technology stacks instead of replacing them.

Image Credits: Sachin Ranawade

Recommended Posts
Comments
  • priya

    The debate between Node.js and Java continues. Each programming language comes with its own set of benefits and drawbacks. Java has been around for years and dominates the Enterprise Server. It offers better IDEs and solid ecosystems. Many thanks for sharing this.

Start typing and press Enter to search

Contact Us
close slider
Contact Us

Yes, I would like Persistent to contact me on the information provided above. Click Here to read our full Privacy Notice.