A Showdown Between Express.js and Fastify Web App Frameworks (2024)

The web application framework Express.js last had a major update in 2014 — that’s a long time, contended Tamar Twena-Stern, an XM Cyber senior system architect.

“The most popular Node.js framework is a framework that did not release a major version for almost 10 years,” Twena-Stern told a roomful of attendees at the International JavaScript conference on Sept. 27. “Don’t you think that we need to maybe not go to the obvious choice and maybe think about something new, something that is better fit to today’s standards?”

She waited for the audience to agree — which they did — before presenting her suggested alternative: Fastify. It’s created by developer Matteo Collina, who was a contributor to the Node.js framework as well as creator of Autocannon and Pino JS, a logging framework for Node.js.

Fastify’s Claim: Speed and Flexibility

Fastify is a new framework that has the same functionality as Express and Hapi, while boasting that it has faster speed, a better developer experience and more flexibility. Twena-Stern decided to put their speed boast to the test and shared the results in her presentation.

“According to Fastify’s comparison, they’re seven times much faster than other frameworks, but I decided that I like to write benchmarks on my own,” she said. “I have like a real passion for performance and when somebody tells me that thing, I have to check it out myself.”

So she did, using the benchmarking tool Autocannon to compare the Node.js Express server and a server with Fastify. She stated with a Hello World scenario, returning Hello World GET requests with no prefix to the router. She also turned off the logs, which she said could ruin performance.

Latency is the length of a request, and how much time it took to serve that request, she pointed out. In that category, she recommended looking at the 99th percentile and not at the average or the median.

“Why I recommend looking at a 99th percentile, because when you’re making a contract with a third party company, and you’re telling them […] all my requests are faster than something, then you need to take the 99th percentile, not the median,” she explained. “As you can see here, the 99th percentile is one millisecond.”

A Showdown Between Express.js and Fastify Web App Frameworks (1)

She pointed out Express successfully served about 20,000 requests per second, with a read average of 4.8 Mega, and served 221,000 total requests. Then she shared the Fastify results.

A Showdown Between Express.js and Fastify Web App Frameworks (2)

“First of all, that might not look so impressive to you, but then the 99 percentile went down from one millisecond to zero,” she said. “Let’s look at the average requests that Fastify has succeeded to serve it: It succeeded to serve about, on average, 50,000 requests — which is a lot, and, I think, the speed is about two and a half times faster than what we had [with] Express.”

The total requests served was 526,000 she added.

“It is also close to two and a half times faster than Express,” she said. “That’s like really impressive, in my opinion.”

A Showdown Between Express.js and Fastify Web App Frameworks (3)

Another Test with MongoDB

Unsure if that was an anomaly, she decided to test it using Node.js plus Express running with Mongoose functioning as the ORM plus MongoDB. Mongoose allows developers to enforce a specific schema at the application layer. She then compared that to Fastify running MongoDB. Again, she used Autocannon to compare the results.

“Here, we’re registering plugins, we’re registering DB connector and browse,” she said. She added a bit of the code, and required the first server to run, refining the schema, doing a post request and serving it.

A Showdown Between Express.js and Fastify Web App Frameworks (4)

Express results with MongoDB

“This is the Express, we can see 99% out of three milliseconds requests per second, we have about 6,500 (requests per second) on average, and on total, we have succeeded to serve about 70K requests,” she said.

A Showdown Between Express.js and Fastify Web App Frameworks (5)

Fastify with MongoDB results

By comparison, Fastify delivered the 99th percentile in two milliseconds with an average of approximately 8800 requests per second and it served about 86K results.

A Showdown Between Express.js and Fastify Web App Frameworks (6)

Comparison Express and Fastify running Mongo DB

“We’ve got like something which is like 40%, faster,” she said. “That’s still very impressive.”

Since ORMs can add to performance overhead, she then switched to a native Mongo Driver. The sped up Express from six to 600 with 7100 requests per second on average and 74,000 total requests.

A Showdown Between Express.js and Fastify Web App Frameworks (7)

Comparison with native MongoDB driver

“It did improve the performance of the Express server; that’s not enough and we’re getting Fastify is still much faster,” she added. “Fastify claims that they’re the fastest framework around. I can say that currently, they’re right.”

Twena-Stern also compared it to Hapi, KOA and other frameworks and found it still performed fastest, although she did not share the results of those tests.

What Makes Fastify Fast

