The Amazon cloud computing platform is an excellent choice of hosting infrastructure for a growing and successful ecommerce business. When properly leveraged, using a proven service like AWS is a smart idea. It provides a secure, reliable, high-performance hosting infrastructure that can scale with your website—to massive proportions if necessary.
Scaling isn’t just a matter of throwing higher-specked hardware at a problem. You should resolve performance issues first to ensure that resources are not wasted. Amazon charges by the minute for its Elastic Compute Cloud (EC2) and Relational Database Service (RDS) instances, with higher fees for more powerful hardware.
Spreading the load across multiple smaller instances can often be more cost-effective and result in better performance. This article will outline these performance and scaling best practices for ecommerce websites in AWS to help you make the right platform and infrastructure choices for your business.
Performance improvements for your ecommerce site ahead of changing your AWS infrastructure
Every plugin you add to your website loads its own images, code and other assets—all potential causes of slowdown if they are poorly coded or inadequately optimized. You should periodically review all third-party code on your website (this could include plugins, themes and extensions if you’re using a platform like WooCommerce or Magento).
Cataloging your plugins in a spreadsheet along with their purpose and priority will make it easy to earmark slow plugins for potential removal or replacement, or even enhancement if you are willing to pay a professional to take a look at the plugin and create a better-optimized replacement.
Some third-party plugins store a lot of unnecessary data in your database. If your database transactions become sluggish, check for large tables and check what data is there. Identify the cause of the slowdown and remove any data that you no longer need. MySQL has the ability to detect and log your slowest database queries.
Enable this logging to identify the queries that slow your site down the most—you can then cache these queries in an in-memory store such as Redis or Memcached, or remove the data (and plugin) entirely if it is not needed. If you have control over your database design, ensure that columns that are regularly retrieved during site searches are indexed.
You should also decide on a caching strategy for your site early on. Caching pages and queries will allow your site to retrieve them faster, which will improve performance. However, caching on ecommerce sites requires extra thought because of the constantly changing stock levels and other ephemeral information unique to the current browsing session.
You need to ensure that you don’t cache this data, because that would lead to a confusing and frustrating experience for your customers. One option is to avoid all caching on catalog/product listing pages—but this blanket approach won’t lead to fast performance, as these pages make up the bulk of sites.
Instead, you could cache the number of items in stock, and then flush your cache whenever an item is sold. It’s important for your site to keep track of the exact number of items in stock so that out-of-stock products aren’t shown to the user as available.
Remember that sales from a physical store or from additional online sales platforms will affect your stock levels. If you sell through multiple venues, consider using a centralized stock management system to keep track of all incoming and outgoing stock, and automating the clearing of your site’s cache upon any change to this system.
Images, stylesheets, scripts or any other files can be cached using Amazon CloudFront–a cost-effective CDN that allows caching files across different global regions. This allows your users to load these files quickly from anywhere in the world.
Related reading: Guide to AWS CloudFront Pricing & Cost Optimization
Some business owners choose to start with a subscription-based managed ecommerce platform, as these paid-for solutions tend to be the easiest to get started with. However, if you want to retain full control over your shop and provide a bespoke experience, then fully customized, self-hosted solutions provide much more flexibility.
With the many choices available, be sure to choose the right platform from the outset. If you’re already using WordPress then using the WooCommerce WordPress plugin may have appeal (if your existing theme is compatible). If you’re a more established business with unique requirements, Magento may be more suitable.
Magento Open Source is a free community version, not to be confused with Adobe Commerce (formerly Magento Commerce), which is a paid-for hosted version of Magento. Other options—for example, OpenCart or PrestaShop—are simpler to use and are easier for non-technical users to get started with, but tend to be less customizable, with fewer plugins.
Related reading: Magento on AWS: Best Practices for Optimized, Scalable Deployments
Make sure you choose a platform that is right for your needs and future plans, thinking about the plugins you will need as your business scales (for example, you may need plugins for an affiliate scheme, dropshipping, digital delivery or postage calculation).
Scaling in AWS
When most people think of scaling, they think of vertical scaling—swapping out one EC2 or RDS instance for one with more processing power or memory. This is the easiest form of scaling and is (usually) the first type that is attempted.
However, once your business grows beyond a certain point, you will either hit the maximum available instance specification on AWS or start seeing diminishing returns on performance.
This is where the benefits of horizontal scaling in AWS appear. Horizontal scaling involves adding more EC2 or RDS instances to your infrastructure. Once you have multiple EC2 instances running your code, elastic load balancing spreads your traffic across these instances, decreasing the load on each individual instance and increasing performance overall.
Database instances are also scalable in this way—up to 5 read replicas of your database can be created in RDS. If your database needs to scale beyond this, Amazon Aurora allows up to 15 read replicas.
Auto Scaling groups are a cost-effective way of implementing horizontal scaling. Auto Scaling groups increase and decrease the number of running instances based on current traffic demands and the limits you specify. This allows you to better manage your infrastructure costs and ensures that you are not paying for extra computing power when it’s not needed.
Related reading: Scalability in Cloud Computing & Why We Love AWS
Achieving high availability
A Region in AWS is a location where Amazon’s data centres are clustered. One example is the US East (Northern Virginia) Region, also known as us-east-1; there are other regions located within Europe, Asia, and Oceania.
Each region has multiple Availability Zones. These follow a consistent naming scheme: us-east-1a, us-east-1b (and so on) for the US East Region. AWS Availability Zones are separate physical data centres within a particular Region. As each Availability Zone is separately located, outages in one Availability Zone will (usually) not affect assets in others.
Once you have horizontally scaled your infrastructure so that you have multiple AWS EC2 instances, you should ensure that the different instances are spread across different Availability Zones. This means that if one data centre goes down, the user requests will be spread across your remaining EC2 instances in entirely different Availability Zones.
An even better practice would be to spread your instances across different Regions entirely, which offers even more redundancy of your resources in the case of a catastrophic event.
AWS security best practices
Keeping all your AWS resources inside a properly configured Virtual Private Cloud (VPC) will stop them from being publicly accessible over the internet. It is still possible to have a VPC and make specific resources publicly available–but you need to take care to ensure only the required traffic is exposed.
You can avoid accidental misconfiguration by setting up a NAT gateway that sits in front of your private subnets within the VPC, and configuring the inbound and outbound rules on the NAT gateway instead. This provides a single point to audit your firewall rules to ensure that only the intended resources are available to the wider internet.
Some general web security best practices will also be useful. You should:
- ensure your AWS root user account is well protected, and
- implement multi-factor authentication on your AWS Identity and Access Management (IAM) user accounts.
Following the principle of least privilege is a good practice when it comes to your IAM user accounts: create many user roles for different permissions and give people access to the minimum amount of privilege they need to do their job, revoking roles from a user when they are no longer needed.
Finally, ensure all your web traffic goes over SSL and encrypt all sensitive data.
There are many different platform choices for hosting ecommerce websites. Hosting on Amazon Web Services gives a good balance between retaining control of your own data and being able to provide a fully bespoke experience while also avoiding the complications of self-hosting.
Using an AWS Managed Service Provider like Logicata removes an extra layer of stress, as you can outsource managing the inevitable complexities, particularly when you need to scale horizontally. As well as being experts on best practices for hosting sites in AWS, Logicata specializes in ecommerce.
We can help you optimize your website to get the most out of your current infrastructure and help you plan more advanced scaling solutions to ensure that you are ready for future growth.
Contact us today for expert advice if you’re experiencing fast growth, or are unsure whether you have the time or resources to implement the AWS best practices for ecommerce outlined here. Our experienced team would love to discuss how we can help you configure and maintain the best possible solution for your business.
Here’s more from our blog on AWS best practices
AWS Best Practices on PHP
Scale and Optimise Laravel on AWS
Magento on AWS: Best Practices
AWS Best Practices for E-commerce
WooCommerce on AWS: Best Practices