Fastify - Fast and low overhead web framework for Node.js - Interview with Tomas Della Vedova (2024)

Servers, servers, servers. I’ve written a lot of Node.js servers since I began using it. Initially, I went through the API it provides but after a while most of the community settled on using Express.

In this interview you’ll learn about an alternative by Tomas Della Vedova. Fastify has been designed performance in mind.

Fastify - Fast and low overhead web framework for Node.js - Interview with Tomas Della Vedova (1)

I am an enthusiastic software engineer, who spends most of his time programming in JavaScript and Node.js. I am constantly forward the enrichment of my knowledge and the exploration of new technologies. Moreover, I truly believe in the open source philosophy, and I will always be passionate about technology, design, and cinema.

How would you describe Fastify to someone who has never heard of it?

🔗

Fastify is an opinionated web framework for Node.js; it focuses on performance and low overhead. The architectural pattern that we used to build it enables microservice ready applications.

The core is small and it exposes powerful APIs to extend it with all the functionalities that are needed.

Fastify is the handler function that you pass to the HTTP core module, nothing more.

We started building it from scratch, adding one feature at a time. For every new feature, we worked a lot on the optimization and lowering the overhead of the feature, trying to reach the “almost zero” overhead.

Fastify supports our of the box Hooks, express style middlewares, decorators, HTTP2 and async-await.

const fastify = require("fastify")();fastify.get( "/", async (request, reply) => ({ hello: "world" }));fastify.listen(3000, function (err) { if (err) { throw err; } fastify.log.info( `Server listening on ${fastify.server.address().port}` );})

We have extracted from Fastify all the code that could be separated from the framework itself and used in other situations, for example in our router, the serialization library and the middleware engine. We released them as separate libraries that don’t need Fastify as a dependency, so you can use them in your current framework as well, or even build one just for your needs!

How does Fastify differ from other solutions?

🔗

Given one of the core goals of the project is performance, we do not land any feature if the implementation isn’t well optimized and the cost that we pay is as low as possible.

Fastify has a robust plugin system, it guarantees the load (and close) order of the plugins and creates a zero cost encapsulation to help the users maintain a clean and ordered code. It will also help the user to write decoupled code and use a different version of the same plugin (or maybe with different configurations) in a different subsystem of the application. A similar approach with Express would cause the performance to drop significantly for each nesting level.

Furthermore, the plugin model is based on reentrant locks and given it’s graph-based, Fastify handles asynchronous code correctly while guaranteeing the loading order and the close order of the plugins.

The plugin system creates a direct acyclic graph, and in this way, it is impossible to create cross dependencies, and you can use a different version of the same plugin in different parts of your application.

Fastify - Fast and low overhead web framework for Node.js - Interview with Tomas Della Vedova (2)

Thanks to this architecture it is easy to split your application in multiple microservices because we’ll help you with the creation of a system where the separation of concerns and cohesion are two essential keys of your application.

Fastify - Fast and low overhead web framework for Node.js - Interview with Tomas Della Vedova (3)

Almost one year and a half ago me and Matteo, the coauthor of Fastify, started working on a nice project, fast-json-stringify. By doing different performances analysis we discovered that serialize JSON is very expensive, so we asked ourself, can we make it faster? We worked for 1-2 months, and we built fast-json-stringify, which is 2x-3x times faster than the native method (spoiler alert, we use JSON Schema).

const FJS = require("fast-json-stringify");const stringify = FJS({ type: "object", properties: { user: { type: "string" }, age: { type: "integer" } }});console.log(stringify({ user: "tomas", age: 24 }));

We were pleased with the results, so we started optimizing other parts that usually are pretty expensive. Routing, hooks, middlewares and so on.

After some time we put all together, and Fastify was born. We wanted to challenge ourselves to build an extremely fast web framework, with the goal to get very close to the performances of a plain node HTTP server.

What next?

🔗

Currently, we are close to the version 1.0.0. We are focusing on fixing the last bugs, and we are listening to feedback from our early adopters. In this way, we can try to meet their needs and handle breaking changes. We are also updating the API plugin to allow the users to declare their dependencies and provide better support for async-await.

An example of how async-await works in Fastify:

server.js

async function build (opts) { const fastify = require("fastify")(opts); fastify.register(require("fastify-helmet")); fastify.register(require("fastify-mongodb"), { url: "mongodb://mongo/db" }); fastify.register(require('./lib'), { prefix: "/v1" }); await fastify.ready(); return fastify;}

lib/index.js

