Choosing the Right Technology for Scalable Web Apps in 2017: A Benchmark Between JavaEE, Spring, and Node.js

Choosing the Right Technology for Scalable Web Apps in 2017: A Benchmark Between JavaEE, Spring, and Node.js

When building a scalable web application in 2017, with a focus on social media and performance, two prominent frameworks often come to mind: JavaEE and Spring, both of which are capable of scaling effectively. Yet, with the rise of JavaScript and its ecosystem, specifically through Node.js, a new era of development has emerged that offers potential advantages. In this article, we will explore the comparative performance of these technologies using a real-life benchmark.

Definition of Performance and Scales Well

Performance, in the context of web applications, refers to the speed at which a system can respond to user requests. This encompasses the time it takes to process a request, interact with databases, manage data serialization, and return a response. Scales well means that the application can efficiently handle increased loads and demands, typically through the addition of resources like CPU, memory, or more servers without a significant drop in performance.

Real-life Benchmark Between Multiple Technologies

The benchmark, conducted with real-life applications, included ExpressJS with Node.js 8.2 and Spring with Java. The tests involved a REST API with four different endpoints, each with varying degrees of complexity:

Hello World - simply respond with a JSON containing the "Hello World" string. Computation - compute the first 10,000 Fibonacci numbers. Simple Listing - list all countries from a MySQL database. Complex Listing - list all users that visited France alongside all countries each one visited, involving a many-to-many mapping between users and countries.

Server Specifications and Benchmark Results

The tests were conducted on a 4 Cores 8 GB RAM machine from DigitalOcean. Here are the results:

Endpoint Express JS Spring Hello World 21.972 req/s 21.853 req/s Computation 17.278 req/s 19.871 req/s Simple Listing 2.904 req/s 2.816 req/s Complex Listing 514 req/s 562 req/s

These tests demonstrated that, in a medium-sized server, Spring and Express had similar performance in handling the Hello World and Computation tasks, but when dealing with more complex operations such as the Simple Listing and especially the Complex Listing, Express performed slightly better. However, on a more powerful 12 Cores 32 GB RAM server, Node.js scaling with PM2 was more efficient.

Further Testing and Comparisons

In addition to these primary tests, further comparisons were made, including serialization, single query, multiple queries, data update, and plain text responses. Here are the detailed results:

JSON Serialization

Express outperformed Spring in JSON serialization by a significant margin:

Technology Responses Per Second Express 186,548 Spring 22,013

Single Query

When querying a single row from a database, Express using Mongodb performed much better than Spring:

Technology Databases Responses Per Second Express (Mongodb) 48,392 Express (Mysql) 45,550 Spring 16,022

Multiple Queries

Express using Mongodb outperformed Spring in multiple queries per second:

Technology Databases Responses Per Second Express (Mongodb) 3,840 Express (Mysql) 3,772 Spring 2,363

Data Update

Express had a significant advantage in handling database writes with multiple updates:

Technology Responses Per Second Express (Mongodb) 2,841 (20 updates per request) Express (Mysql) 374 (20 updates per request) Spring 833 (20 updates per request)

Plain Text

In handling the simplest response of plain text, Node.js outperformed Spring clearly:

Technology Responses Per Second Express 213,982 Spring 131,533

In conclusion, based on this benchmark, Node.js demonstrated superior performance in various aspects, particularly under heavy load conditions.

Should Performance be Your Only Concern?

While performance is crucial, it is not the only concern when choosing a technology for a scalable web application. Other factors to consider include:

Scalability - How easily can the application scale with increasing load? Maintainability - How understandable and maintainable is the codebase? Community Support - Is there a strong community and active ecosystem? New Features - Does the technology support the necessary features for your project? Developer Experience - Is the development environment and process enjoyable?

While Node.js and Express may have a slight edge in performance, these considerations should also play a part in your decision-making process.

For a more comprehensive overview of technology performance, you can refer to the TechEmpower Round 13 benchmark.