Topic hub
Request Lifecycle in Web Frameworks
What happens between the socket and the response in Laravel, Symfony, Django, Flask, FastAPI, Express, NestJS, Next.js, Spring and the browser: middleware, routing, guards, filters, error handling and post-response work, with interview questions and a quiz.
Lessons
- The Anatomy of a Request · Request Lifecycle: How Web Frameworks Handle a Request
Why users saw 504 errors while the application logged every request as successful, and how to align timeouts across load balancer, web server, app server and framework. - PHP-FPM and the Shared-Nothing Model · Request Lifecycle: How Web Frameworks Handle a Request
Why a PHP site returned 502 errors while CPU sat at 30%, how PHP-FPM workers serve requests, and what 'shared nothing' means for state between requests. - WSGI, ASGI and the Event Loop · Request Lifecycle: How Web Frameworks Handle a Request
Why one slow endpoint made every endpoint slow in an async service, and how WSGI workers, ASGI event loops and Node.js serve many requests at once. - Laravel Octane and Long-Running Workers · Request Lifecycle: How Web Frameworks Handle a Request
Why, after switching to Octane, a user briefly saw another customer's name, and which kinds of state leak between requests when the application stays in memory. - The Laravel Request Lifecycle · Request Lifecycle: How Web Frameworks Handle a Request
Why even the health-check endpoint took 120 ms, and how Laravel's bootstrap, service providers, middleware and terminate phase fit together. - Symfony's HttpKernel and Kernel Events · Request Lifecycle: How Web Frameworks Handle a Request
Why a maintenance-mode listener redirected visitors to the login page instead of showing a maintenance notice, and how Symfony's kernel events and listener priorities decide what runs first. - The Django Request Lifecycle and Middleware Order · Request Lifecycle: How Web Frameworks Handle a Request
Why an audit log recorded every action as 'anonymous', and how the order of MIDDLEWARE decides what each middleware can see. - FastAPI and Starlette: Middleware, Exceptions and Dependencies · Request Lifecycle: How Web Frameworks Handle a Request
Why an auth middleware that raised HTTPException(401) returned 500 errors, and how Starlette's middleware stack, exception handling and FastAPI dependencies are layered. - Flask: Contexts, Hooks and Teardown · Request Lifecycle: How Web Frameworks Handle a Request
Why a Flask app ran out of database connections after adding a header hook, and when before_request, after_request and teardown functions run. - Express: The Middleware Stack and Error Handling · Request Lifecycle: How Web Frameworks Handle a Request
Why requests to one endpoint hung until the client timed out, and how Express decides which middleware and error handlers run. - NestJS: Middleware, Guards, Interceptors, Pipes and Filters · Request Lifecycle: How Web Frameworks Handle a Request
Why mobile users got 403 errors from an ownership guard after a validation pipe was added, and the fixed order in which NestJS runs each part of its request pipeline. - Next.js: Proxy (Middleware), Rendering and Caching · Request Lifecycle: How Web Frameworks Handle a Request
Why a Next.js app made 40 session-API calls per page view, and what runs on each request: the proxy, route matching, server components, client components and caches. - The Browser Side: React and Vue Page Loads · Request Lifecycle: How Web Frameworks Handle a Request
Why a dashboard took four seconds to show data despite fast APIs, and what happens in the browser between navigation, rendering, hydration and data fetching in React and Vue apps. - Choosing the Right Layer for Cross-Cutting Concerns · Request Lifecycle: How Web Frameworks Handle a Request
Why one forgotten permission check exposed every customer's invoices, and how to place authentication, authorisation, validation, logging and transactions in the right layer of any framework. - Spring Boot: Filters, DispatcherServlet and Interceptors · Request Lifecycle: How Web Frameworks Handle a Request
Why expired tokens returned Spring Boot's default error JSON instead of the API's error format, and how a request moves through servlet filters, the DispatcherServlet, interceptors and controller advice.
Cookbook recipes
- Add JWT authentication to an Express API · Node.js
- Add request IDs and structured logs to FastAPI · FastAPI
- Protect routes in the Next.js App Router · Next.js
- Offload CPU-heavy work with worker threads · Node.js
Interview questions
Request Lifecycle in Web Frameworks interview questions and answers →