Fastify vs Springboot: Hello world performance comparison

Mayank C
Tech Tonic

--

In one of 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.

I recently did a comparison of express and spring, and spring emerged as a winner, as expected.

This article compares the other popular framework, fastify, with spring. It’s well known that fastify is much faster than express. I do 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 Fastify from "fastify";
const fastify = Fastify({ logger: false });

fastify.get("/", () => {
return "Hello world!";
});

fastify.listen({ port: 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!";
}
}

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.

Unlike express, which was quite slow compared to spring, fastify turns out to be quite faster. Fastify offers more RPS at low CPU and memory usage.

WINNER: Fastify

The comparison with express can be seen here.

--

--