Introducing Fastify, a Speedy Node.js Web Framework – InApps is an article under the topic Software Development Many of you are most interested in today !! Today, let’s learn Introducing Fastify, a Speedy Node.js Web Framework – InApps in today’s post !

Read more about Introducing Fastify, a Speedy Node.js Web Framework – InApps at Wikipedia

You can find content about Introducing Fastify, a Speedy Node.js Web Framework – InApps from the Wikipedia website

Matteo Collina

Matteo has many years’ experience in the software industry and is a well-known figure in the global Node.js, Internet of Things and open source software communities. He first started working with Node.js in 2010, and, to date, has released dozens of Node.js modules. He is also co-author of the book JavaScript: Best Practices (FAG Milan, 2013) .

Why have we written yet another web framework for Node.js? I am committed to making the Node.js platform faster, more stable and more scalable. In 2016, myself and David Mark Clements started Pino, which was designed to be the fastest logger for Node.js, and it now has four active maintainers and an ecosystem of hundreds of modules.

Fastify is a new web framework inspired by Hapi, Restify and Express. Fastify is built as a general-purpose web framework, but it shines when building extremely fast HTTP APIs that use JSON as the data format. These are extremely common in both web and mobile software architectures, so Fastify could improve the throughput of the majority of applications.

This is an example web server that renders a JSON response:

Here is our Getting Started guide if you want to test it out now. For those that want a bit more of an explanation behind the why and the what of Fastify, please read on.

Read More:   Containers at Scale, Mantl, and Preserving Open Source Communities – InApps Technology 2022

Reducing the Overhead

The above diagram shows the number of request/second to send a { “hello”: “world” } response as JSON. We use this simplistic benchmark to evaluate the overhead of all the various frameworks – it does not represent the actual throughput of a real-world application. We assert that Fastify is the framework with the lowest overhead compared to the feature that it provides.

Fastify uses fast-json-stringify to double the throughput of the rendering of JSON, and find-my-way to reduce the routing by a factor of 10 compared to alternatives. Fastify consumes the same middlewares that Express consumes, but we contend it is faster.

A good chunk of the speed increase in Fastify comes from the findings described in my “Reaching Ludicrous Speed” talk at Node.js Interactive 2015:

Fully encapsulated plug-ins

Fastify offers a plug-in model similar to that of Hapi. It adds full encapsulation of plug-ins so that each plug-in can use its own dependencies and hooks if it wants to. This enables greater software reuse and decoupling. Furthermore, the plug-in model is based on reentrant locks and graph-based, it perfectly handles asynchronous code and it guarantees the load order and the close order of the plug-ins.

Fastify has a wide range of plug-ins already developed, including those for template rendering, React integration, GraphQL support, serving static files, and database drivers.

The following server makes uses of this capability:

And subsystem/index.js:

Note that both the “subsystem” plug-in and the main file register “point-of-view” provides handling of multiple templating languages. Those two instances of the plug-in are completely encapsulated via the use of prototypical inheritance, which makes it close to a zero cost abstraction. A similar approach with Express would cause the performance to drop significantly for each nesting level.

Check out our guide to know more about plug-ins.

Note: In the example, the Marko templates have been omitted, you can check the full source code on GitHub.

Made in Italy with Love

Fastify is currently sponsored by nearForm and LetzDoIt, which offers a new activities app and has just deployed Fastify to production. Fastify is fully made in Italy, between Udine and Forlì, where co-creator LetzDoIt engineer Tomas Della Vedova and myself live, respectively. We wrote it because we saw that the APIs for most web frameworks could not be easily optimized, and it would not reasonable to break backward compatibility.

I will present Fastify during my “Take your HTTP server to Ludicrous Speed” session at Node.js Interactive. I will also be holding a performance workshop alongside my colleague, David Mark Clements.

Feature image via Pixabay.


Rate this post
As a Senior Tech Enthusiast, I bring a decade of experience to the realm of tech writing, blending deep industry knowledge with a passion for storytelling. With expertise in software development to emerging tech trends like AI and IoT—my articles not only inform but also inspire. My journey in tech writing has been marked by a commitment to accuracy, clarity, and engaging storytelling, making me a trusted voice in the tech community.

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download


      Success. Downloading...