One factor contributing to Fastify’s speed is the fast-jon-stringify library, which she said was significantly faster than the JSON.stringify() library for small payloads.

“That library gives an edge with when you get an HTTP request, you need to serialize to a JavaScript object, so they have a real edge here,” she said. “I recommend even if you don’t want to adopt Fastify, that you would consider looking at that library and try to optimize performance in your Express server.”

She also played with it to load it and wrote a server, replacing the standard Express middleware with body-parser and other “stuff.” She I wrote a middleware and got very big performance improvements there.

Fastify has a lightweight architecture, she said, that leverages plugins for components, defining a controller and connecting. Everything is a plug-in, she added.

“Their components are communicating very efficiently with one another and that also gives them an edge,” she said.

Fastify also follows recommendations regarding managing database connections, maintaining shared resources and maintaining an efficient connection pool for the database server, she added.

Finally, Fastify uses the log library Pino JS, which is considered one of the — if not the — fastest log libraries, she said.

Developer Experience

She also tested Fastify on developer experience and demonstrated some of the ways that Fastify turns logs and defines plugins to create certain functionalities. She demonstrated how it implements encapsulation, how it uses decorators, and how it deploys hooks in order to make operations in Fastify.

Overall, she said it was easy to learn, thanks in part to the tutorials Fastify offers on its site.

“Fastify gives plugins to almost everything, so if you can, check it out,” she said. “They have plugins for multiple functionality that we as developers need to have in our services.”

AWS Lambda can be used to write a Fastify server and expose it in Lambda with Fastify/aws-lambda. Google Cloud offers native support except for content-type parsing, she added.

TRENDING STORIES

Loraine Lawson is a veteran technology reporter who has covered technology issues from data integration to security for 25 years. Before joining The New Stack, she served as the editor of the banking technology site Bank Automation News. She has... Read more from Loraine Lawson
A Showdown Between Express.js and Fastify Web App Frameworks (2024)

FAQs

What is the difference between fastify and ExpressJS? ›

js, but they have major differences. Express focuses on simplicity and flexibility, while Fastify is dedicated to performance and extensibility.

Is fastify compatible with Express? ›

This plugin adds full Express compatibility to Fastify, it exposes the same use function of Express, and it allows you to use any Express middleware or application.

What are the disadvantages of fastify? ›

Disadvantages of Fastify

Being a relatively newer web framework, Fastify may have a smaller community compared to more established frameworks. This can result in limited availability of community-developed plugins, extensions, and community-driven support resources.

What is the difference between fastify and Hapi? ›

Fastify uses a schema-based routing system, where routes are defined using JSON schemas. This allows for easy validation and serialization of request and response payloads. On the other hand, hapi uses a more traditional callback-based routing system, where routes are defined using JavaScript code.

Which is better Express or NestJS fastify? ›

NestJS oficial page they even suggest you to use Fastify if you want to improve your app's performance, but it comes with Express by default. Many things doesn't seem to make sense to me tbh. In the picture attached below you can spot Fastify is 4x times faster, at request processing per second.

What are the benefits of fastify? ›

Performance: Fastify is designed to be one of the fastest web frameworks available. It uses an extremely optimized HTTP layer to achieve high throughput and low latency. Benchmarks have shown that Fastify can handle more requests per second compared to other frameworks like Express.

Why not to use Express JS? ›

js is great for building small to medium-sized applications, but it may not be the best choice for large-scale or enterprise-level applications. Express. js does not have a lot of features or tools that can help you manage the complexity and challenges of such applications, such as: Data modeling and validation.

Is fastify a node js framework? ›

Fastify is a web framework for Node. js that boasts speed, low overhead, and a delightful developer experience. Many Node.

How to migrate from Express to Fastify? ›

To migrate an Express route to Fastify, you need to:
  1. Remove the route from the express. Router instance.
  2. Register the route on the fastify instance in the plugin function.
  3. Update the route itself so that it conforms to the Fastify API.
Jun 28, 2023

Why is Fastify not popular? ›

Cons of Fastify: Fastify is not as easy to learn and use as Express, making it less suitable for beginners. It has a steeper learning curve due to its focus on performance and scalability. Fastify does not provide built-in support for templating engines, making it less suitable for building dynamic web pages.

What companies are using fastify? ›

