Lesson 32 / 32
Interview Questions & Tips
Practise common Fastify interview questions on performance, plugins and async handling.
Quick check
Quick check: Why is Fastify faster than Express?
- It uses a different programming language
- It has lower overhead through object pooling, efficient routing, and built-in validation
- It doesn't support middleware
- It runs only in the browser
Answer
It has lower overhead through object pooling, efficient routing, and built-in validation — Fastify reuses request/reply objects, optimizes routing with a trie-based router, and validates input with JSON Schema—all designed for performance.
Quick check
Quick check: What is the purpose of Fastify plugins?
- To add CSS styling to routes
- To replace Express middleware
- To encapsulate and reuse functionality (auth, DB, logging) across routes
- To generate HTML templates only
Answer
To encapsulate and reuse functionality (auth, DB, logging) across routes — Plugins enable modular, maintainable code by separating concerns and allowing reusable components to be registered across the app.
Quick check
Quick check: How does Fastify handle async/await in route handlers?
- It wraps them in try/catch automatically
- Async handlers are not supported
- It requires manual promise chains
- It catches rejected promises and passes errors to the error handler
Answer
It catches rejected promises and passes errors to the error handler — Fastify is built on async/await and automatically catches rejected promises, routing them to the setErrorHandler.
Final quiz 1 of 8
Final quiz
Quick check: Which Fastify method sends a request without a real server?
- fastify.listen()
- fastify.close()
- fastify.inject()
- fastify.log()
Answer
fastify.inject() — inject simulates HTTP requests for fast tests.
Final quiz 2 of 8
Final quiz
Quick check: What is Fastify's built-in logger?
- Winston
- Bunyan
- Morgan
- Pino
Answer
Pino — Pino is fast structured JSON logging.
Final quiz 3 of 8
Final quiz
Quick check: What does a response schema improve?
- Serialization speed and data safety
- CSS size
- Git history
- DNS lookups
Answer
Serialization speed and data safety — Only listed fields are serialized.
Final quiz 4 of 8
Final quiz
Quick check: Which lifecycle order is correct?
- preHandler, onRequest, onSend
- onRequest, preValidation, preHandler, onSend
- onSend, onRequest
- preValidation, onRequest
Answer
onRequest, preValidation, preHandler, onSend — Hooks run in a defined sequence for each request.
Final quiz 5 of 8
Final quiz
Quick check: What does plugin encapsulation provide?
- Global variables
- Faster CPU
- Scoped decorators, hooks and routes
- Automatic HTTPS
Answer
Scoped decorators, hooks and routes — Child plugin changes do not leak to siblings.
Final quiz 6 of 8
Final quiz
Quick check: Which plugin handles multipart file uploads?
- @fastify/cors
- @fastify/jwt
- @fastify/helmet
- @fastify/multipart
Answer
@fastify/multipart — It parses multipart/form-data.
Final quiz 7 of 8
Final quiz
Quick check: Why keep a Fastify app stateless when scaling?
- Any instance can serve any request
- It uses less RAM
- It disables logging
- It avoids HTTPS
Answer
Any instance can serve any request — Shared state belongs in Redis or a database.
Final quiz 8 of 8
Final quiz
Quick check: Which header-setting plugin adds protective HTTP headers?
- @fastify/static
- @fastify/helmet
- @fastify/multipart
- @fastify/jwt
Answer
@fastify/helmet — Helmet sets common security headers.