Express vs Springboot: Hello world performance comparison

Mayank C
Tech Tonic

--

In the previous article, where I compared Node’s native HTTP server with spring, I got comments that the comparison wasn’t fair. Spring is a framework, therefore it should be compared with a framework on the Node side: Express, Fastify, Nest.js, etc. A very valid point.

This article compares the extremely popular express.js with spring. It’s well known that express is quite slow. I don’t expect it to perform better than spring. The test setup is the same: MacBook M1 with 16G RAM. Node.js v19.7.0 is compared with spring 3.0.2 over Java 17.

The code is as follows:

Node.js

import express from "express";
const app = express();
const port = 3000;

app.get("/", (req, res) => {
res.send("Hello World!");
});

app.listen(port, () => console.log("Listening on", port));

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!";
}
}

The test runs a total of 1M requests for 10, 50, 100, and 200 concurrent connections. The testing tool is bombardier which is known to be very fast.

Let’s jump straight to the results.

I’m not at all surprised with the results. In my previous runs, I’ve seen that express is very slow. And that’s the case here, too. Express turns out to be two to three times slower than spring. The only issue with spring is too much CPU and memory usage.

WINNER: Spring

A similar comparison with fastify can be seen here.

--

--