Web Framework Internals interview question · Most asked
Where should authentication, authorisation, validation and error formatting live in a web framework?
Summary
Authentication in the pipeline layer that runs for every request (middleware, firewall, guard, filter, dependency); coarse authorisation in route-level middleware, guards or dependencies with default-deny; resource-level authorisation near the data (services, policies, query scopes); validation at the input boundary (Form Requests, serializers, Pydantic models, pipes, @Valid); error formatting in one global handler (exception handler, kernel.exception, exception filters, @ControllerAdvice).
Longer Answer
Putting checks inside each controller by hand makes them opt-in, and one forgotten endpoint becomes a data leak. A route-inventory test that fails when a route has no authorisation rule enforces default-deny.
Key Points
- Authentication in the global pipeline.
- Default-deny coarse authorisation.
- Resource checks near the data.
- One global error formatter.
Deep dive: Request Lifecycle: Choosing the Right Layer for Cross-Cutting Concerns
Explanation
What interviewers look for
Layer-appropriate placement and the default-deny principle.
More most-asked Web Framework Internals questions
- What is a request lifecycle, and why should a backend engineer know it for their framework?
- What layers does a request pass through before reaching application code, and how should their timeouts relate?
- Walk through the Django request lifecycle.
- How does Express handle a request, and how are errors routed?
- What is the NestJS request lifecycle?
- Describe the Spring MVC request flow and where exceptions are handled.
- Walk through the Laravel request lifecycle and say where you would add code that must run on every request.
- What is the middleware 'onion' model?