List of companies using Fastify in India
CompanyCountryTechnologies
IO DataLabsIndiaFastify
ComUnus Technologies Pvt LtdIndiaFastify
Hupp TechnologiesIndiaFastify
Eminence InnovationIndiaFastify
6 more rows

Is Fastify production ready? ›

GitHub - mehmetsefabalik/fastify-template: production-ready and development-friendly minimal Fastify Typescript Boilerplate, includes Mongoose, Jest for testing, Eslint for linting.

Why use fastify over Express? ›

If you value stability, a wealth of resources, and a vast community, Express is the way to go. However, if you're looking for a faster, more efficient alternative with built-in validation and serialization, Fastify is an excellent option.

Is there something better than Express JS? ›

What can we use instead of ExpressJS? ExpressJS is a great framework, but it has its limitations. Some alternatives to ExpressJS can be used, like Koa, Hapi, Sails, Feather, etc. These are the most popular alternatives to ExpressJS.

How many requests can fastify handle? ›

Core features. These are the main features and principles on which Fastify has been built: 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 30 thousand requests per second.

Which is faster Express or fastify speed test? ›

Testing with Fast JSON Stringify

So clearly JSON. stringify was the major performance blocker as we can see Express an increase of 10% but Fastify has 9.3x increase in performance. Since the performance bottleneck is gone the only difference is raw framework cost which is why Fastify is now 13.2x faster than Express.

How to convert Express to fastify? ›

Converting an Express Application to Fastify
  1. Setting Up Fastify. const fastify = require('fastify')({ logger: true });
  2. Migrating Routes. Convert your Express routes to Fastify routes. ...
  3. Migrating Middleware. In Fastify, middleware is replaced by hooks. ...
  4. Error Handling. ...
  5. Starting the Server.

Is there something better than ExpressJS? ›

What can we use instead of ExpressJS? ExpressJS is a great framework, but it has its limitations. Some alternatives to ExpressJS can be used, like Koa, Hapi, Sails, Feather, etc. These are the most popular alternatives to ExpressJS.

Top Articles
3 Stages Of Negotiating A Settlement | Henke & Williams LLP
Britannica Money
Craigslist San Francisco Bay
It’s Time to Answer Your Questions About Super Bowl LVII (Published 2023)
Ups Dropoff Location Near Me
Www.craigslist Virginia
Ghosted Imdb Parents Guide
Voordelige mode in topkwaliteit shoppen
Activities and Experiments to Explore Photosynthesis in the Classroom - Project Learning Tree
LA Times Studios Partners With ABC News on Randall Emmett Doc Amid #Scandoval Controversy
Obituary | Shawn Alexander | Russell Funeral Home, Inc.
What Is A Good Estimate For 380 Of 60
Magicseaweed Capitola
Nene25 Sports
boohoo group plc Stock (BOO) - Quote London S.E.- MarketScreener
NBA 2k23 MyTEAM guide: Every Trophy Case Agenda for all 30 teams
Robert Deshawn Swonger Net Worth
Popular Chinese Restaurant in Rome Closing After 37 Years
Stoney's Pizza & Gaming Parlor Danville Menu
All Breed Database
Baldur's Gate 3: Should You Obey Vlaakith?
Drying Cloths At A Hammam Crossword Clue
Hefkervelt Blog
Lovindabooty
Masterbuilt Gravity Fan Not Working
The Powers Below Drop Rate
Schooology Fcps
Acuity Eye Group - La Quinta Photos
Siskiyou Co Craigslist
15 Downer Way, Crosswicks, NJ 08515 - MLS NJBL2072416 - Coldwell Banker
One Credit Songs On Touchtunes 2022
Gwu Apps
Dallas City Council Agenda
Metra Schedule Ravinia To Chicago
Geology - Grand Canyon National Park (U.S. National Park Service)
Jail View Sumter
Firestone Batteries Prices
10 Types of Funeral Services, Ceremonies, and Events » US Urns Online
Zom 100 Mbti
Wpne Tv Schedule
9294027542
Jackerman Mothers Warmth Part 3
Bellelement.com Review: Real Store or A Scam? Read This
Germany’s intensely private and immensely wealthy Reimann family
4Chan Zelda Totk
Wera13X
Wvu Workday
Craigslist Psl
ESPN's New Standalone Streaming Service Will Be Available Through Disney+ In 2025
De Donde Es El Area +63
Generator für Fantasie-Ortsnamen: Finden Sie den perfekten Namen
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 5437

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.