Logo

dev-resources.site

for different kinds of informations.

Fastify v5 vs v4 β€” vs Encore.ts

Published at
9/20/2024
Categories
node
javascript
fastify
backend
Author
eandre
Categories
4 categories in total
node
open
javascript
open
fastify
open
backend
open
Author
6 person written this
eandre
open
Fastify v5 vs v4 β€” vs Encore.ts

Fastify, one of the most popular web frameworks for Node, just announced a major new release, version 5.0.

We were initially very excited to see if any cool new features or improvements were added, in case there was something we could take inspiration from in Encore.ts.

Unfortunately, after taking it for a spin, we felt it was quite underwhelming: the new release is extremely light on new features, but extremely heavy on breaking changes.

Let's take a look at what's new, and whether it's worth upgrading.

Fastify v5 comes with lots of breaking changes

Don't believe me? Check out the migration guide. It clocks in at almost 2000 words! It lists no less than 20 breaking changes. That's a lot of breakage to consider.

As far as we can tell, most of the breaking changes amount to "cleaning things up" in the code base.

It removes a lot of convenient shorthands for defining JSON Schemas, making schema validation more verbose and less readable.

It also removes a lot of deprecated functionality. Sometimes this is a good thing, if the functionality carries a significant maintenance burden. But in this case, a lot of the removed functionality is essentially a one-liner.

For example, reply.getResponseTime() is removed in favor of reply.elapsedTime. Maybe elapsedTime is a better name, but the cost of maintaining getResponseTime, with its one-line implementation, is zero.

Still, it's easy enough to grep a codebase for getResponseTime and fix it. Other breaking changes are more difficult.

Consider for example fastify.hasRoute() still exists, with exactly the same signature, but the behavior has changed in a subtle way. It used to support passing in a request path to evaluate whether an incoming request matches a route or not.

In Fastify v5 the method instead only supports matching the exact string given when registering the route. Migrating over to this is much more difficult, as it's not always clear whether you need to change your code or not.

Fastify v5 has very few, minor improvements

At this point I hear you say, "surely all the breaking changes were done for good reason!". Unfortunately the documentation is surprisingly sparse when it comes to the benefits of upgrading to v5.

The only new feature listed is support for the Diagnostic Channel API.
Is that worth upgrading for? For most people, probably not.

The other improvement is a modest performance boost.

From our benchmarking, Fastify v5 is about 5-10% faster than v4, depending on configuration settings and whether you use schema validation. That's nothing to sneeze at! But it's not a game changer either.

Is upgrading worth the hassle? Probably not.

It's disappointing to see a major new release of a popular framework that is so light on new features, and so heavy on breaking changes.
Particularly when the breaking changes are seemingly done to clean up internals rather than improving the user experience.

Our belief is that migrating from Fastify v4 to Fastify v5 is probably not worth it for most people.

If you care about performance or reliability, you should probably check out Encore.ts instead of spending time migrating to Fastify v5.

It's about twice as fast, and provides a lot of other benefits as well, like TypeScript-native schema validation, automatic tracing (no need to manually instrument your code with the Diagnostic Channel API!), and more.

Encore.ts vs Fastify performance

What's more, Encore.ts takes backwards compatibility extremely seriously, and follows the Linux Kernel model when it comes to breaking changes: don't.
And Encore.ts is of course also open source.

fastify Article's
30 articles in total
Favicon
Understanding CORS and Setting it up with NestJS + Fastify πŸš€
Favicon
Building a Real-Time Auction Platform: Behind the Scenes
Favicon
Async Local Storage is Here to Help You
Favicon
Master Node.js with the 5th Edition Cookbook
Favicon
Real-time data replication in Postgres and Node.js
Favicon
NestJS vs. Ditsmod: pipe features
Favicon
NodeJS Framework which one is Fast
Favicon
Gerando Documentação de API AutomÑtica com Fastify, @fastify/swagger e Zod
Favicon
Fastify v5 vs v4 β€” vs Encore.ts
Favicon
nestjs vs fastify Battle
Favicon
Speeding Up Your Website Using Fastify and Redis Cache
Favicon
Streaming PostgreSQL data with Fastify
Favicon
Fastify adoption guide: Overview, examples, and alternatives
Favicon
The Essential Do's and Don'ts of Fastify: Unlocking Your API's Potential
Favicon
How to Customize the Fastify Logger
Favicon
Express.js needs a funeral
Favicon
Serve Next.js with Fastify
Favicon
Nextjs custom server with fastify
Favicon
Testing Your API with Fastify and Vitest: A Step-by-Step Guide
Favicon
Introduction to Fastify: A Superior Node.js Framework
Favicon
Fastify Developers: Upgrade Your Logging with This Simple Guide
Favicon
How to create a lan server using Node.js and Fastify.js
Favicon
Criando sua API com Fastify e Prisma
Favicon
DynamoDB Single Table Design
Favicon
Stop exposing your Node.js metrics πŸ›‘
Favicon
Fastify Meets WireMock: External Service Mocking
Favicon
The Fastify book is out!
Favicon
How to Automatically Consume RESTful APIs in Your Frontend
Favicon
Validate the Fastify input with Joi
Favicon
Starting With Fastify Today

Featured ones: