Magento is a popular choice for large businesses looking to build their own fully bespoke ecommerce platforms. Favoured for its customizability, Magento allows businesses to fully control their shopping experience and data.
It allows them to pick and choose their own integrations and payment handlers, without the limitations of off-the-shelf solutions like Shopify.
The flexibility and performance provided by AWS makes it perfect for hosting highly-customizable ecommerce platforms such as Magento.
Magento is a resource-intensive application, requiring hosting tailored to provide the best performance. Magento websites expecting high traffic must have both their code and hosting environment optimized and should be configured to scale according to demand.
This article details the best practices for hosting Magento on AWS, explaining how to make full use of the AWS services that can be used to effectively optimize and scale your website.
Magento’s many moving parts
Magento is big and it does a lot of stuff. We’re not being condescending here—it really does have a lot of moving parts and therefore, high system requirements. It has a large codebase written in PHP, which is quite resource intensive due to its structure.
Magento stores long-lived data—like products, customers and invoices—in a MySQL-compatible database. This is your vital business data and it must be stored on robust infrastructure that is regularly backed up.
For best performance, Magento requires a cache for short-lived data, such as user sessions. If you have a large product database, a full text search engine will make sure your customers can quickly and consistently find the product they are looking for.
High-quality product images drive sales, so Magento also requires a significant amount of ever-growing file storage for your product photos, thumbnails and images optimized for different screen sizes.
You will also need to set up your Magento site to send emails reliably (to ensure your customers receive all of their invoices and product offers) and also pass data on to third-party analytics partners (to improve customer engagement and inform advertising decisions).
Another important part of your Magento site is your ability to monitor and log any site errors, so that you can easily detect bugs and site slowdowns and get them fixed early. Depending on your customer’s expectations and the kind of service you are offering, you will likely have other plugins and integrations that need to be implemented on top of these.
As we said: Big. Lots of stuff.
Magento is an ecommerce platform for organizations with high expectations for future growth, who want full control over their vital business apparatus. These organizations want to see the benefits of full ownership of their data—and are willing to invest in it.
They’re willing to absorb the up-front costs to avoid having decisions on how their infrastructure behaves (and, importantly, how their earnings are processed) made for them by prefabricated ecommerce platforms.
AWS provides a full infrastructure stack that can host both Magento and the tools and services it relies on in a cost-effective, scalable manner.
Optimizing Magento on AWS to get the most out of your existing infrastructure
To make the most of your investment in your ecommerce system, you should optimize your Magento site before scaling your infrastructure. Scaling increases costs and scaling unoptimized code will usually yield minimal performance gains if your performance bottleneck is code-related, rather than being caused by a lack of resources.
Installation and PHP: Magento hosted on AWS is usually delivered from EC2 instances running PHP. Recent versions of PHP have been heavily optimized for performance in these environments, so ensuring both your Magento installation and PHP environment are up to date is the first step in squeezing the most out of your current hosting budget.
Graviton processors: AWS instances using Graviton processors—purpose-built CPUs for serving web apps as fast as possible—are also now available and should be used when hosting any PHP application.
HTTP/2: A modern update to the HTTP protocol, HTTP/2 will also provide performance gains when serving your application code. HTTP/2 ships with both the Apache2 and NGINX web servers and can be enabled with a configuration change. You should also enable compression on your Apache or NGINX web server.
Database and cache servers: If you are using Magento’s built-in cache, using an external Redis or Memcached server will give you large performance gains. Both Redis and Memcached can be configured to use more available memory, improving performance.
MySQL: Ensure that you are using the most up-to-date version of MySQL to see the best performance gains. Magento keeps a large amount of indexed data in its database to help improve performance. Regularly re-indexing your data will ensure that it is up to date and that performance is not affected.
Image optimization: You can use your storage more efficiently if you optimize your images prior to uploading them. Original, high-resolution product photos should be stored locally on your computer or office network, and only the maximum resolution image that needs to be delivered to customers should be stored online.
When serving images, configure image resizing to ensure that an appropriate image size is served—there’s no need for your users to be waiting for a billboard-sized image to load if it’s going to be displayed on their phone screen.
Website code: You should inspect your website code to identify individual pages and assets that load slowly. Keep pages simple—reduce the amount of unnecessary plugins and external content being loaded.
Unnecessary scripts: Ads and tracking scripts from multiple sources add little value and can both slow down your website and make it more difficult for your users to navigate. Profile your website and remove unnecessary scripts, and minify your scripts and stylesheets.
ElasticSearch and CDN: If your site performs well generally, but is slow to return search results, consider using ElasticSearch to offload search duties. If image-heavy product listings are slowing things down, consider implementing a CDN (content delivery network) like AWS CloudFront to speed up navigation.
Scalable Magento deployments on AWS
If your optimized Magento deployment is still struggling under load, it’s time to consider scaling your AWS hosting infrastructure. You can scale vertically by simply upping the CPU and memory specification of the instances delivering your website—no special preparation required.
However, this too will eventually reach a point of diminishing returns, or max out the available CPU and memory limits.
Horizontal scaling doesn’t suffer from these limitations and can often be more cost- effective. Scaling horizontally means adding more servers to your deployment and spreading the load across them when traffic increases. Auto Scaling groups in AWS let you adjust the number of running instances on the fly, ensuring that no capacity is wasted and costs are kept as low as possible.
The core concern when scaling horizontally and using multiple servers is that when a user makes a request to your website, subsequent requests may not be responded to by the same server.
This means that the database, caches, file storage—all of the moving pieces Magento requires that are listed above—must be abstracted away from the application code so that multiple servers are all using the same shared data sources.
Ensure your Magento store is ready to scale horizontally
To ensure your Magento store is ready to scale horizontally in AWS, host your MySQL database in an Amazon RDS managed database instance. Databases can be scaled horizontally too by storing data on multiple, synchronized databases hosted from separate servers.
RDS supports up to five database replicas, allowing for easy scaling of both the application and database. If further scaling is required, Amazon Aurora supports up to 15 database replicas.
To follow best practices, your optimized site should be using caching and implement a full-text search engine. Amazon ElastiCache can be configured as your Redis or Memcached caching service and AWS also provides a managed Elasticsearch service for full-text search.
S3 storage is an ideal storage solution for both uploaded files and site event logs. All running EC2 instances will be able to read and write from this file store and there are no storage limitations. Using S3 buckets will also allow you to keep the disk size of your deployment images low, as only the code and static assets will need to be included. S3 integrates with CloudFront for a ready-to-use CDN for your online store.
Email sending should be handled by Amazon SES, thereby removing the need for your application to send emails directly from the server and increasing deliverability (and making your emails far less likely to be mistaken for spam). Many cloud providers today won’t even allow you to attempt to send emails through anything but their dedicated email service.
Once you’ve configured your AWS Magento website to use all of the above, you can package it into an AMI template and deploy it to one or more EC2 instances—ready for any future scaling requirements—with traffic being passed through a load balancer.
If you need more capacity, you can launch more instances from the AMI template and add them to the load balancer, or employ an Auto Scaling group to do it automatically to meet demand.
Logicata engineers are the AWS and ecommerce experts
Magento is a professional tool that, when wielded by a professional developer following best practices, provides a robust foundation for almost any kind of ecommerce online experience. All of the decisions are up to the operator, granting full control of their sales platform.
As an ecommerce business you need to focus on running your online stores—coordinating stock, reaching out to new customers, and planning for the future—not figuring out the complexities of infrastructure scaling.
Additionally, AWS misconfiguration by inexperienced users can lead to outages, poor performance, or (worst of all) the leaking of sensitive customer data. Customers will not return to your website if it doesn’t load or if it has leaked their personal details to spammers.
Further reading: AWS Ecommerce Best Practices
Are you serious about providing a rock-solid ecommerce experience that your customers will keep coming back to? An AWS Managed Service Provider like Logicata will ensure that your business operates on a robust, scalable platform that’s suitable for your needs and ready to grow with your business.
Contact us and we’ll work with you to evaluate your current ecommerce solutions, explore options for improvement, and help you decide if Magento on AWS is the right solution for you.