async function plugin (fastify, opts) { const { db } = fastify.mongo; const collection = db.collection("users"); // you can reach this route with `/v1/user/:id` fastify.get("/user/:id", async (request, reply) => { try { return await collection.findOne({ id: request.params.id }); } catch (err) { reg.log.error(err); return new Error("Something went wrong"); } })}module.exports = plugin;

We want our community to continue to grow, so every time a plugin creator sends it work to us, before adding it to our “official” plugin list we help them to improve their code (if needed), and enforce a correct use of our API.

We are also constantly updating the documentation with all the hardest parts or our architectural decisions. For example, we wrote the hitchhiker’s guide to plugins to help users understand the architecture of the framework and how to use correctly the APIs that we expose, and we have just updated our getting started guide.

I hope it looks shiny!

Joke apart, one of our core design decision, is that Fastify should provide a lightweight and small core that is easy to extend with plugins. Probably most of the work we’ll do in the future will be in this direction while exposing new (and low overhead) APIs to the plugins creators and help them to create valuable plugins.

Regarding the future of web development I think that progressive web apps, AI and internet of things will play a important role. This is why with Fastify we created a “batteries not included” framework, we want to help developers build the applications they need by using the code they need.

I hope that the open source world will continue to grow massively as its doing right now, and that developers and companies will continue to release their work, in a way that everybody will continue to grow as a group, where we all help each other make valuable code to help people.

What advice would you give to programmers getting into web development?

🔗

Try. The better way to learn new things is to try them.

A book or a workshop can help until a certain point, but if you want to really understand how something works, just write it. Get your hands dirty.

If you have some problem with a library or have a question on how approach to a pattern or technology, ask.But remember to be always kind with others, we are all human beings and the way we interact each other is important.

If you open an issue be kind, thank for the work that has been done, explain your problem and if you can, propose a solution. It will be appreciated.

Contribute to open source, even with small things. The open source world is amazing and as much you give as much you get.

It’s hard to measure how much the open source world gave to me; it helped me to be a better developer and a better person.

Do not be discouraged by others experienced developers, everyone has been young and everyone will help you, as well as you will help other young developers in the future.

Yoshua Wuyts, creator of Choo and many other cool things.

Conclusion

🔗

Thanks for the interview Tomas! Fastify looks like something I should try on my servers.

You can learn more from Fastify site or Fastify GitHub.

Fastify - Fast and low overhead web framework for Node.js - Interview with Tomas Della Vedova (2024)

FAQs

Is fastify a node js framework? ›

Fastify is a next-generation web framework for Node. js that prioritizes speed, efficiency, and developer experience. Built with a focus on performance, Fastify offers lightning-fast routing, built-in input validation, and serialization capabilities to enhance your development process.

Is Fastify better than Express? ›

In benchmarks, Fastify has shown to be significantly faster than Express in terms of request throughput and response time. However, it's important to note that the performance of your server will depend on a variety of factors, including your hardware, network, and the complexity of your application.

Is Fastify free? ›

Fastify is a web framework, for Node. js, available free and open source under an MIT license.

How is fastify so fast? ›

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.

Should I use NestJS or fastify? ›

Fastify provides a good alternative framework for Nest because it solves design issues in a similar manner to Express. However, fastify is much faster than Express, achieving almost two times better benchmarks results.

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.

How popular is fastify? ›

Is fastify popular? The npm package fastify receives a total of 1,536,875 weekly downloads. As such, fastify popularity was classified as a key ecosystem project. Visit the popularity section on Snyk Advisor to see the full health analysis.

Is fastify compatible with Express? ›

You can register an entire Express application and make it work with Fastify.

What is the benefit of fastify? ›

Pros of Fastify: Fastify is optimized for performance and provides superior speed compared to other Node. js frameworks. It provides built-in support for features such as request validation, serialization, and deserialization, making it easy to build robust and secure applications.

What is done in fastify? ›

Request and Reply are the core Fastify objects. done is the function to continue with the lifecycle. It is pretty easy to understand where each hook is executed by looking at the lifecycle page. Hooks are affected by Fastify's encapsulation, and can thus be applied to selected routes.

Is Fastify worth it? ›

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.

Does Node.js count as a framework? ›

Node. js is a JavaScript runtime environment built on Chrome's V8 JavaScript engine. It's called a "runtime" and not a language or framework because it's an environment for executing JavaScript on a specific platform - in this case a server.

Is Express JS a Node.js framework? ›

Express is a node js web application framework that provides broad features for building web and mobile applications.

What is the fastest JavaScript framework? ›

After evaluating these frameworks against our defined criteria, Svelte emerges as the fastest JavaScript framework in many scenarios, particularly in terms of update performance and bundle size.

Is Nextjs a Node.js framework? ›

js is a runtime environment for server-side JavaScript execution. Next. js takes advantage of its status as a framework to provide a full suite of capabilities for server-side and static rendering in React apps, whereas Node. js is mostly used as a runtime environment.

Top Articles
Counter Currency: What It Is, How It Works, Example
Checklist: What makes a product green? - Green Built Alliance
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
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
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 5801

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.