How to make your Magento applications scalable using AWS
Handling traffic spikes, and keeping an eCommerce website up and running fast during marketing campaigns has always been challenging, particularly when it comes to a platform like Magento.
Magento 2 is also more resource-consuming than the first version and requires more mandatory services to run out of the box.
But before we jump into the examples, let’s define what we mean by application scalability and application Based on our previous article Building scalable and resilient applications using AWS, we will see today how AWS scalability and resilience capabilities can apply and be used in a Magento 2 application.
Magento 2 requirements
Before explaining how to scale your Magento 2 website on AWS, we need to have a look at what Magento needs to run correctly. Here’s a summary of basic requirements:
AWS Auto Scaling allows you to automatically scale your compute (EC2) instances according to load conditions you define—such as CPU utilization or RAM consumption—also known as Dynamic Scaling.
It reduces the need to manually provision EC2 capacity in advance and when it is already too late, and directly follows the demand curve to start & stop additional instances on the fly.
You could also rely on Predictive Scaling, which aims to predict future traffic based on daily and weekly trends, thanks to machine learning algorithms. This helps provision against the right number of EC2 instances when they are needed.
Scaling fast and efficiently
In order to respond to the fluctuating eCommerce demand—reactively or proactively—it is crucial to scale up and down as fast as possible.
When working on AWS, in order to do so, you could consider building a custom Amazon Machine Image (AMI) to pre-install and compile all needed packages, services and tools, and save time later on during booting and provisioning.
On top of new instance(s) availability, you should also consider Magento 2 deployment steps, which could slow down the availability of those new instances.
Cloning the code, running the composer install command, deploying static resources, etc., could take several minutes to execute. This makes your auto-scaling mechanism slow and inefficient to properly handle instant spikes and hurts resiliency.
We recently wrote about a Magento 2 build & deploy commands workflow, used in a Docker context, which covers that part and might help you to address this. Most of the application deployment steps are done at the build stage, from which a Docker image—containing the entire and compiled application codebase—is created, and will be reused later on. Thanks to that encapsulation done in advance, It will be a matter of seconds to make your application available on new instances, enhancing the overall resiliency of your infrastructure.
Scaling RDS databases
Magento always suffered from its database heaviness. Still relying on the legacy EAV data model, it also became bigger and potentially heavier after more and more features and integrations were added over time.
Reaching traffic spikes, in addition to sudden connectivity increases, can result in complex parallel SQL queries execution, increasing the database workload, and slowing down your website completely. AWS RDS allows you to create, maintain, and scale relational databases in the cloud, to answer this kind of situation.
Firstly, by deploying your production instances in multiple availability zones, you get a physically distinct and replicated version of the database on each AZ. When an infrastructure failure occurs, Amazon RDS performs an automatic failover to any standby or replica instance, from another AZ. This allows you to resume database operations, as soon as the failover will be completed, without the need for manual intervention.
When it comes to scale resources and absorb any workload, AWS Aurora is probably the most appropriate choice. Compared to an RDS MySQL master instance—which needs to trigger a downtime in order to scale vertically, even in multi-AZ configuration—Aurora Auto Scaling feature allows your Aurora DB cluster to handle sudden increases in connectivity and workload, by providing up to 15 read replicas you can define through a scaling policy, without any downtime or outage.
Aurora Auto Scaling adjusts the number of Aurora Replicas up or down in response to actual workloads, determined by using Amazon CloudWatch metrics and target values.
As a cloud-native database, compared to RDS MySQL, AWS Aurora addresses better matters of availability and resiliency and is an excellent choice. Aurora is being fully supported since the release of the 2.4.3 Magento version.
AWS ElastiCache, OpenSearch, and MQ services are most convenient and easier to scale, as none of them requires any downtime after vertically or horizontally scaling actions. When you have to do it manually for OpenSearch and MQ, you can opt-in for ElastiCache for Redis that has recently been integrated with AWS Auto Scaling, eliminating the need for any manual administrative intervention to scale.
Using AWS to make your Magento application scalable is a great strategy. The number of services and features you have at your disposal is huge!
If you’re looking to leverage the scalable and resilient capabilities of AWS to build other types of applications, make sure to check out the previous article on how to build scalable and resilient applications with AWS.
I hope you found this article helpful! Book a demo with us If you’re interested in seeing how Artifakt is using AWS to provide you with the most seamless experience possible.