Skip to content

Performance ​

A NestJS controller validates a request and its response through a pipe and an interceptor. An endpoint validates with the same schemas and runs neither. The same API, with the same Zod schemas and the same handlers, serves about 25% more requests per second where both are validated, and the same number where nothing is.

  • +27%

    GET with path and search parameters

    40,635 against 32,021 requests per second

  • +25%

    POST with a JSON body

    33,938 against 27,107 requests per second

  • Level

    GET with no schemas

    49,837 against 49,744 requests per second

The numbers ​

Each pair of bars is one request, sent as fast as each app answers it. Hover over a bar for the range it was measured in.

  1. GET with path and search parameters+27%

    nestjs-endpoints40,635

    NestJS32,021

  2. POST with a JSON body+25%

    nestjs-endpoints33,938

    NestJS27,107

  3. GET a list of 50 items+4%

    nestjs-endpoints10,072

    NestJS9,682

  4. POST rejected with a 400Level

    nestjs-endpoints24,619

    NestJS24,560

  5. GET with no schemasLevel

    nestjs-endpoints49,837

    NestJS49,744

Requests per second on one CPU core. Longer is better.
  • Validated requests are where the difference is. A GET with path and search parameters and a POST with a JSON body each validate on the way in and on the way out.
  • A long response narrows it. For a 14 KB list, most of the time goes to validating and serializing fifty items, which both do alike.
  • A rejected request is level, and an endpoint's 400 carries the full Zod issues.
  • A route with no schemas is level. An endpoint adds nothing to a request it doesn't validate.
The same numbers as a table
RequestValidatednestjs-endpointsNestJSDifference
GET with path and search parametersParameters in, an object out40,635 (40,481 to 41,507)32,021 (31,817 to 32,141)+27%
POST with a JSON bodyAn object in, an object out33,938 (33,730 to 34,304)27,107 (26,885 to 27,443)+25%
GET a list of 50 itemsA 14 KB object out10,072 (9,963 to 10,260)9,682 (9,521 to 9,767)+4%
POST rejected with a 400An object in, which breaks five rules24,619 (24,488 to 24,675)24,560 (24,191 to 25,271)Level
GET with no schemasNothing49,837 (48,597 to 50,494)49,744 (48,836 to 50,496)Level

Medians of six rounds, with the range across them. Two runs of the same app differed by up to 0.6%, so a difference that small is shown as level.

What was compared ​

One API, written twice:

nestjs-endpointsNestJS
Routesendpoint.query() and endpoint.mutation()@Controller() classes
Requestsparams, query and input schemas@Param({ schema }), @Query({ schema }) and @Body({ schema }), with the global StandardSchemaValidationPipe
ResponsesAn output schemaStandardSchemaSerializerInterceptor, with @SerializeOptions({ schema }) on each handler

The controllers are set up as the NestJS docs describe, and an endpoint is a NestJS controller too. Both apps use the same schemas and handler bodies, and every 200 response is the same in both, byte for byte.

Where the time goes ​

Both apps run the same Zod schemas around the same handlers, so the validation itself costs the same in each. The difference is what a request passes through to get to them:

  • A controller validates through NestJS's request pipeline. Every pipe gets every argument and picks which to validate, and an interceptor wraps the handler.
  • An endpoint calls each schema on its own value, with safeParse in its handler, so it needs neither.

NestJS controller

endpoint

Routing, middleware and guards

Routing, middleware and guards

Interceptor

Runs the steps inside it as an RxJS stream, to get at the return value.

19 promises, 15 RxJS subscriptions

No interceptor

A pipe on each parameter

Each value passes through five async functions.

26 promises

No pipe

Prototype keys removed

From each value, before its schema sees it.

Left to the schema

Zod parses the parameters

Zod parses the parameters

Your handler runs

Your handler runs

Zod parses the response

Zod parses the response

31 microseconds a request

59 promises, 15 RxJS subscriptions

25 microseconds a request

14 promises, as many as a route with no schemas

A GET with path and search parameters. A percentage is that step's share of what the three cost together, to the nearest 5%.

The rest of the pipeline is the same in both. A pipe or an interceptor your app adds runs on an endpoint as it does on a controller, and costs the same.

What each step costs ​

Each step's share of what the three cost a controller together, to the nearest 5%:

GETPOST
The interceptor70%65%
Of which, running any interceptor at all55%45%
The pipe on each parameter20%15%
Removing prototype keys10%20%
  • The interceptor is most of it. About half the whole is NestJS running an interceptor through RxJS at all, even one that only calls next.handle().
  • A pipe is a chain of async calls, five for each parameter.
  • Removing prototype keys is a safety step of the schema pipe, counted on its own. An endpoint leaves those keys to Zod: a z.object() drops them, a z.looseObject() or a z.record() keeps prototype and constructor, and z.any() keeps all three.
  • The validation is not what is slow. A controller that calls the same Zod schemas in its handler, with no pipe and no interceptor, is about as fast as an endpoint.

What it means for your app ​

The handlers measured do no I/O, so these numbers are what the framework costs per request: about 25 microseconds for a validated GET in an endpoint, and 31 in a controller. A handler that queries a database spends far longer there, and the share you gain is smaller.

At the same load, both answer in the same time: a median under a millisecond for every request above.

How it was measured ​

  • Where: Apple M1 Pro, Node.js 26.13, NestJS 12.4 on @nestjs/platform-node, Zod 4.6. Each app runs its production build on one CPU core.
  • Load: 64 keep-alive connections, each sending as fast as the app answers.
  • Rounds: six ten-second rounds for each app after a warm-up, each in a new server process, with the apps taking turns.
  • The steps: each is the controller app with that step taken out.

The apps and the scripts are in the repository's benchmarks folder: pnpm bench for the numbers, and pnpm bench:breakdown for the steps and what a request creates.

Released under the MIT License.