NestJS Senior interview questions and answers
75 questions for a NestJS (Senior) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.How does Nest know what to inject into
constructor(private users: UsersService)? - 2.Why can a bundler or compiler without decorator metadata support break a Nest app?
- 3.How is the DI container organized across modules?
- 4.A REQUEST-scoped provider is injected into a singleton service. What happens?
- 5.What are durable providers for?
- 6.How do you inject the current request into a provider, and what does it cost?
- 7.How can you discover all providers with a custom decorator at startup, e.g. to register event handlers automatically?
- 8.How does
ConfigurableModuleBuilderhelp when writing a reusable dynamic module? - 9.Why can
forwardRefhide a design problem even when it fixes the error? - 10.Why might an injected value be
undefinedinside a constructor but defined later, with circular dependencies? - 11.Where does Nest's overhead usually matter, and where doesn't it?
- 12.Why can
class-transformerserialization become a bottleneck for large responses? - 13.How do you reduce cold-start time of a Nest app on serverless platforms?
- 14.Why is SWC often used in Nest development?
- 15.In Nest microservices over Kafka, what must handlers be prepared for?
- 16.Why can request-response (
client.send) between microservices be risky at scale? - 17.How do you get reliable event publishing from a Nest service that also writes to the database?
- 18.What does the gRPC transport in Nest rely on?
- 19.How do you propagate a trace or correlation ID across Nest microservices?
- 20.How would you structure a large Nest codebase to keep boundaries clear?
- 21.What does hexagonal (ports and adapters) architecture look like in Nest?
- 22.When does
@nestjs/cqrspay off? - 23.How do you keep transactions consistent across several services in one request without passing a transaction object everywhere?
- 24.How would you implement multi-tenancy with a database per tenant in Nest?
- 25.What's a risk of putting authorization logic only in guards?
- 26.Why is it useful to have the same validation and authorization for HTTP, GraphQL and message handlers?
- 27.How should a Nest app shut down in Kubernetes to avoid dropped requests?
- 28.What should a readiness check in Nest verify, and what should liveness avoid?
- 29.How do you make outbound HTTP calls from Nest resilient?
- 30.What problem can a global
@Croncause in a scaled Nest deployment, and how do you solve it? - 31.How should BullMQ workers in Nest be deployed under load?
- 32.Why should errors in event handlers (
@OnEvent) be handled carefully? - 33.How do you add distributed tracing to a Nest app?
- 34.How do you make Nest's logs structured and correlated?
- 35.How can you test a module that uses a request-scoped provider?
- 36.What's a good strategy for testing a Nest app's database layer in CI?
- 37.How do you test that guards, pipes and filters are wired correctly for a route?
- 38.How do you protect a Nest GraphQL API from very expensive queries?
- 39.Why must DataLoader instances be created per request in a Nest GraphQL app?
- 40.What does Apollo Federation (supported by Nest's GraphQL module) allow?
- 41.Which settings make a Nest API safer by default?
- 42.How do you prevent mass assignment when updating entities in Nest?
- 43.Why should secrets not be logged by Nest's default exception or request logging?
- 44.How do you safely handle file uploads at scale in Nest?
- 45.What's a sensible approach to upgrading a large Nest app to a new major version?
- 46.Why might a team choose Nest over a minimal framework like Fastify alone?
- 47.How can you share DTOs and validation between a Nest backend and a TypeScript front end?
- 48.What's a concern with exposing Swagger UI in production?
- 49.How can one interceptor implement idempotency keys for POST endpoints?
- 50.How would you implement response caching that varies by user in Nest?
- 51.How can you implement API versioning without duplicating whole controllers?
- 52.What's a pitfall of
@Res()withoutpassthroughin interceptors and filters? - 53.How do you stream a large file download in Nest without loading it into memory?
- 54.What's the difference between
onModuleInitandonApplicationBootstrap? - 55.Why do lifecycle hooks not run for request-scoped or transient providers in the usual way?
- 56.What happens to global enhancers in a hybrid app's microservice part by default?
- 57.How do you write a guard that works for HTTP and GraphQL?
- 58.What's the effect of throwing inside an interceptor's
mapoperator? - 59.Why should long CPU-bound work not run in a Nest request handler?
- 60.How can you enforce module boundaries automatically in a Nest monorepo?
- 61.Why is it a good idea to separate the Nest app bootstrap (
main.ts) from app configuration (e.g. aconfigureApp(app)function)? - 62.How can Nest's
ValidationPipeerrors be made more useful to API clients? - 63.What does
app.useGlobalInterceptors()NOT give you compared toAPP_INTERCEPTOR? - 64.How would you implement soft-delete filtering globally with TypeORM in Nest?
- 65.Why can
@nestjs/event-emitterhandlers run before the database transaction commits? - 66.What does
onApplicationShutdown(signal)receive and why is it useful? - 67.How do you limit the impact of a slow downstream service on a Nest API's thread of execution?
- 68.Why should controller tests not be the only tests for authorization rules?
- 69.What does
useMocker()on a testing module builder help with? - 70.How can Nest consume messages from a broker it has no built-in transport for, like AWS SQS?
- 71.Why should domain services throw domain errors rather than
HttpExceptions? - 72.How do you rate limit per authenticated user instead of per IP with
@nestjs/throttler? - 73.How do you broadcast WebSocket messages across several Nest instances?
- 74.What is a Backend for Frontend (BFF) and how might Nest implement it?
- 75.Why may a global
ClassSerializerInterceptornot hide fields when you return results from Prisma?