Node.js vs Spring
In this story, I tried to be as precise and neutral as possible. I based my research on recent articles made by neutral communities. Because of the fast growth of both frameworks, Outdated articles (published before 2019) are not taken under consideration. I’m completely aware of what node.js really is, but for sake of simplicity by node.js I mean the runtime environment and all frameworks and tools based on it.
Node.js
I. Why Node.js ‘may’ be the best choice for developing a web app?
When we start seeing many big companies like Nasa, PayPal started using Node.js as a runtime environment for their web applications, I think it’s time to question why. Nodejs is there, in the web development business for almost a decade now and here is why I think that node.js might overtake other web development technologies in the next few years.
1. The use of JavaScript: According to StackOverflow annual survey made in 2019, JavaScript is the most popular language among developers. Nearly 70 percent of survey respondents said that they had used JavaScript in the past. If we look at GitHub or Red Monk language ranking, JavaScript is the most popular programming language. The reason why we are saying this is that by using JavaScript as a core development language, node.js should have a large community of developers. This will surely assure the fast growth of node.js frameworks by creating new features for the new growing enterprise needs. It will assure also node.js modules stability over the years.
2. Node.js is fast: There are two main reasons that make Node.js as fast as it is.
a. Non-blocking I/O model: and by that we mean node.js takes the requests and never blocks itself from receiving more requests while fulfilling its queue. Most of the I/O operations, like database access, network access, file system access does not block the process which started them, which means that it can do something else until data is ready.
b. Build on top of Chrome V8 JavaScript Engine: In recent years google made big efforts to make this engine fast, and they did a really good job. V8 now is the fastest JavaScript engine in the market.
3. Node.js is suitable for microservices: Due to the non-blocking I/O specificity and the focus on events, writing code directed to microservices is easier in Node.js than in other languages. The community around Node.js created several frameworks that facilitate work with microservices
4. Node.js will give a development team a boost: Using JavaScript for backend and frontend will make a team more efficient and cross-functional, which, in turn, leads to lower development costs. Node.js has also a package manager npm which includes many open-source tools.
Node.js is lightweight and completely unopinionated: Node.js is single-threaded which means that only one thread is responsible for receiving client requests. Also, the core modules are lightweight, and the developers are free to use the already made modules or to develop their own from scratch.
I. Why Node.js ‘may not’ be the best choice for developing a web app?
When thinking about what makes a great web application, the first thing that will come to mind may be how many requests per second it can respond to, and how much time, it will take to treat different kinds of requests, is the web app scalable enough to handle different loads of requests. As we have seen before, node.js have a great response to all these questions but is it as great as we think it is? Here is why we should think again before assuming anything about node.js.
1. Node.js ‘still’ not good for heavy computation: Though the node.js community already made it able to do multithreading, it still not as good as other solutions available in the market. Node.js is initially designed to use an event-based, non-blocking I/O model, using a single CPU.
2. NPM is quantity driven not quality driven: While the core products are proven to be well tested and stable, the npm registry is poorly structured and badly documented. This is not uncommon for open source projects.
3. Unstable Api: One of the biggest issues which faces developers when it comes to keeping their application up to date is unstable Apis. Node.js Apis are well known for being unstable which causes the developers to spend too much time in updating their apps each time a new version of Node.js is available.
Spring
I. Why spring ‘may’ be the best choice for developing a web app?
Spring is used for years now by some big companies like Google, Microsoft, Amazon. It’s the most popular framework in java. But from where this fame comes from and why these companies chose it as their main framework for developing their production applications.
1. The use of java: java is famous for being a mature, robust and platform-independent language which means enterprises can have more confidence when it comes to the quality of apps developed using java. Moreover, according to the TIOBE Index for February 2019 and the IEEE Spectrum ranking, Java holds the title as the most popular programming language. Java also has a big community of experts behind it. This will assure the fast growth and stability of the frameworks and tools based on java. Besides, java has very useful features like multi-threading, automatic memory management and garbage collection which make it stand as one of the best programming languages in the market.
2. Spring is open source but company-backed: Major spring modules are open source, but it is heavily maintained and backed by pivotal.
3. Spring is cloud-native: using spring, enterprises can easily build distributed systems. Spring also facilitates deployments on a local server, VMs, Containers, AWS, etc. It makes building microservices quite easy because of the wide variety of tools proposed that help in building such architecture.
4. Spring is easy to use: One of the key aspects of any framework’s popularity is how easy it is for developers to use it. Spring through multiple configuration options and Convention over Configuration makes it easy for developers to start and then configure exactly what they need.
5. Spring is quite fast and ideal for multitasking: Since Spring is based on java, it handles multitasking very well. This will make it ideal for application which includes Heavy computations. Also, with Spring, a production-oriented application will have a fast startup, fast shutdown, and optimized execution.
6. Spring supports a non-blocking programming model: One of the recent features added when spring 5.0 is published, Spring Webflux. Spring Webflux introduces a programming model new to spring which is the non-blocking (reactive) paradigm. Using the modules of the Webflux framework, spring now can be faster and more lightweight when we speak about resources consumption.
7. Flexible configuration and easy testing
II. Why spring ‘may not’ be the best choice for developing a web app?
To be honest, finding real arguments for this was difficult. The web community tends to give some personal opinions about spring which most of the cases do not really reflect its reality. Here is why most of the developers think that spring may not be a good choice
1. A difficult learning path: The Spring framework is verbose, and it has a lot of variables and baked configurations. Therefore, we should only use it if we have an experienced team of developers who have used this framework before.
2. Spring is a bit slow and heavy: compared with other solutions in the market.
3. Lack of guidelines and tons of options: There are no clear guidelines on several topics for the developers in Spring documentation such as cross-site scripting attacks or cross-site request forgery attacks.
4. Unstable API
Wrapping-Up
Node.js is proven to be fast, lightweight, easy to learn and easy to use environment but still immature in many aspects. Therefore, decision-makers should not be fooled by the success made by big companies and think twice before using it as a runtime for their production-grade applications. One of the biggest issues with node.js is the way it handles heavy computations. Although the community is trying to make it able to do multitasking through multiple CPUs, it still not a good choice for this kind of application. On the other hand, Spring gives us maturity, robustness, flexibility, and a wide variety of tools that make life a lot easier. This ease comes with its pros and cons. Spring is a bit slow and heavy and its quite opinionated which makes it quite difficult to learn. Furthermore, we can say that this choice really depends on the type of application (I/O oriented, heavy computations oriented, etc.), the company itself (which tool is familiar with) and the availability of developers and their experiences.