These Fastify interview questions are for hiring managers and backend leads building a technical round for Node.js developers who work with Fastify, and for developers checking their knowledge before an interview. Each question explains what a strong answer covers, with red flags where candidates often slip. The questions accept answers in Fastify v4 or v5 terms, and a few cover the v5 upgrade directly. Pick 6 to 8 that match your stack. For the runtime itself, use our Node.js interview questions as well.
What a strong Fastify interview checks
- The plugin model: how register, encapsulation and fastify-plugin decide what each part of the app can see.
- The request lifecycle: which hook runs when, and where auth, parsing and logging belong.
- Schemas: JSON Schema used for validation and for fast, safe serialization.
- Errors and async code: one clear way to reply, and errors handled at the right level.
- Testing and operations: inject-based tests, logging with Pino and graceful shutdown.
- Current versions: what changed in Fastify v5.
Fastify interview questions: plugins and encapsulation
1. What is a Fastify plugin, and what does register do?
What good looks like: in Fastify almost everything is a plugin, a function that receives a Fastify instance and options. fastify.register(plugin, opts) loads it in order during boot, and the instance it receives is a child context. Routes, hooks and decorators added inside belong to that context. A strong candidate mentions that registration is asynchronous and finishes when ready() or listen() resolves.
Red flag: "register is just Fastify's name for middleware."
2. Explain encapsulation. Why can't a sibling plugin see my decorator?
What good looks like: each register call creates a new context that inherits from its parent but doesn't leak upward or sideways. A decorator, hook or error handler added in one plugin is visible to that plugin and its children only. This lets teams build isolated parts of an app, such as a public API and an admin API with different auth hooks, in the same server.
3. When do you wrap a plugin with fastify-plugin?
What good looks like: when the plugin should add something to the parent context, such as a database client decorator or a shared auth hook that every route needs. fastify-plugin skips encapsulation for that plugin. A strong answer adds that it can also declare the Fastify version and plugin dependencies it expects.
Red flag: wrapping every plugin with fastify-plugin "so things work", which throws away encapsulation.
4. What are decorators, and what is the catch with decorateRequest?
What good looks like: decorate, decorateRequest and decorateReply add properties to the instance, the request or the reply. They keep object shapes stable, which helps V8 performance. The catch: request decorators shouldn't be given a shared object or array as the starting value, because every request would share it. Start with null and set the value in a hook, or use a getter.
5. How do you split a large app into plugins?
What good looks like: shared infrastructure (config, database, auth) as fastify-plugin wrapped plugins registered first, then feature plugins registered with a prefix, such as /users and /billing. Many teams use @fastify/autoload to load a folder of plugins and routes. Good candidates talk about boot order and keeping features isolated.
Fastify interview questions: hooks and the request lifecycle
6. Walk through the request lifecycle hooks in order.
What good looks like: onRequest, preParsing, preValidation, preHandler, then the handler, then preSerialization, onSend and onResponse. onError runs when an error is thrown, and onTimeout and onRequestAbort cover slow and dropped requests. A strong candidate knows the body isn't parsed yet in onRequest.
Red flag: reading request.body inside onRequest and being surprised it's undefined.
7. Where should authentication run, and why?
What good looks like: usually onRequest, so an unauthenticated request is rejected before Fastify spends time parsing and validating the body. If auth depends on the body, preValidation or preHandler works. Registering the hook inside an encapsulated plugin protects only that plugin's routes, which is the point.
8. What is the difference between an application hook and a route-level hook?
What good looks like: addHook applies to every route in the current context and its children. A route can also set its own hooks, such as preHandler in the route options, for logic only that route needs. Application hooks like onReady and onClose run at startup and shutdown, not per request.
Fastify interview questions: schemas, validation and serialization
9. How does Fastify validate requests?
What good looks like: routes declare JSON Schema for body, querystring, params and headers. Fastify compiles them with Ajv at startup and rejects invalid requests with a 400 before the handler runs. A strong answer mentions that schemas also coerce types, such as turning a query string "5" into the number 5 when the schema says integer.
10. Why define a response schema?
What good looks like: two reasons. Fastify uses it to serialize output with fast-json-stringify, which is faster than JSON.stringify. And it only sends the properties the schema lists, so a stray field such as passwordHash on a user object is dropped instead of leaked.
Red flag: "Response schemas are only documentation."
11. How do you share schemas across routes?
What good looks like: addSchema with an $id, then reference it with $ref, for example a shared user or error schema. Candidates who use TypeScript often mention TypeBox or json-schema-to-ts with a type provider, so one schema gives both runtime validation and static types.
12. A route accepts any body even though it has a schema. What do you check?
What good looks like: whether the schema is attached in the right place in the route options, whether the content type is one Fastify parses, whether additionalProperties is allowed, and whether a custom validator compiler was set. In Fastify v5, shorthand schemas that skip type: 'object' and properties are no longer accepted, which is a common upgrade surprise.
Fastify interview questions: errors, async code and testing
13. Should a handler return a value or call reply.send?
What good looks like: pick one. In an async handler, returning the value is the clean pattern. Calling reply.send and also returning a value can send twice or log errors. If an async handler calls reply.send, it should return the reply object so Fastify knows the reply is handled.
14. How does error handling work, and how is it scoped?
What good looks like: a thrown error or rejected promise goes to the error handler. setErrorHandler is encapsulated like everything else, so a plugin can format its own errors. Errors with a statusCode (for example from @fastify/sensible or a custom error class) keep that status, and validation errors arrive with a validation property. setNotFoundHandler covers unknown routes.
15. How do you test a Fastify app without opening a port?
What good looks like: build the app in a function that returns the instance, then call app.inject() with a method, URL and payload. It runs the full lifecycle in memory, which makes tests fast and reliable. Close the app after each test, or use a fresh instance per test.
16. How do logging and graceful shutdown work?
What good looks like: Fastify ships with Pino, and request.log adds a request ID to every line. For shutdown, catch the signal and call fastify.close(), which stops new connections, lets in-flight requests finish and runs onClose hooks so database pools close cleanly.
Fastify interview questions: versions and practical scenarios
17. What changed in Fastify v5?
What good looks like: Fastify v5 requires Node.js 20 or newer, requires full JSON Schema for request validation, and moved custom logger instances to the loggerInstance option. Strong candidates also mention running the deprecation warnings from the last v4 release before upgrading, and checking each plugin for a v5-compatible version.
18. You need to move an Express app to Fastify. How do you plan it?
What good looks like: start by mounting the existing Express app with @fastify/express so routes keep working, then move routes over one feature at a time, replacing middleware with hooks and adding schemas as each route moves. Measure before and after. Good candidates don't promise a big-bang rewrite.
19. Throughput dropped after a release. Where do you look?
What good looks like: a missing response schema (falling back to JSON.stringify), heavy work in a hook that runs on every request, synchronous code blocking the event loop, logging at debug level in production, or a slow database call. They profile with a load test, such as autocannon, and compare against the last good release.
20. Behavioral: tell me about a backend incident you fixed.
What good looks like: a specific incident, such as a memory leak, a request decorator shared across requests, or a slow endpoint. They explain the root cause, the fix and how they confirmed it, such as a test or before and after numbers.
Red flag: a vague story with no root cause, or a fix that only hid the symptom.
A simple scoring rubric
Running this interview with AI
NTRVSTA's AI interviewer runs a live first round and adapts as it goes. Node.js and JavaScript are part of its exam library, and interviews can be customized per role, so you can add the Fastify topics on this page. If a candidate explains encapsulation well, it moves on to hooks, schemas and the v5 upgrade. If they struggle, it stays with the basics and can offer a hint, so you learn whether they can take a nudge and recover.
Each candidate's report includes a score breakdown and video snippets of key moments, ready to share with the hiring manager. For context on what the scores mean, read how AI interviews are scored, and see our ranking of AI interview software. You may also want our Node.js, JavaScript and backend developer interview questions.
Questions
Is Express experience enough for a Fastify role?
It helps with routing and Node.js basics, but Fastify thinks differently. Plugins are encapsulated, request handling runs through named hooks, and JSON Schema drives both validation and output. Ask two or three questions on encapsulation and schemas to see how quickly an Express developer adjusts.
Should a Fastify interview cover Fastify v4 or v5?
Cover the version your team runs, and ask about the v5 upgrade if you are migrating. A candidate on v4 who can name the main v5 changes, such as the Node.js 20 requirement and full JSON Schema for request validation, is showing the awareness you want.
How many of these questions should a first round use?
Six to eight. Take two on plugins and encapsulation, one on hooks, two on schemas and serialization, and one each on errors and testing. Add one behavioral question at the end.
Want to watch an adaptive AI interviewer run a Fastify round? Grab a 20-minute demo slot, or try a sample interview yourself with no setup.




