Node.js vs Springboot: Hello world performance comparison

Mayank Choubey
Tech Tonic
4 min readFeb 12, 2023

--

Continuing my quest of performance comparisons, this article is about Node.js and Springboot. Spring boot is a light-weight server technology built over Java that’s mostly used for web services. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. Spring boot is quite popular in the java world.

Who do you think is faster for a simple hello world case? I guess the answer could be Springboot because it’s compiled into byte code while Node.js is interpreted. If you’re interested in finding out the correct answer, read on. You might be surprised!

Update: A comparison of Node.js express cluster with SpringBoot is available here.

Setup

The test is executed on MacBook Pro M1 with 16G of RAM. The test is executed using the well-known HTTP tester: Bombardier. The test is executed for 50, 100, and 200 concurrent connections.

The versions are:

  • Node.js v19.6.0
  • Springboot 3.0.2 with Java17

The code is:

Node.js

The Node.js code has a minimal router that makes it equivalent to the functionality provided by Spring’s native server.

import http from "node:http";

http.createServer((req, resp) => {
try {
if (req.method !== "GET") {
return resp.writeHead(405).end();
}
if (req.url !== "/") {
return resp.writeHead(404).end();
}
resp.writeHead(200, {
"content-type": "text/plain",
});
resp.end("Hello world");
} catch (e) {
resp.writeHead(500).end();
}
}).listen(3000);

Spring

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

@GetMapping("/")
public String handleRequest() {
return "Hello World!";
}
}

A note about Springboot app: For Spring Boot, I’ve only shown the main application file. This is the only file which has been written by me. By default, this springboot app starts with 60 threads.

A total of 5M (5 million) requests are executed for each concurrency level.

The following measurements are taken:

  • Time taken
  • Requests per second
  • Latencies: Mean, median, q25, q75, q90, maximum (in milliseconds)
  • System usage: Average CPU and memory usage

Results

Here are the charts representing results for each type of measurement:

(Note that all latencies are in milliseconds)

My analysis

First, Spring/Java is a very resource intensive application. For a simple hello world case with 200 concurrent connections, Spring uses ~190% CPU and 470M of memory. Comparatively, Node.js uses 95% CPU and 82M of memory.

Now for the latencies, spring’s latencies are lower than Node.js till 3rd quartile. Spring fails with maximum latency readings which runs into seconds, while Node.js’s maximum latency reaches 123ms. Even the median latency of Spring (0.6ms) is significantly better than Node.js’s (2.5ms).

To conclude, Node.js offers more RPS using significantly less system resources.

UPDATE: As this article got quite popular in the community, I got comments that the comparison of Node’s native server with a framework like Springboot is unfair. A very valid point. I’ve already published articles to compare Express and Fastify with Springboot. The links are:

Some more suggestions were to compare webflux/vert.x with express/fastify. The articles are now available:

Thanks for the feedback!

SECOND UPDATE: If you’re interested in real-world comparisons, you can visit the main article here.

A comparison of Node.js express cluster with SpringBoot is available here.

--

--