English for Fastify v5 Developers
Master the English vocabulary for Fastify v5: plugin architecture, hooks lifecycle, decorators, schema-first validation, type providers, and reply.send explained.
Fastify has grown into one of the most popular Node.js web frameworks for teams that prioritise performance, type safety, and plugin encapsulation. Version 5 introduced breaking changes alongside significant improvements, and understanding the precise English terminology for its core concepts helps developers communicate clearly in code reviews, onboarding sessions, and API design discussions.
Key Vocabulary
Plugin — the fundamental unit of Fastify’s extensibility model. Every route, decorator, and hook is registered through a plugin, which receives the Fastify instance and an options object. “Wrap the database connection logic in a plugin so the connection pool is available as a decorator across the entire application scope.”
Plugin architecture — Fastify’s encapsulation model where each plugin creates an isolated scope, preventing accidental cross-contamination of routes, decorators, and hooks between unrelated parts of the application. “The plugin architecture means our authentication plugin only adds the verifyToken decorator to the routes registered within the same scope, not to public routes in sibling plugins.”
Hook — a lifecycle callback registered with fastify.addHook() that intercepts the request or reply at a specific stage of processing, such as onRequest, preHandler, or onSend. “Add an onRequest hook to validate the API key before the route handler runs, so authentication logic is not repeated in every route.”
Decorator — a property added to the Fastify instance, request object, or reply object using fastify.decorate(), making shared utilities or state available throughout the application. “Use fastify.decorate(‘db’, pool) so every plugin can access the database connection as fastify.db without importing it explicitly.”
Schema-first validation — Fastify’s approach of using JSON Schema objects to validate request bodies, query parameters, headers, and response payloads before the handler executes. “Define the body schema upfront — Fastify compiles it to a validator at startup, so invalid requests are rejected immediately with a structured error rather than reaching your business logic.”
Type provider — a TypeScript integration that maps JSON Schema definitions to static TypeScript types, enabling full type inference in route handlers without manual type assertions. “With the JSON Schema to TypeScript type provider configured, the request body type in the handler is inferred automatically from the schema we already wrote.”
reply.send() — the Fastify method used to send a response from a route handler, which also triggers the serialisation pipeline defined by the response schema. “Call reply.send(data) rather than res.json(data) — Fastify’s serialiser is significantly faster because it compiles the response schema ahead of time.”
Encapsulation — the behaviour where decorators, hooks, and routes registered inside a plugin are invisible to sibling or parent plugins unless explicitly shared via fastify-plugin. “Encapsulation is why our rate-limiting hook only applies to the /api scope — it was registered inside the API plugin rather than at the root instance.”
Common Phrases
- “Register the plugin with fastify-plugin if you need the decorator to be visible outside its scope.”
- “The preHandler hook runs after route matching but before the handler — that’s where authentication belongs.”
- “Schema compilation happens at startup; a malformed schema will throw immediately rather than failing silently at runtime.”
- “Use reply.hijack() only if you need to bypass Fastify’s response lifecycle entirely.”
- “In v5, the default content type parser for JSON is stricter — make sure your clients send the correct Content-Type header.”
Example Sentences
When reviewing a pull request: “This authentication check is duplicated in every route handler. Extract it into a preHandler hook on the parent plugin so it applies automatically to all child routes.”
When onboarding a new developer: “Fastify’s plugin architecture means that decorators added inside one plugin are not visible in sibling plugins by default. If you want to share the database decorator across the whole app, wrap your plugin with fastify-plugin to opt out of encapsulation.”
When discussing performance with a technical lead: “By defining a response schema on every route, we enable Fastify’s fast-json-stringify serialiser, which is typically three to five times faster than JSON.stringify for predictable object shapes.”
Professional Tips
- Use “lifecycle hook” when referring to Fastify hooks in architecture discussions to distinguish them from framework-level event emitters or React-style hooks.
- Explain encapsulation early when onboarding developers who come from Express — the scoping behaviour is the single most common source of confusion for newcomers.
- When discussing type providers, emphasise that they eliminate the “write schema twice” problem — the same definition drives both runtime validation and compile-time type checking.
- In v5 upgrade discussions, highlight the stricter JSON parser and the removal of legacy callback-style plugins as the two most impactful breaking changes.
Practice Exercise
- A junior developer is confused about why a decorator added in one plugin is undefined in another plugin’s route handler. Write a two-sentence explanation referencing encapsulation.
- You need to log every incoming request including the method, URL, and IP address. Which hook would you use and why? Write three sentences.
- Explain the performance benefit of schema-first validation to a product manager who is evaluating whether to migrate from Express to Fastify.