Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (2024)

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (1)

In this article, I’m going to compare the four popular frameworks: Express, Fastify, Hapi, and Koa, for a simple hello world case.

Express

Though getting older, Express still is one of the most popular frameworks for Node.js. Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Express provides a thin layer of fundamental web application features, without obscuring Node.js features that you know and love. The popularity of Express can be seen from the GitHub stars and weekly NPM downloads (29M weekly downloads the week of writing this article).

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (4)
Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (5)

Needless to say, Express is extremely popular. It is the perfect framework for moderate needs because Express’s performance is not as good as other lesser popular options.

Fastify

An efficient server implies a lower cost of the infrastructure, a better responsiveness under load and happy users. How can you efficiently handle the resources of your server, knowing that you are serving the highest number of requests possible, without sacrificing security validations and handy development?

Enter Fastify. Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express. As far as we know, it is one of the fastest web frameworks in town.

Fastify is popular, but nowhere close to Express. In fact, no other framework used in this article is anywhere close to Express.

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (6)
Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (7)

Hapi

Originally developed to handle Walmart’s Black Friday scale,
hapi continues to be the proven choice for enterprise-grade backend needs. Build powerful, scalable applications, with minimal overhead and full out-of-the-box functionality — your code, your way.

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (8)
Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (9)

Koa

Koa is a new web framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs. By leveraging async functions, Koa allows you to ditch callbacks and greatly increase error-handling. Koa does not bundle any middleware within its core, and it provides an elegant suite of methods that make writing servers fast and enjoyable.

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (10)
Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (11)

In the scope of this article, I’m going to test out a simple hello world case. I’ll follow up with other articles for JSON processing, multipart uploads, etc.

The tests are executed on MacBook Pro M1 with 16G RAM. Bombardier HTTP testing tool is used for sending the load.

The latest Node.js with new features is used for testing:

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (12)

Let’s go over the hello world code for each framework:

Express

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));

Fastify

import Fastify from "fastify";
const fastify = Fastify({ logger: false });

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

fastify.listen({ port: 3000 });

Hapi

import Hapi from "@hapi/hapi";
const server = Hapi.server({
port: 3000,
host: "localhost",
});

server.route({
method: "GET",
path: "/",
handler: (request, h) => {
return "Hello World!";
},
});

server.start();

Koa

The base koa package doesn’t come with a router. A separate package is required to get the routing functionality.

import Koa from "koa";
import Router from "@koa/router";

const app = new Koa();
const router = new Router();

router.get("/", (ctx, next) => {
ctx.body = "Hello World!";
});

app
.use(router.routes())
.use(router.allowedMethods());

app.listen(3000);

Each test is executed for 2M (2 million) requests. The tests are repeated for 25, 100, and 300 concurrent connections. A number of measurements are taken:

  • Requests per second
  • Time taken to finish off 2M requests
  • Mean latency
  • Median latency
  • Maximum latency
  • Q25 latency
  • Q75 latency
  • Q90 latency
  • Average CPU usage
  • Average memory usage

The results are presented in the following charts, along with analysis on each measurement.

Time taken

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (13)

Express takes the most time (110 seconds) to finish off 2M requests. Fastify is the fastest (28 seconds). Hapi and Koa are slower than Fastify, but significantly faster than Express. The difference is pretty significant.

Requests per second

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (14)

Fastify offers the most RPS (72K), while Express is the slowest (18K). Both Hapi and Koa also offers good RPS (45K and 55K respectively).

Mean latency

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (15)

The mean latency numbers depend on the concurrency. Fastify has the lowest mean latency, while Express has the highest. Hapi and Koa stays pretty close to Fastify for mean latency numbers.

Median

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (16)

The median value for Fastify is 4.1ms, while it is 15.8ms for Express. Again, Hapi and Koa stay close to Fastify.

As we’re establishing a pattern here, let’s move through the next few charts quickly.

Q25, Q75, Q90 latency

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (17)
Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (18)
Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (19)

Maximum latency

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (20)

The maximum latency numbers don’t have much difference across the contenders. This is the maximum time taken by any request out of the 2M requests.

Average CPU usage

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (21)

The average CPU usage is more or less the same for all the contenders.

Average memory usage

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (22)

Again, there is no significant difference in the memory usage. This is good news for Fastify because it is able to offer more at the same price.

Overall, Fastify offers the most RPS & least latency at comparable cost. Express turns out to be the slowest of all. Hapi and Koa are slower than Fastify, but the difference isn’t noticeable.

WINNER: Fastify

Thanks for reading!

Express vs Fastify vs Hapi vs Koa: Hello world performance comparison (2024)
Top Articles
What is Consolidation in Accounting? Meaning & Examples
Security Information - Intuit QuickBooks
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
How To Cut Eelgrass Grounded
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Umn Biology
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Colin Donnell Lpsg
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
San Pedro Sula To Miami Google Flights
Selly Medaline
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6473

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.