AWS Best Practices for E-commerce

Voiced by Amazon Polly

The AWS cloud computing platform is an excellent choice of hosting infrastructure for a growing and successful e-commerce business. When properly leveraged, using a proven service like AWS is an e-commerce best practice in and of itself. AWS 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-specced hardware at a problem. You should resolve performance issues first to ensure that resources are not wasted. AWS 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 e-commerce websites in AWS to make the right e-commerce platform and infrastructure choices for your business.

Performance improvements for your e-commerce site ahead of changing your AWS infrastructure

The first step is to profile your code: put your e-commerce platform into developer mode and start by investigating any errors or warnings that your code generated. Debug client-side JavaScript errors by using the console in your web browser’s developer tools, and use the network tab to view how quickly (and in what order) scripts, images and assets are loading on your site.

A view of the developer console showing Javascript errors on the client side of your ecommerce website

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 e-commerce 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 e-commerce 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 e-commerce 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.

Some business owners choose to start with a subscription-based managed e-commerce 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 e-commerce 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 customisable, with fewer plugins.

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 AWS 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 in AWS involves adding more EC2 or RDS instances to your infrastructure. One you have multiple EC2 instances running your code, AWS 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.

AWS 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.

Achieving high availability in AWS

A Region in AWS is a location where Amazon’s data centers 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 AWS 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 centers 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 EC2 instances, you should ensure that the different instances are spread across different Availability Zones. This means that if one data center 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 (MFA) 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.

Conclusion

There are many different platform choices for hosting e-commerce websites. Hosting on AWS gives a good balance between retaining control of your own data and being able to provide a fully bespoke e-commerce 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 complexities of AWS, particularly when you need to scale horizontally. As well as being experts on best practices for hosting sites in AWS, Logicata specializes in e-commerce. 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 on AWS best practices for e-commerce.

You Might Be Also Interested In These...

Managed Cassandra

Why Should you Care About Amazon Keyspaces (Managed Apache Cassandra Service)?

**Updated 24th April 2020 when Amazon Managed Apache Cassandra Service went GA as Amazon Keyspaces** Last week at re:Invent 2019, AWS CEO Andy Jassy announced the launch of the preview for the new Amazon Managed Apache Cassandra service (launched in GA as Amazon Keyspaces).  But what exactly is it, and why should you care?   Apache Cassandra […]

View Post
Outbreak and lockdown city on covid 19-virus epidemic in europe zone.healthy and medical treatment.biology effect.business and economy.

Combat Covid-19 With 3 Free AWS Homeworking Solutions

It’s fair to say that the world was unprepared for a global pandemic such as Covid-19.  We’ve seen outbreaks in the past – SARS, Ebola, but nothing that has spread so quickly and with such far reaching consequences.  Bill Gates told us in 2015 that we were not ready for such a global outbreak and he was […]

View Post

WooCommerce on AWS Best Practices for Scalable Deployments

WooCommerce sites can be vulnerable to performance issues, and complicated to scale. Marc shares how to keep your installation clean and up-to-date, and when you should choose to work with an established AWS MSP.

View Post
ebook featured image

5 Steps to a Successful

AWS Migration

DOWNLOAD FREE EBOOK