# Interview Questions & Tips — Fastify: Building High-Performance Node.js APIs

Source: https://www.skillbyai.com/en/fastify/ff-interview-questions

> Practise common Fastify interview questions on performance, plugins and async handling.

Quick check

**Quiz:** Why is Fastify faster than Express?

- [ ] It uses a different programming language
- [x] 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

**Quiz:** What is the purpose of Fastify plugins?

- [ ] To add CSS styling to routes
- [ ] To replace Express middleware
- [x] 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

**Quiz:** 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
- [x] 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

**Quiz:** Which Fastify method sends a request without a real server?

- [ ] fastify.listen()
- [ ] fastify.close()
- [x] fastify.inject()
- [ ] fastify.log()

*Answer:* fastify.inject(). inject simulates HTTP requests for fast tests.

## Final quiz 2 of 8

Final quiz

**Quiz:** What is Fastify's built-in logger?

- [ ] Winston
- [ ] Bunyan
- [ ] Morgan
- [x] Pino

*Answer:* Pino. Pino is fast structured JSON logging.

## Final quiz 3 of 8

Final quiz

**Quiz:** What does a response schema improve?

- [x] 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

**Quiz:** Which lifecycle order is correct?

- [ ] preHandler, onRequest, onSend
- [x] 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

**Quiz:** What does plugin encapsulation provide?

- [ ] Global variables
- [ ] Faster CPU
- [x] 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

**Quiz:** Which plugin handles multipart file uploads?

- [ ] @fastify/cors
- [ ] @fastify/jwt
- [ ] @fastify/helmet
- [x] @fastify/multipart

*Answer:* @fastify/multipart. It parses multipart/form-data.

## Final quiz 7 of 8

Final quiz

**Quiz:** Why keep a Fastify app stateless when scaling?

- [x] 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

**Quiz:** Which header-setting plugin adds protective HTTP headers?

- [ ] @fastify/static
- [x] @fastify/helmet
- [ ] @fastify/multipart
- [ ] @fastify/jwt

*Answer:* @fastify/helmet. Helmet sets common security headers.
