How it works
Fastify routes accept a JSON Schema for the body, query string and response. Fastify compiles those schemas into fast validation and serialisation functions, so bad input is rejected before a handler runs and responses skip slow generic JSON conversion. With a type provider such as TypeBox, the same schema also gives the handler its TypeScript types.
Everything is a plugin (database connections, auth, groups of routes), and plugins are encapsulated so one part of an app cannot accidentally change another. Logging through Pino is built in. It is an OpenJS Foundation project, and in benchmarks it handles noticeably more requests per second than Express on the same machine.
Fastify pros and cons
Pros
- High throughput with low overhead
- Validation and response shaping built in through JSON Schema
- Encapsulated plugins keep large apps organised
- Built-in structured logging with Pino
Cons
- More concepts to learn (plugins, hooks, decorators) than Express
- Smaller ecosystem than Express, though most needs are covered
- Built for Node.js, not for edge runtimes
When to use Fastify
Pick it when
- Busy Node.js APIs where throughput and hosting cost matter
- Teams that want validated input and typed routes from the start
Skip it when
- The code must run on Cloudflare Workers or other edge runtimes
Fastify pricing
Fastify vs the alternatives
Related terms
More in Backend and APIs
Frameworks