Drupal Request Flow
When you visit a Drupal-powered website and hit a page, there’s a lot happening behind the scenes before the HTML is delivered to your browser. Drupal, built on top of Symfony, follows a structured request–response lifecycle that ensures flexibility, security, and performance. Let’s walk through the journey step by step.
Everything starts when a user enters a URL in the browser. The request lands on index.php
, the front controller of Drupal. From here, Drupal initializes the Drupal Kernel, which bootstraps the system. During this bootstrap process, Drupal loads the configuration from settings.php
, builds the service container (Dependency Injection), and prepares core systems like logging, caching, and database connections.
Next, the routing system comes into play. Using Symfony’s Routing component, Drupal matches the incoming URL against the routes defined in *.routing.yml
files across modules. Each route specifies a path, permissions, and the controller responsible for handling the request. Once a match is found, Drupal executes the corresponding controller method.
The controller acts as the brain of the request. It fetches the required data—whether from entities, APIs, or business logic—and passes it forward. But Drupal doesn’t return raw data. Instead, the controller usually builds a render array, which is Drupal’s structured way of describing what should be displayed. Render arrays then move through the Render API pipeline, where caching layers are applied (page cache, render cache, and dynamic placeholders).
At the final stage, the render array is handed over to Twig, Drupal’s templating engine. Twig takes the data and transforms it into HTML. Before sending the response, Drupal ensures that performance optimizations like caching, placeholders, and lazy builders are properly handled. Finally, a Response object is returned to the browser, and the user sees a fully rendered page.
To summarize, the Drupal request flow looks like this:
Request hits
index.php
.Drupal Kernel bootstraps configuration and services.
Routing system matches URL to a route.
Controller executes logic and returns render arrays.
Render API processes arrays, applies caching, and calls Twig.
Twig generates HTML.
Drupal sends the response back to the browser.
This structured flow allows Drupal to provide a balance of flexibility (custom controllers, routes, modules) and performance (caching, lazy loading). Whether it’s a simple page or a complex API response, every request in Drupal follows this consistent and powerful lifecycle.