
Best practices for optimal infrastructure performance with Magento
Authored by Platform.sh Magento specialists, Stephanie Daugherty and Jared Wright.
Magento is a powerful eCommerce platform that drives thousands of online stores worldwide. Its flexible, scalable, and feature-rich environment makes it a top choice for retailers across diverse industries.
However, Magento’s extensive feature set and complexity can create performance bottlenecks—especially as businesses scale. Growing product catalogs, high traffic volumes, and intricate checkout processes can strain site performance, leading to slower load times and reduced conversion rates.
By following key best practices, developers, site administrators, and eCommerce architects can ensure their Magento stores scale efficiently—delivering both high performance and a seamless user experience.
This article explores the recently relaunched Magento 2 Community Edition template on Platform.sh, highlighting the built-in optimizations. These enhancements incorporate Magento’s best practices alongside our deep experience in hosting and scaling the platform.
The latest Magento optimizations for maximum efficiency
Let’s start with the composer.json file from this repo. This file provides the building blocks of the application. We’ve included the following to make life easier for your development team:
"magento/ece-tools": "^2002",
"fastly/magento2": "*",
"markshust/magento2-module-disabletwofactorauth": "*",
"n98/magerun2-dist": "*"
These packages enhance the Magento experience on Platform.sh
Ece-tools simplifies building and deploying on Platform.sh. Ece-tools can detect that the build and deployment target is Platform.sh, then adjust the application configuration accordingly using environmental variables we provide.
We also include the Fastly module, our CDN of choice. This module disables two-factor authentication (necessary because development environments aren’t always able to send verified mail) and the;
n98 magerun tool which can be called from within your application using:
vendor/bin/n98-magerun2
The composer file also uses the mirror https://mage-os.org/distribution/
Using the https://repo.magento.com/ mirror requires authentication. If you wish to use it, just follow the instructions in the repository.
The next important step file in the repository is `.magento.env.yaml`
This file is the heart of the application Magento configuration and contains a lot of small performance and stability enhancements.
In our configuration, for caching alone, we’ve added multiple performance enhancements, a separate Redis Session service, L2 Caching, and Stale Cache, and Preloading of certain cache keys—all now enabled by default.
We adjusted the cron and consumers to process only 250 messages at a time. Ensuring all consumer crons run, but do not run indefinitely. You can adjust crons and increase this value on larger plans.
The static content deployment (SCD) is set to the quickest and shortest deployment times possible with Magento using `compact` SCD strategy. If you add or remove modules, make sure to use the below snippet to push the correct state:
`vendor/bin/ece-tools config:dump`
Our .platform/service.yaml file has been updated with new services to support the latest version of Magento. It also has two MariaDB tweaks, which help with long running indexing processes:
optimizer_switch: "rowid_filter=off"
optimizer_use_condition_selectivity: 1
Last—but definitely not least—is the .platform.app.yaml
We’ve added additional read and write endpoints for the database service. And if you deploy the template on a highly available cluster, the multiple endpoints will be available for redis, too.
- The build hook installs nvm and node, just in case you use a PWA within your build and/or MagePack. It then uses the ece-tools process to build and complete SCD.
- The last line of the build is a small change; it ensures all crons delivered to the application are set to run sequentially, not in parallel. If you have ample resources, you can choose to remove this line.
- Ece-tools handles the deployment and post-deployment processes, detecting and updating necessary configurations and application upgrades.
- The cron section has been updated to handle the sequential cron process. Now, there’s a cleanup process for the reports folder and a 10-day log rotation for application logs.
Locations are the standard for the Magento application, with the addition of examples for an Apple Pay pass-through. We often see Apple Pay domain verification as a merchant requirement.
Three essential Magento best practices for peak performance
Along with the template and the best configuration for the application, we recommend these best practices when using Magento.
1. Use Content Delivery Networks (CDNs)
A CDN like Fastly can offload traffic and reduce Time to First Byte (TTFB) globally. By leveraging CDNs, you can improve page load speeds by up to 60%, as shown in real-world implementations.
CDN recommendations:
- Reduce automated flushes: Check Fastly for excessive cache flushes—automated flushes triggered by misconfigured modules can defeat caching entirely.
- Leverage key Fastly features: Platform.sh includes additional Fastly features to enhance performance:
- Full page cache for Fastly CDN: All operations act on the CDN exactly as if performed on your infrastructure instances.
- Fastly Image Optimizer (Fastly IO): Use this to offload image transformation to the Fastly cloud, reducing latency and improving initial content delivery speed to your end users. Fastly IO is included with your Fastly service; you can enable it from your Adobe Commerce admin panel. For full details, please see the Adobe Commerce Cloud documentation.
- You only need to keep a single high-resolution copy of each image on the server. Fastly provides an appropriately sized image for thumbnails and slow or low-resolution devices. It works on common image formats like .png, .jpeg, and .gif.
- The Fastly Image Optimization snippet consists of VCL code to perform image optimization on the Fastly edge nodes.
- Two-stage cache: Replies are cached both close to the customer and close to your Adobe Commerce server.
- Force TLS: When enabled, this setting redirects all HTTP requests to HTTPS.
- Edge Access Control Lists (ACLs): This can manage IP addresses that are used to allow or block access to resources.
- Error/Maintenance page: With this feature, set up a custom 503 page with your branding.
- Basic authentication: You can toggle HTTP basic authentication to restrict access to a website.
- Geo-IP: You can redirect visitors to the storefront based on their country code or restrict access for countries where you don’t do business.
2. Ensure server-side optimization
Exploring key integrations and toggling the right settings can drastically improve the performance of your Magento store.
Server-side optimization recommendations:
- Set memory limits: Set appropriate
php.ini
memory limits for server stability. For most environments, 512MB or 1GB is sufficient. Excessive limits (e.g., 4GB) may indicate underlying performance issues and should prompt further investigation. - Proper error recovery: Restart Nginx and PHP processes after significant fixes or changes to remove orphaned workers and ensure efficient resource utilization. End users can do this via runsv, systemctl, or pkill.
- To keep admin backend pages from timing out, Magento typically gets configured with max_execution_time of at least 600s (10 minutes). But when things break down, you end up with orphaned PHP workers trying to return requests to clients that have already given up on receiving those requests—or worse, to clients that have already refreshed the page. That’s why this is critical to speed up recovery after a service failure.
- PHP and web server configuration: Optimize PHP-FPM settings to ensure you don’t run out of memory for your PHP workers.
- Database tuning: Explore MySQL or MariaDB performance optimization strategies such as database indexing, query caching, and using read-write separation in multi-server environments. Regularly analyze and optimize slow queries using tools like
mysqlslowdump
to prevent outages caused by poorly performing queries.
- Run Mysqlanalyze often—at least after every service and application upgrade, but ideally on a regular schedule.
- Ensure that tables are optimized during maintenance windows. This can release disk space and help improve performance.
3. Leverage performance monitoring and profiling tools
Performance optimization isn’t a one-time initiative—it’s an ongoing process. Continuous monitoring and testing are essential to maintaining stability.
Monitoring and profiling recommendations:
- Blackfire: Use tools like Blackfire to monitor and profile Magento’s request-response cycle, identifying areas of improvement.
- Magento Profiler: Utilize Magento’s built-in profiler to measure database query execution time, block rendering time, and memory consumption.
- Continuous load testing: Implement load-testing frameworks such as Apache JMeter and Gatling to simulate high-traffic scenarios and benchmark system performance under stress.
- Modules: When facing a performance problem, can you reproduce the problem with only core modules? If not, it's the modules.
By following these best practices and configuring your Magento store correctly, you create a foundation for seamless scalability. With the right optimizations in place, you can focus on growing your business instead of troubleshooting platform issues.
Have questions about optimizing your Magento site on Platform.sh? Reach out—we’re here to help.
Ready to future-proof your Magento store?
Experience effortless scaling, built-in performance optimizations, and streamlined workflows with Platform.sh. See how we simplify Magento hosting.