Free course · 17 lessons · Intermediate

Request Lifecycle: How Web Frameworks Handle a Request

Follow a request from the socket to the response in the frameworks you use: the proxy and server chain, PHP-FPM, WSGI, ASGI and event loops, Laravel and Octane, Symfony's HttpKernel events, Django middleware, Flask contexts, FastAPI and Starlette, Express, NestJS, Next.js, Spring's DispatcherServlet and the browser side of React and Vue. Every lesson starts from a real production bug caused by the lifecycle, with a runnable simulation in that framework's language.

Start the course

1. Foundations: From Socket to Response

What happens to a request before your framework sees it: the chain of proxies and servers and their timeouts, PHP-FPM's shared-nothing workers, and how WSGI, ASGI and event loops serve concurrent requests.

  1. The Anatomy of 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.
  2. PHP-FPM and the Shared-Nothing Model — 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.
  3. WSGI, ASGI and the Event Loop — 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.

2. PHP Frameworks: Laravel, Octane and Symfony

How Laravel bootstraps the application, runs service providers and the middleware onion; what changes when Octane keeps the app in memory; and how Symfony's HttpKernel turns a request into events.

  1. The Laravel Request Lifecycle — Why even the health-check endpoint took 120 ms, and how Laravel's bootstrap, service providers, middleware and terminate phase fit together.
  2. Laravel Octane and Long-Running Workers — 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.
  3. Symfony's HttpKernel and Kernel Events — 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.

3. Python Frameworks: Django, Flask and FastAPI

How Django's middleware chain wraps views, how Flask's contexts and hooks run around a request, and how FastAPI and Starlette layer middleware, exception handling and dependencies.

  1. The Django Request Lifecycle and Middleware Order — Why an audit log recorded every action as 'anonymous', and how the order of MIDDLEWARE decides what each middleware can see.
  2. Flask: Contexts, Hooks and Teardown — Why a Flask app ran out of database connections after adding a header hook, and when before_request, after_request and teardown functions run.
  3. FastAPI and Starlette: Middleware, Exceptions and Dependencies — Why an auth middleware that raised HTTPException(401) returned 500 errors, and how Starlette's middleware stack, exception handling and FastAPI dependencies are layered.

4. JavaScript Frameworks: Express, NestJS and Next.js

How Express runs its middleware stack and error handlers, the fixed order of NestJS middleware, guards, interceptors, pipes and filters, and what runs where when a request hits a Next.js app.

  1. Express: The Middleware Stack and Error Handling — Why requests to one endpoint hung until the client timed out, and how Express decides which middleware and error handlers run.
  2. NestJS: Middleware, Guards, Interceptors, Pipes and Filters — 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.
  3. Next.js: Proxy (Middleware), Rendering and Caching — 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.

5. Spring, the Browser Side, and Putting It Together

Spring MVC's filter chain and DispatcherServlet, the lifecycle of a page load in React and Vue, and how to choose the right layer for cross-cutting concerns in any framework.

  1. Spring Boot: Filters, DispatcherServlet and Interceptors — 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.
  2. The Browser Side: React and Vue Page Loads — 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.
  3. Choosing the Right Layer for Cross-Cutting Concerns — 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.

6. Capstone Case Studies

Trace and redesign real request pipelines end to end.

  1. Capstone: Trace a Slow Request Through Every Layer — A Laravel checkout behind a load balancer, nginx and PHP-FPM has a p99 of 6 seconds. Find where the time goes, layer by layer, and fix it.
  2. Capstone: One API Standard Across Many Frameworks — A company runs Laravel, Django, NestJS and Spring Boot services. Design how each one enforces the same request IDs, authentication, error format and timeouts using its own request pipeline.