Express vs Fastify Performance

Whose performance is better?

Kishan Patel
SixBerries Labs
3 min readJan 20, 2023

--

It is essential to choose the proper web framework as it saves the developers time and effort when developing web applications like web services, resources, and APIs.

With plenty of web frameworks, it gets hard for web developers to choose the right one for their projects.

Image source: blog.intception.me

Fastify and Express are two web frameworks for Node.js. In this shot, we will compare both frameworks and highlight some key differences.

  • About Express

Express (Express.js) is a web application framework that has been around for quite a long time and has become the standard server framework for Node.js.

  • About Fastify

Fastify is inspired by Hapi and Express and provides a faster alternative to Express with less overhead. It is built as a general-purpose web framework, but it shines regarding its fast HTTP APIs.

Fastify vs Express

Both frameworks are open-source and actively developed.

Fastify claims to be the fastest web framework around. Benchmarks back up their claim with Fastify performing nearly twice as fast as Express in a simple ‘hello world’ overhead benchmark. The only case where Fastify falls behind Express is in handling empty requests.

Fastify provides full encapsulation for plug-ins, automatically parses JSON with relatively faster rendering, and provides quick routing. Among other benefits, Fastify also has a cleaner syntax for writing async code in controllers.

Fastify is consistently faster than Express by 2–3 seconds. Fastify requires 6.27 seconds while Express requires 8.6 seconds. Fastify is the winner with 27.3% faster.

The only case where Fastify falls behind Express is in handling empty requests.

Express, however, has a stronger user base with plenty of documentation available. Express is so popular that it is ubiquitously associated with Node.js and part of the MEAN and MERN stack.

The documentation of fastify is not as expansive as you might expect from more mature frameworks. If you plan on using a library such as passport.js, you will find that it doesn’t work with Fastify. Make sure that Fastify is compatible with all of the other pieces of software you want to use.

Some of the features offered by ExpressJS are:

  • HTTP helpers (redirection, caching, etc)
  • Allows to dynamically render HTML Pages based on passing arguments to templates.
  • Allows to set up middlewares to respond to HTTP Requests.
  • View system supporting 14+ template engines
  • Robust routing

This is a typical example of a node application with express:

Node with express framework

On the other hand, Fastify provides the following key features:

  • 100% asynchronous: all the cores are implemented with asynchronous code, in this way not even a millisecond is wasted.
  • Highly performant: as far as we know, Fastify is one of the fastest web frameworks in town, depending on the code complexity we can serve up to 20000 requests per second.
  • Extendible: Fastify is fully extensible via its hooks, plugins, and decorators.
  • It is developer friendly and It comes with a logger too.

But Fastify is one of the fastest web frameworks in town, depending on the code complexity we can serve up to 76+ thousands requests per second.

This is a typical example of a node application with fastify:

Node with fastify framework

In summary, Fastify promises faster performance with low overhead, but Express is a familiar framework with which many developers may be more comfortable.

Thanks for reading… Hope it helped!

--

--