#What are some surprises one can encounter by using Fastify instead of Express?
9 messages · Page 1 of 1 (latest)
Passport integration is flaky* (maybe it got better though)
The request/response objects in a middleware are no actually fastify's Request and Reply, but Node's base request/response objects due to some techincal limitation
App setup and test setup is more involved, because it's not the default.
Apart from that, it's fine
- but frankly, passport integration is pretty confusing even with express
Thank you for the info. Is there anything that is straight up impossible with Fastify but possible with Express?
I wouldn't say there is anything is straight up impossible. One think that comes to mind is if you use GraphQL, then there's no support for Federation 2 with the Mercurius driver for fastify yet.
Btw, don't expect that fastify is going to improve the performance drastically. Most time will be still spent on database queries and other I/O operations. Route resolution is a minor part of the whole application and you'd only see benefits when you have a large number of routes.
OK, I think I will go with Express then. 4 or 8 instances of Express in cluster mode of PM2 will hopefully compensate any lack of performance - if such thing arises.
The application itself is rarely the weakest part - unless you're doing a lot of unoptimized looping. The real bottleneck is usually the database.
Of course, Fastify is faster than Express
This is somewhat of a myth backed up by nothing more than a single article from a lot of years ago, "faster" in itself doesn't mean a lot as in the article it meant "faster when you get 20K request per second" which is probably not the typical use case. You will probably find very different results if you test on a few hundreds requests per second or even on a up-to-date stack.
Best (and only) way to know for sure is to make your own benchmark with your own setup in conditions that will match highest expected traffic.
Fastify will have quite a few edge cases with Nest that will demand attention compared to being completely transparent with Express. If you know exactly why you have to use Fastify it might be worth it but otherwise it can (and will) lead to huge time loss.