Web Framework Internals interview question · Most asked
What is the NestJS request lifecycle?
Summary
Middleware → guards → interceptors (before) → pipes → controller handler (and services) → interceptors (after) → response; exception filters handle errors thrown at any stage. Within each kind, global ones run before controller-level and route-level ones (pipes also apply per parameter).
Longer Answer
Because guards run before pipes, a guard sees the raw request, not the validated and transformed DTO. Use guards for identity and coarse permissions and do resource-level checks after validation.
Key Points
- Middleware, guards, interceptors, pipes, handler.
- Interceptors wrap the handler (before and after).
- Exception filters catch errors from any stage.
- Guards see raw input.
Deep dive: Request Lifecycle: NestJS: Middleware, Guards, Interceptors, Pipes and Filters
Explanation
What interviewers look for
Exact order and the guard-before-pipe implication.
More most-asked Web Framework Internals questions
- Where should authentication, authorisation, validation and error formatting live in a web framework?
- How does Express handle a request, and how are errors routed?
- Describe the Spring MVC request flow and where exceptions are handled.
- What is a request lifecycle, and why should a backend engineer know it for their framework?
- Walk through the Laravel request lifecycle and say where you would add code that must run on every request.
- What layers does a request pass through before reaching application code, and how should their timeouts relate?
- Walk through the Django request lifecycle.
- What happens in the browser from navigation to an interactive single-page app?