Three solutions to reduce the load for an online store on Magento 2

31 January 2023

next article
Slava Nahnybida


Slava Nahnybida
Three solutions to reduce the load for an online store on Magento 2

What does every online store need, besides products for sale, attractive design and convenient management tools? Of course, visitors, for whom this site was created. After all, everyone who visits your Internet site is a potential buyer. Therefore, the greater their number, the higher the chances of getting new customers and increasing profits. That is why the owners of online stores are so fond of various marketing moves: seasonal or thematic discounts, events, advertising mailings, etc. However, in the pursuit of more leads, one of the main features of the site is often forgotten — performance, and one of the main problems - peak loads. If you choose Magento 2 and an experienced development team like Avivi, the chances of your site not being able to withstand the load are drastically reduced. But different methods need to be used to counteract peak loads, so today we will talk about three implemented projects where these tasks were prioritized.

What is a critical load and when to expect it?

Each site is designed for a certain limit of requests from external users, which it is able to process in a certain period of time. To a large extent, this ability depends on the server on which the resource is hosted, but right now we will not delve into this issue and assume that we have the best possible server. Therefore, the next in line of responsibility for us is the CMS system. Magento 2 has a number of advantages over its predecessor Magento 1: deep changes in the architecture allow it to withstand significant loads, which is especially valuable for creating online stores. However, the CMS itself is not all-powerful, so without proper configuration or implementation of solutions, there will inevitably come a time when the number of visits to the site exceeds the system's capabilities. What then? The website becomes unresponsive and temporarily unavailable to visitors until the developers restore its functionality. Needless to say, at the time of important events and active sales, this is the worst that can happen economically.

Most often, this happens during increased marketing activity: before the holidays, on "Black Friday" or Christmas, when people start looking for gifts en masse — these are seasonal peak loads. Spontaneous surges are also possible, when the offered product suddenly gains demand due to events in the world: for example, antiseptics at the beginning of a pandemic. By the way, with the spread of Civid-19, the overall load on websites in the world has increased significantly, as lockdowns have increased the share of virtual user activity. Another factor in the load growth can be a DoS attack, but this is already a targeted unfriendly influence that aims to harm the site and almost always achieves its goal. Therefore, for now, we are only talking about organic loads, which any online store that wants to make more money needs to be ready for.

Solutions for complex individual settings

The first one our team can name is a solution based on subtle custom settings of the system almost without the involvement of third-party programs. This can actually be effective if your site develops smoothly and regularly. In this case, Magento 2 will provide you with reliable countermeasures against peak loads, provided that the system components are used correctly. To determine performance and find bottlenecks, developers use Apache JMeter™, a cross-platform, open-source software that simulates peak loads. Usually, a set of test scenarios includes:

  • Viewing the main page;

  • Product search by text;

  • Adding the product to the cart;

  • Placing an order;

  • User registration.

If necessary, developers can simulate any necessary conditions. It should be noted that in a real situation, users do not make requests to the site continuously. Testing tools also take this into account, so HTTP(S) Test Script Recorder applies a time delay to make the test conditions as close to reality as possible.

Based on the results of testing, it is almost always possible to find weak points of the site on Magento 2, but our team always conducts an additional manual check. We know from experience that the database is always a vulnerable part, although automated testing may not detect problems in this section. On several occasions, we have suggested that customers counter loads by addressing data caching issues. Instead of the standard Magento 2 Full Page Cache, we recommend the Varmish Cache tool. This software is installed before the site and checks for a cached copy of the desired page for the user. If it is, the request is not forwarded to Magento 2, which reduces the overall load.

Next, Avivi specialists check the operation of Magento 2 modules, especially if they are not products from the marketplace, but custom solutions from other developers. But in any case, remember: an additional module always affects performance, and "more expensive" does not mean "better". So if you've already spent, say, several thousand dollars on an add-on, that doesn't guarantee that this default software won't overload the system.

One of the last important steps is to check the redirects. Each of them is an additional request to the server. So even 1 redirect on the site actually doubles the number of requests from 1 user.

A solution using Redis

If you are the owner of a large online store that has created an extensive catalog, or several sites on the same platform, simple settings will not be enough. The main reason for possible site failures due to overload lies in the standard Zend_Cache_Backend_File of the Magento 2 system. Such a file may well grow to 15 million records in 1 day, which is already a significant size, which can cause problems with MySQL. Another problem is the TwoLevels backend, which uses two servers at the same time and causes additional load. Therefore, Avivi specialists implemented a project to replace Zend_Cache_Backend_File with Redis technology.

The solution can reduce the use of resources by several times. Redis can be used as a store for PHP sessions, which eliminates the use of memcached, which always has certain limitations. In addition, the solution indexes file tags, so an additional scan of all cached files is not required. Also, Redis stores metadata and cache records in one file, which reduces the number of operations for their verification.

Therefore, the correct settings of Redis for Magento 2 significantly reduce the load on the platform and allow you to develop several online stores at once without fear. The solution works stably, but its installation and configuration requires the work of experienced specialists. Therefore, if you need integration with Redis, you can contact Avivi developers.

A solution using RabbitMQ

Another method of overcoming peak loads can be to organize the queue of requests from users. The principle is simple: if a large number of visitors access the site at the same time, it causes a surge in activity. But if you develop rules according to which visitors line up to your online store in a distributed queue, the system will know the volume of requests and will not accept more than it can simultaneously. Here it is worth understanding that a person will not feel the difference when he is in the queue at the first place or at 1101 — we are talking about fractions of a second. However, for the system, such an arrangement will be practically a vicious circle.

Avivi developers have dealt with the RabbitMQ platform even earlier and in projects with another CMS. Then the solution became effective for international goods delivery service. Therefore, when a similar need arose for an online store on Magento 2, we turned to the proven tool without hesitation.

RabbitMQ acts as a queue manager and provides asynchronous data exchange. These can be elements of the same system or completely different ones. To save data, queues are formed, which the system can access at any stage. This ensures the preservation of information in the event of an unexpected failure of elements, and provides an opportunity to calculate the resources needed to perform the operation.

Integrating Magento 2 and RabbitMQ requires much less effort than most other third-party applications. You can control the formation of streams using the Management plugin. By the way, RabbitMQ can be installed on the same server as Magento 2, or on any other server.

In conclusion, we would like to say that it is necessary to counteract peak loads on the site, especially if it is an online store, in advance, so that at a crucial moment the failure of the system does not become an unpleasant surprise for you. Avivi specialists have experience in implementing various solutions, so we are always ready to help your business grow and get more and more customers.

Similar articles
Apply for a consultation

We will reach out to within 10 minutes