Fastify vs Express: The Difference Isn't the Benchmark

By Aakash Verma · · 4 min read

Every Fastify vs Express comparison opens with a requests-per-second chart, and Fastify wins it. Fine. For almost every API I'd be asked to build, that chart doesn't matter, because the database query behind the route takes 20 ms and the framework's overhead is a rounding error next to it. The real differences are about structure: how each one wants you to validate input, shape output, split code and log. That's what I'd choose on.

Versions on npm, checked November 27, 2026: Fastify 5.12.8 (published November 2) and Express 5.3.0 (October 9). Last week's downloads: Express about 207 million, Fastify about 23.5 million. Express is in my stack and has been for years, so read the rest with that bias in mind.

The one-line answer

New API with a team, a schema-first habit and a long life ahead: Fastify. An existing Express app, or a small service where half the work is gluing middleware together: Express 5, and don't move it. I've written about Hono vs Express for the case where the code might run on Workers or Bun; this post is the Node-server case.

Schemas are the actual feature

In Express, validation is something you add. You pick zod or joi or express-validator, write a middleware, and remember to put it on each route. Responses go out as whatever object you passed to res.json(), extra fields included.

Fastify puts a JSON Schema on the route itself, for the body, query, params, headers and each response status:

fastify.post('/invoices', {
  schema: {
    body: {
      type: 'object',
      required: ['customerId', 'amount'],
      properties: {
        customerId: { type: 'string' },
        amount: { type: 'integer', minimum: 1 }
      }
    },
    response: {
      201: {
        type: 'object',
        properties: { id: { type: 'string' }, status: { type: 'string' } }
      }
    }
  }
}, async (req, reply) => {
  const invoice = await createInvoice(req.body)
  return reply.code(201).send(invoice)
})

Bad input gets a 400 before your handler runs (Ajv, through @fastify/ajv-compiler). The response schema does something people underrate: Fastify serializes with fast-json-stringify, and properties not in the schema are dropped. If createInvoice returns the row with an internal stripe_customer_id on it, the client never sees it. In Express that field goes out unless someone remembered to strip it.

The same database row sent by Express with internal fields, and by Fastify with only the fields in the response schema

That's the security argument for Fastify, and it's a better one than speed. It cuts both ways, though. Forget to add a new field to the response schema and it silently vanishes from the API, and somebody on the frontend spends an afternoon wondering why dueDate is undefined. If you write TypeScript, a type provider (TypeBox or zod) keeps the schema and the types in one place so that mostly stops happening.

Plugins instead of a flat middleware list

Express has one middleware stack and the order you call app.use() is the order things run. Simple, and it stays simple until the app has 40 routes and an auth middleware that some routes must skip.

Fastify's register() gives each plugin its own scope. Decorators and hooks registered inside a plugin apply to the routes in that plugin, not to the whole app, unless you wrap it with fastify-plugin to share it upward. You can put the admin routes, their auth hook and their rate limit in one plugin and know nothing leaks into the public routes. It's more to learn. The first time a hook "doesn't run" it's because of encapsulation, every time.

Logging is already there

Fastify ships with pino. Turn on logger: true and every request gets a request id and a JSON log line with the response time. In Express you add morgan or pino-http yourself. Not hard, just one more decision, and plenty of Express services run in production with no request ids, which makes reading logs during an incident miserable.

fastify.inject() (from light-my-request) also deserves a mention: you can call a route in a test without opening a port. Express tests usually pull in supertest for the same thing.

What Express still does better

The ecosystem. Twenty years of middleware, every tutorial, every Stack Overflow answer, every auth library's example. Passport, multer, express-session: they assume Express. Fastify has its own versions (@fastify/multipart, @fastify/session and so on), and they're good, but when you hit an odd integration the Express answer usually exists already.

And Express 5 fixed the two old complaints. Async errors in handlers now reach your error middleware without a wrapper, and the route matcher was rewritten (path-to-regexp 8), with stricter syntax for wildcards. If you avoided Express because of express-async-errors, that reason is gone.

Moving an Express app to Fastify

@fastify/express (4.0.14, published November 26) lets Fastify run Express middleware, so you can move route by route. I'd only do it for a reason: you want response schemas because of a data-leak scare, or the team keeps fighting the middleware order. "It's faster" isn't one. Profile first; the slow part is nearly always a query, an N+1 loop or a missing index, and switching frameworks fixes none of those.

How I'd decide

If I'm starting a new Node API that several people will work on for years, and it's mostly JSON in and JSON out, I'd take Fastify for the schemas and the plugin scoping. If it's an existing Express codebase, a quick internal tool, or something leaning on Express-only middleware, Express 5.

If you have a Node backend that's grown into something nobody wants to touch, or you're picking the stack for a new one and want a second opinion, book a free call. All consultation is free, and here's what I do for Node.js backends.

Introductory offer

Free cloud cost optimization. You only pay from what I save.

I cut your AWS, cloud, Supabase or Vercel bill for free and keep half of what I save for 6 months. Save nothing, pay nothing. Code, architecture and infrastructure.

See the offer →