Backend

Fastify

A fast Node.js framework with a plugin architecture and JSON Schema validation.

What it is

Fastify is built with performance and low overhead in mind. Schema-based response serialization and a fast router give it a clear edge over Express.

Everything extends through plugins that have their own encapsulated scope. That helps split an app into parts without global state.

Request and response validation is described by schemas, and OpenAPI docs come from them. The Pino logger is built in and TypeScript support is good.

Use it when

  • You need high API throughput on Node.js.
  • You want schema validation and auto-generated docs.
  • You prefer plugin modularity over global middleware.

Avoid it when

  • The team has many existing Express middleware that are hard to port.
  • You need rigid architecture with DI: consider NestJS (it can run on Fastify).

Key concepts

Plugin
A function that registers routes, hooks or decorators in an encapsulated scope.
Schema
JSON Schema for input validation and fast output serialization.
Hooks
Lifecycle points: onRequest, preHandler, onSend.
Pino
A fast structured logger built into Fastify.

Example

A route with schema-validated params.

Interview questions

  1. 1. Why is Fastify faster than Express?

    A fast router and serialization with a precompiled schema, plus less per-request overhead.

  2. 2. What is plugin encapsulation?

    Decorators and hooks registered in a plugin are visible only there and in its child plugins. This prevents state from leaking between parts of the app.

  3. 3. Why use schemas?

    They validate input, speed up output serialization and feed OpenAPI documentation.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).