12. 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
Show answer
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.
Lesson: Interview Questions & Tips
13. 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
Show answer
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.
Lesson: Interview Questions & Tips
14. 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
Show answer
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.
Lesson: Interview Questions & Tips
18. Which lifecycle order is correct?
- preHandler, onRequest, onSend
- onRequest, preValidation, preHandler, onSend
- onSend, onRequest
- preValidation, onRequest
Show answer
Answer: onRequest, preValidation, preHandler, onSend
Hooks run in a defined sequence for each request.
Lesson: Interview Questions & Tips