Web Framework Internals interview question · Most asked
Walk through the Laravel request lifecycle and say where you would add code that must run on every request.
Summary
public/index.php loads the autoloader and app; the HTTP kernel bootstraps (environment, configuration, error handling, facades) and registers then boots all service providers; global middleware runs; the router matches a route and applies its middleware group and route middleware; the controller runs; the response passes back through middleware in reverse and is sent; terminable middleware runs afterwards. Code for every request goes in global middleware; wiring goes in service providers, kept cheap.
Longer Answer
Under PHP-FPM, providers boot on every request, so queries or HTTP calls in boot() slow down everything; under Octane they boot once per worker, so request data must not be captured in singletons.
Key Points
- Bootstrap → providers register/boot → middleware → router → controller.
- Response back through middleware, then terminate.
- Every-request code in global middleware.
- Keep providers cheap.
Explanation
What interviewers look for
Correct order and awareness of provider cost.
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.
- Where should authentication, authorisation, validation and error formatting live in a web framework?
- What is the middleware 'onion' model?