Skip to main content

Request Flow in Magento 2

By |August 21, 2015 February 10th, 2022No Comments

Have your eCommerce website built in Magento platform by opting our Magento 2 development services.

There is a lot of buzz around Magento 2 and about its new features that promises to improve user experience and performance.One of the key changes made is in the request flow (i.e.) the path taken by the system from the time an user clicks a page to the time it is served as a page in the front end.

In Magento 1, both the front end and back end configuration files will be loaded for each request. But in Magento 2, only the related configuration files of that area will be loaded.

E.g. in Magento 1.x, if you click “Registration” Page in the front end, it loads the entire configuration files including the front end and the back end. But in Magento 2, it will load only the configuration file related to the front end.

This greatly improves the performance (i.e.) request-response time of the website thus enhancing the user experience.

Migrate To Magento 2

In this blog, we will discuss the request flow in Magento 2.

Step 1 :

Request hits index.php in root folder of Magento 2.

Step 1a

Step 2 :

index.php calls static create() method of bootstrap class to create objectmanagerfactory and bootstrap objects.Step 2aStep 2b

Step 3 :

index.php calls createApplication() method of bootstrap object which in turn will initiate ObjectManager using objectManagerFactory. Then, application instance gets created using objectManager and returned to index.php.

Step 3a

Step 3b

Step 3c

Step 3d

Step 4 :

index.php calls run() method of bootstrap object to run the application, which in turn will call launch() method 

of application object.

Step 4a

Step 4b

Step 4c

Step 5 :

HTTP Application instance does initial routing. It takes first part of the URL to find out which area should be loaded (admin/frontend).

When the area is defined, configuration for that area is loaded (unlike Magento 1 where all configuration was loaded).

Then application object calls MagentoFrameworkAppFrontControllerInterface::dispatch of requested area.

Step 5a

Step 5b

Step 6 :

Front Controller does routing same as in Magento 1.  All routers are iterated to match request. The router that matches the request returns instance of ActionController. When FrontController gets instance of action controller it calls dispatch method on it. This process is more efficient because only routers of one area are used (admin router is not used in frontend).

Step 6a

Step 7 :

Action controller performs its task and returns instance of some implementation of ResultInterface.

Step 7a

Step 7b

Step 8 :

FrontController just returns ResultInterface to Application Instance that renders the response.Step 8a

There is much more to Magento 2 than request flow. If you want dig deep, please find below a few useful links.


Magento 2 Useful Links
Abbas Ali

Abbas is a Magento Developer Plus Certified Associate Architect at DCKAP. He is passionate about working with Magento and PHP frameworks. Loves adventure and travelling.

More posts by Abbas Ali

Discover What You’re Missing

Get the weekly email full of actionable ideas and insights you can use at work and home.