Under The Hood
backend nestjs NestJS 10+ (`@nestjs/platform-fastify`)

Fastify Adapter (platform-fastify): Routing Performance vs Express

Last updated
Prerequisites:
NestJS HTTP Adapters (`HttpAdapterHost`)
Express vs Fastify architectures
  • nestjs
  • fastify
  • express
  • performance
  • platform-fastify
  • throughput

Read at your depth

The practical view

NestJS is platform-agnostic: it uses Express by default (`@nestjs/platform-express`), but you can switch to Fastify by installing `@nestjs/platform-fastify` and initializing `NestFactory.create(AppModule, new FastifyAdapter())`. Fastify provides up to **2x higher throughput (RPS)** and lower latency than Express due to its radix-tree router and fast JSON serializer (`fast-json-stringify`).

The same idea in other frameworks

nestjs equivalent
`NestFactory.create(AppModule, new FastifyAdapter())`.

Legacy vs modern

Default Express Platform vs High-Throughput Fastify Adapter

Switching from Express to Fastify doubles request throughput in high-QPS NestJS microservices.

before → after
Default Express Bootstrap
const app = await NestFactory.create(AppModule); // ❌ Defaults to slower Express platform
High-Performance Fastify Adapter
const app = await NestFactory.create(AppModule, new FastifyAdapter()); // ✅ NEW: Fastify engine

Interview gotchas

Context

This is the classic production deployment gotcha with Fastify.

The mechanical answer

Express binds to `0.0.0.0` (all network interfaces) by default. Fastify binds to `127.0.0.1` (localhost only) by default. If you deploy a Fastify app inside a Docker container and call `await app.listen(3000)`, the container port will **not be reachable from outside the container**. You **must pass `'0.0.0.0'` explicitly**: `await app.listen(3000, '0.0.0.0')`.

Trap

Forgetting `'0.0.0.0'` in `app.listen(3000)` causes container health checks and ingress routing to fail with connection refused.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.