Search

Search pages, services, tech stack, and blog posts

Fastify

Fastify BackendFast and low-overhead Node.js framework

Fastify is our go-to when we need Node.js performance without switching runtimes. Schema-based validation, plugin encapsulation, and a built-in JSON serialiser make it ideal for high-throughput APIs.

Fastify is a high-performance Node.js framework focused on speed, developer experience, and plugin encapsulation. Its JSON serialisation is 2× faster than JSON.stringify, and its schema-based validation catches errors at the request boundary. At A Major, we choose Fastify for high-throughput API services where Node.js performance matters. Fastify's plugin system enforces encapsulation — plugins can't accidentally pollute global state. Combined with lifecycle hooks at every request stage, automatic OpenAPI generation from JSON Schema, and first-class TypeScript support, Fastify is our recommended Node.js framework for new performance-critical backends.

Quick start

bash
npm init fastify my-api
cd my-api
npm install
npm run dev

Read the full documentation at fastify.dev/docs/latest/

High-throughput JSON APIs

Fastify's JSON serialiser is 2× faster than JSON.stringify — measurable difference at scale.

Schema validation

JSON Schema validation on every request and response — errors caught at the boundary, not deep in your code.

Plugin encapsulation

Fastify's plugin system enforces encapsulation — no accidental global state between routes.

Auto OpenAPI docs

Swagger UI generated from your JSON Schema definitions — documentation that never goes stale.

Lifecycle hooks

Fine-grained hooks at every stage of the request lifecycle — preValidation, preHandler, onSend.

Low overhead

Minimal abstraction over Node's http module — Fastify's overhead is measured in nanoseconds.

Why it's hard

Plugin encapsulation learning curve

Fastify's encapsulation model is powerful but different from Express's flat middleware. Understanding parent/child plugin scopes takes time.

Smaller middleware ecosystem than Express

While Fastify has plugins for most needs, the ecosystem is smaller than Express. Some niche middleware may need custom implementation.

JSON Schema verbosity

Writing JSON Schema for request/response validation is verbose. Use typebox or fluent-json-schema to generate schemas from TypeScript types.

Best practices

Use @fastify/autoload for route discovery

Auto-load routes from a directory structure — convention-based routing without manual registration.

Define schemas with TypeBox

TypeBox generates JSON Schema from TypeScript types — write once, get validation and type inference together.

Use fastify-plugin for shared decorators

Wrap plugins that need to be accessible across the entire app with fastify-plugin to break encapsulation intentionally.

Enable ajv strict mode

Strict JSON Schema validation catches schema definition errors early — preventing silent validation bypasses.

Frequently asked questions




Want to build with Fastify?

Talk to our engineering team about your Fastify architecture. We'll respond within 24 hours.

1 spot available in May 2026Apr 2026 fully booked

We limit intake each month so every project gets the focus it deserves.