Fastify
A fast, low-overhead web framework for Node.js
js web framework designed for high throughput and low overhead, using schema-based JSON validation and serialization along with a plugin architecture to build fast, well-structured HTTP APIs.
Definition
Fastify is a Node.js web framework designed for high throughput and low overhead, using schema-based JSON validation and serialization along with a plugin architecture to build fast, well-structured HTTP APIs.
Overview
Fastify emerged in 2016 as a response to the performance ceilings and loosely structured plugin ecosystems of earlier Node.js frameworks. Its core design goal is speed without sacrificing developer ergonomics: routes, hooks, and plugins are all built around a strict encapsulation model, so plugins cannot leak state into the wider application unless explicitly decorated to do so. This makes large Fastify codebases easier to reason about than frameworks where middleware can arbitrarily mutate shared request or app objects. The defining technical feature of Fastify is its use of JSON Schema for both request validation and response serialization. Every route can declare a schema describing expected input and output shapes; Fastify compiles these schemas into optimized serialization functions ahead of time, which is a major source of its throughput advantage over frameworks that serialize JSON generically at request time. This schema-first approach also produces machine-readable API contracts that pair naturally with OpenAPI/Swagger documentation generation. Fastify's plugin system, built on the `avvio` boot sequencing library, allows encapsulated contexts: a plugin registered under a route prefix only affects routes within that context unless it opts into global scope. This gives large applications a modular structure similar to dependency injection, without a heavyweight framework layer forcing it. The ecosystem includes official plugins for CORS, JWT authentication, rate limiting, WebSockets, and database connectivity (Postgres, MongoDB, Redis), plus first-class TypeScript support. Fastify is commonly chosen for high-throughput API services, microservices, and backend-for-frontend layers where request latency and JSON serialization cost matter, and where teams want structural discipline enforced by the framework rather than by convention alone.
Key Features
- Schema-based request validation and response serialization using JSON Schema
- Ahead-of-time compiled serializers for significantly faster JSON output than generic serialization
- Encapsulated plugin architecture that prevents unintended state leakage between plugins
- Built-in support for async/await throughout the request lifecycle
- Extensive lifecycle hooks (onRequest, preValidation, preHandler, onSend, etc.)
- First-class TypeScript typings and strong ecosystem of official plugins
- Native support for HTTP/2 and low-overhead logging via Pino
- Benchmark-leading throughput among Node.js HTTP frameworks