English for Fastify Developers

Master the vocabulary for discussing plugins, schemas, hooks, and throughput when building APIs with Fastify.

Fastify’s identity as a framework is built around two words that show up in nearly every discussion of it: “schema” and “throughput.” Teams choose Fastify specifically for request validation performance and low overhead, so being able to talk about those tradeoffs precisely — not just “it’s fast” — matters in design reviews and architecture discussions alike.

Key Vocabulary

Plugin (Fastify plugin) An encapsulated unit of functionality — routes, decorators, hooks — registered into a Fastify instance, with its own scope that doesn’t leak into sibling plugins unless explicitly shared. Example: “We wrapped the authentication logic in its own plugin so it stays encapsulated and doesn’t accidentally register routes visible to unrelated parts of the app.”

Encapsulation Fastify’s default behavior of scoping decorators, hooks, and configuration to the plugin they’re registered in, preventing accidental leakage across unrelated parts of an application. Example: “This decorator isn’t visible outside its plugin because of encapsulation — if we need it globally, we have to register it at the root instance instead.”

Schema (JSON Schema validation) A JSON Schema definition attached to a route that Fastify uses to validate incoming requests and serialize outgoing responses, both for correctness and for performance. Example: “Adding a response schema here isn’t just about validation — Fastify uses it to generate a much faster serializer for the response body.”

Hook (lifecycle hook) A function that runs at a specific point in the request/response lifecycle, such as onRequest or preHandler, used for cross-cutting concerns like authentication or logging. Example: “We’re checking the auth token in a preHandler hook so every route under this plugin gets the check without repeating the logic.”

Decorator A way of adding custom properties or methods to Fastify’s request, reply, or server instance objects, making shared utilities available without importing them separately in every handler. Example: “We decorated the request object with a currentUser property set in an earlier hook, so handlers can just read request.currentUser directly.”

Serialization The process of converting a JavaScript object into a JSON string for the response, which Fastify can significantly accelerate by compiling a serializer from the route’s response schema. Example: “Serialization time dropped noticeably once we added explicit response schemas — Fastify can skip a lot of generic JSON.stringify overhead that way.”

Throughput The number of requests a server can handle per unit of time, often the primary metric cited when comparing Fastify’s performance against other Node.js frameworks. Example: “We saw a meaningful throughput improvement after migrating this service, mostly from schema-based serialization rather than routing changes.”

Common Phrases

In code reviews:

  • “This route doesn’t have a response schema, so we’re missing out on the serialization speedup and losing a layer of output validation.”
  • “This decorator is being registered at the root instance, but it’s only used by one plugin — should we scope it down so encapsulation actually protects us here?”
  • “We’re duplicating this auth check in every handler under this plugin — let’s move it into a shared preHandler hook instead.”

In standups:

  • “Yesterday I added response schemas to our highest-traffic routes; today I’m benchmarking the serialization speedup before we roll it out further.”
  • “I’m blocked on a plugin encapsulation issue — a decorator I need isn’t visible from a sibling plugin, so I need to register it higher up the tree.”
  • “I finished moving our auth check into a preHandler hook, which removed about a dozen duplicated blocks across route handlers.”

In architecture discussions:

  • “Fastify’s plugin encapsulation model maps well onto our service’s module boundaries, so each team’s routes stay isolated by default.”
  • “The throughput gain here comes mostly from schema-based serialization, not from routing — so we should prioritize adding schemas to hot paths first.”
  • “We’re using hooks for cross-cutting concerns like logging and auth specifically so route handlers stay focused on business logic.”

Phrases to Avoid

Saying “it’s fast” without naming the mechanism. Say instead: “schema-based serialization skips a lot of generic JSON stringification overhead” — this is the actual, specific reason Fastify tends to outperform frameworks without built-in schema validation, and it’s more persuasive in a technical discussion.

Saying “the plugin isn’t working” for an encapsulation issue. Say instead: “this decorator isn’t visible outside the plugin it was registered in, which is expected encapsulation behavior” — this is a design feature, not a bug, and naming it precisely avoids wasted debugging time.

Saying “add validation” vaguely when you mean a schema. Say instead: “add a JSON Schema to this route for both request validation and response serialization” — schemas in Fastify do double duty, and vague language obscures that the response side has a performance benefit too.

Quick Reference

TermHow to use it
plugin”Authentication logic is encapsulated in its own plugin.”
encapsulation”Decorators don’t leak outside the plugin they’re registered in.”
schema”A response schema speeds up serialization and validates output.”
hook”The preHandler hook checks auth before the route handler runs.”
decorator”We decorated the request with a currentUser property.”
throughput”Schema-based serialization improved throughput noticeably.”

Key Takeaways

  • Name the specific mechanism behind Fastify’s speed — schema-based serialization — rather than a vague “it’s fast” claim.
  • Understand encapsulation as Fastify’s default, intentional scoping behavior, not a bug when a decorator isn’t visible somewhere unexpected.
  • Use hooks for cross-cutting concerns like auth and logging, keeping route handlers focused on business logic.
  • Remember that schemas serve double duty — request validation and response serialization speedup — when recommending they be added.
  • Distinguish plugin-level decorators from root-level ones precisely when debugging visibility issues across plugins.