AWS Auto Scaling with Varnish – How your Magento shop can handle increased traffic easily!

Stefan Wieczorek —  August 18, 2020 — Leave a comment

AWS Auto Scaling with Varnish – How your Magento shop can handle increased traffic easily!

Many e-commerce businesses do a lot of marketing like sending newsletters, Groupons, or TV campaigns.

A good marketing campaign means much more traffic than on a normal day.
It’s not uncommon that you can have hundreds or thousands of customers within the first 10-15 minutes.

These marketing campaigns are really expensive, but can turn out even more expensive!

The increased traffic that you were not prepared for can lead to slow loading times at best. That can annoy your potential customers. But at worst, traffic peaks can cause your site to be unavailable so that you can’t sell your products or services at all.

To make sure your Magento shop can handle increased traffic, Auto Scaling is not only convenient but a must-have preparation for you.

Managing your traffic peaks with Auto Scaling brings you one invaluable advantage:

Auto Scaling ensures your e-commerce shop’s availability no matter how high the traffic volume is!

Combined with professional Magento hosting, it will raise your e-commerce store to a new level.

You may have already heard about instant scalability in the AWS Cloud as one of many
cloud benefits, but haven’t made the leap to autoscale cloud deployment yet?
What are you waiting for?

In this blog post, we will explain to you how to auto scale Magento together with
Varnish Cache on the Amazon AWS Cloud and much more:

Table of Contents

Why you need Auto Scaling: reasons, problems and consequences of unexpected traffic peaks

To grow your e-commerce business, you will probably decide to run a marketing campaign and invest a lot of money and effort into its success.

But there is one-factor many shop owners are not using for their calculations.

If their marketing campaign is really successful, it will cause increased traffic and traffic peaks.

There are many reasons for traffic peaks, such as:

  • newsletter or Groupon campaigns
  • TV commercials
  • Christmas time
  • Black Friday
  • other special sales

Nevertheless, as great as this high traffic is, it can have a decisive impact on your e-commerce shop.

Traffic peaks can cause many problems like:

  • restrictions in store functionality
  • slow loading times
  • a temporary or steady unavailability of the shop

Being this unprepared can cause consequences such as:

  • unsatisfied customers
  • lost sales
  • loss of image

At worst, this marketing campaign will only burn your money, and in the short and long term, direct and indirect financial losses may arise.

The example of Macy’s (the largest department store operator in the United States) showed in 2016 that even big players can fail because of this challenge.

Due to unmanageable traffic peaks on Black Friday, Macy’s website displayed “Sorry, shoppers! We’re currently experiencing heavier traffic than normal.” and sent their customers into a queue to wait.

That’s why you have to ensure that fast loading times are guaranteed even during traffic peaks.

Your shop has to work at all times, independently of how many more potential customers are on your site.

To make initial improvement, we recommend taking a look at our top 12 easy tips on how to increase Magento website speed.

But how do you manage traffic peaks in the most efficient and reliable way?
The solution is Auto Scaling!

Auto Scaling Traffic Peaks

Auto Scaling accelerates your Magento shop to make traffic peaks a thing of the past.

What is Auto Scaling?

Auto Scaling is a web service from Amazon that enables you to automatically launch or terminate servers based on user-defined policies, health status checks, and schedules.

With Auto Scaling you can ensure that the number of servers you are using increases seamlessly during demand spikes to maintain performance and decreases automatically during demand lulls to minimize costs.

Advantages of AWS Auto Scaling features

In the following, there is a variety of advantages to Auto Scaling.

The main advantages of Auto Scaling are:

  • The resources required at any given time are always available in a reliable, scalable on-demand infrastructure.
  • Your applications are monitored and capacity automatically adjusted to achieve lasting, predictable performance at the lowest possible cost.
  • Since the infrastructure is optimally utilized, there is no waste of resources or money. You only pay for what you need. AWS bills per minute. It makes a big difference whether you run two web servers and use more for a few minutes, hold some in reserve, or always have 6 or more active. This fact will be reflected in our AWS Auto Scaling Pricing.
  • Scaling for multiple resources and services can be set up in just a few minutes.
  • You determine when and how to scale.
  • You are prepared for long-term growth and are able to grow your business strategically and effectively.

Making smart scaling decisions and ensuring constant performance even with a high number of visitors was never this easy.

How Auto Scaling works (incl. AWS Auto Scaling example)

Now let’s look at an example of how Auto Scaling works.

Suppose you have a Magento store that runs on a single server. The single server performs well when you have regular traffic. However, occasionally the traffic to your Magento store increases up to five times the normal load.

When that happens, you need additional server resources to handle the traffic; otherwise your Magento shop will go down.

What happens in this example if you use Auto Scaling?

  1. You define the conditions that determine the increasing traffic to your Magento store.
  2. Then you tell Auto Scaling to launch more servers whenever those conditions are met.
  3. After that, you define another set of conditions that determines the decreasing traffic to your Magento store and then tell Auto Scaling to terminate a server when those conditions are met.

3 MGT solutions that are essential for a professionally operating Auto Scaling

If you are already interested in Auto Scaling, you have to know that there are three parts that are essential for professionally operating it.

These 3 parts are:

  • MGT Code Deploy
  • MGT Cloud Log
  • MGT WAF – Web Application Firewall

We will now explain each of them to you and how they benefit your Auto Scaling.

Of course, all of these 3 solutions are included in our MGT Auto Scaling plans.
Contact us now to find out more!

Solution 1: MGT Code Deploy – zero downtime deployment

The first of our solutions that are necessary for professional Auto Scaling is MGT Code Deploy. This tool makes Auto Scaling usable.

Imagine this challenge: You have 5 web servers located in 3 different states, and you have detected that something is not working and want to fix as soon as possible. But how do you get access to these 5 servers?

MGT Code Deploy makes this possible!

This is our zero downtime deployment solution for Magento on Amazon Web Services.

Its convincing benefits include:

  • built specifically for Magento and its needs
  • zero downtime
  • automated deployments
  • blazingly fast
  • centralized control
  • Supported by MGT

MGT Code Deploy is ready for Auto Scaling and supports multiple environments and users as well.

Solution 2: MGT Cloud Log for easy log management

Our MGT Cloud Log makes log management easy.

It is a fully managed log solution for rapid troubleshooting and exploration.

Even though they might have only been active for a few minutes, you have to know for all of your web servers what exactly happened on them.

Maybe due to a mistake, one of your products in your e-commerce shop was not accessible or the basket was not working.

Now you want to get an overview of all of the server activities in the past that are stored on your own network for the future and won’t get lost.

MGT Cloud Log allows you to retrace in detail what exactly caused the mistake on your site.

What’s even better: This important analysis tool warns you in real-time, e.g. via SMS, when mistakes occur on your site, enabling you to take action fast.

With our innovative and easy-to-use log management, you get everything in one central place:

  • Magento
  • NGINX
  • PHP-FPM
  • MySQL
  • System Logs

Learn more about MGT Cloud Log.

If you have any questions, feel free to contact us at any time.

Solution 3: MGT WAF – Web Application Firewall for Magento

A Web Application Firewall is an important part of your safety measures to secure a Magento site.

But what is a WAF in detail?

The three general tasks for a WAF include:

  • filtering
  • monitoring
  • blocking

Exceeding this basic protection, MGT WAF – Web Application Firewall for Magento is a managed web application firewall on top of an AWS WAF.
It protects your Magento shop against common web exploits that may affect availability, compromise security, or consume excessive resources.

MGT WAF ensures you the highest security possible and brings you benefits like:

  • Denial-of-service attack mitigation
  • SQL injection and cross-site scripting protection
  • Preventing Linux attacks
  • Country as well as bot and IP blocking
  • Auto updates

AWS Auto Scaling Architecture: How does it work?

To get an idea about Auto Scaling architecture and how it works, take a look at our architecture graphic:

AWS Auto Scaling Architecture Diagram

AWS Auto Scaling Architecture Diagram

The numbers are shown here mean:

  1. Amazon Route 53 (DNS)
  2. Varnish Cache
  3. Elastic Load Balancing (ELB)
  4. Auto Scaling – Web Server (NGINX)
  5. Database Server (MySQL)
  6. Database Server (Slave)
  7. NFS Server
  8. ElastiCache
  9. Admin Server
  10. Cloudfront CDN
  11. Test Server

In the following, we explain each of them to you in detail.

But instead of getting lost in technical explanations, let’s focus on the question that really interests you: What are you getting with this?

With AWS Auto Scaling Architecture, you get an incredibly flexible infrastructure combined with a service that is able to process this kind of flexibility.

Your auto-scaling requirements might change from one day to the next. But this infrastructure and our additional service always stay the same.

1. Amazon Route 53 (DNS)

Amazon Route 53 is a highly reliable cloud DNS web service (Domain Name System).

Benefits:

  • very fast due to global infrastructure (Edge locations) around the world
  • highly available and reliable
  • automatic DDoS protection

2. Varnish Cache

Varnish Cache is a web accelerator, sometimes referred to as an HTTP accelerator or a reverse HTTP proxy that will significantly improve your Magento shop page loading time.

Varnish speeds up your Magento Store by storing a copy of the page in the memory the first time a visitor requests a site.

We deliver expertise, and professional support gained from more than six years of integration experience with Magento. We developed a module to enable easy control of Varnish Cache for Magento, included in our turnkey solutions.

Benefits:

  • fast loading time
  • higher click-through rate
  • increased conversion rate
  • savings in infrastructure

3. Elastic Load Balancing (ELB)

Elastic Load Balancing automatically distributes incoming traffic across multiple Web Server instances to different data centers (availability zones).

The Elastic Load Balancer scales automatically provides high availability and the highest security industry standards.

4. Auto Scaling – Web Server (NGINX)

Auto Scaling is used to ensure that the number of instances increases seamlessly during demand spikes to maintain performance and decrease automatically during demand lulls to minimize costs.

Benefits:

  • high performance
  • high availability
  • minimizes costs

5. Database Server (MySQL)

Amazon Relational Database Service (RDS) is a reliable and scalable cloud database service.
It was designed for the highest performance and security and is inexpensive. You pay very low rates and only for the resources you actually use.

Benefits:

  • very fast
  • highly scalable
  • available and durable
  • rollback possible in five-minute steps

6. Database Server (Slave)

Amazon Relational Database Service (RDS) Read replicas provide enhanced performance and durability.

This replication feature makes it easy to scale beyond the capacity constraints of a single DB instance for read-heavy database workloads.

7. NFS Server

The NFS Server is used as shared storage between the web servers. All media files including generated product image thumbnails are stored on it.

8. ElastiCache

ElastiCache is a highly scalable and fault-tolerant web service for in-memory data storage like Redis.

Redis is used for sharing the Magento cache and session between all web servers.

9. Admin Server

The Admin Server is responsible for all backend activities like:

  • managing the orders
  • products
  • categories

All cron jobs and other scripts are located on the admin server as well.

10. Cloudfront CDN

Amazon CloudFront is a web service that gives businesses and web application developers an easy and cost-effective way to distribute content with low latency and fast data transfer.

We use CloudFront CDN to deliver static files.

The files that are delivered via CDN include:

  • Stylesheets
  • JavaScript
  • Images

This relieves the web servers. Therefore, it improves performance and drops costs because the web servers now only have to handle PHP requests.

11. Test Server

The Test Server is an independent single server environment with MGT CloudPanel.

The test server is used as a pre-production environment to test new features/developments before applying them to production.

AWS Auto Scaling Architecture Requirements

AWS Auto Scaling architecture has some special requirements.

In the following section, our MGT experts that have years of experience in Auto Scaling can consult with you in as much detail as you need.

If you have further questions, our support would be happy help you.

Requirement 1: Flexible Hosting Platform

Amazon AWS has a global infrastructure around the world that is very secure, reliable, scalable, and flexible.

With Amazon AWS, we have access to the same reliable, secure technology platform used to power Amazon.com’s global web properties.

Combined with our High Performance Magento Hosting that is fully managed on AWS, your e-commerce site is on its way to having its best success.

Requirement 2: Multi Server Environment

For Auto Scaling Magento, you need a multi-server environment to add and remove servers from the load balancer without any downtime.

It’s not possible to scale a single server automatically. A single server can only scale vertically.

To add more resources (CPU, RAM) you need to stop/start the server, which can take several minutes depending on the load.

Multi-Server Architecture Diagram

Multi-Server Architecture Diagram

Requirement 3: Shared Nothing?

For Auto Scaling we need a “Shared Nothing” architecture.

The Shared Nothing architecture is a highly scalable system that consists of several nodes that work autonomously.

The nodes have their own exclusive resources such as:

  • processor performance
  • storage space
  • memory

This architecture offers high performance due to the parallel processing of tasks.

This means we need to share:

  • varnish cache
  • database
  • network file system (NFS)
  • session and cache storage

With this architecture, we are able to add and remove web servers from the load balancer.

3 Problems to solve

Nevertheless, at this point, there are three problems for us to solve.

Problem 1: Sync of the latest source code

Since we launch new instances from an image (AMI), we need to sync the Magento source code before we can put the instance into service.

We have developed a small shell script that syncs the source files from the admin server before we start Nginx.

Problem 2: Varnish Cache Auto Scaling

To get varnish working in a multi-server environment, you need to define all backends (instances) in the config file.

With Auto Scaling, you have no knowledge of which instances and how many instances are running.

Because of that, you need an automatic way to write the config file based on the instances in the load balancer.

We thought the easiest solution would be to define the load balancer (ELB) as the backend.

Unfortunately, that does not work because varnish needs a static IP as backend and the ELB does not have one. The load balancer has several private IPs and scales automatically.

We have solved the problem with a PHP script that updates the configuration file with all active instances from the load balancer. For this, we use the AWS SDK for PHP.

Problem 3: Auto Scaling Code Deployment

With Auto Scaling, you may have 1, 2, 3, or even 100 active instances running.

The problem is that you need the private IP of each instance to deploy a new version.

The easiest way to get all of the instances is to use the Amazon API.

We launch all instances with an environment tag to identify them later.

With the help of the environment tag, we can simply filter the instances for the deployment.

Lessons Learned for making Auto Scaling most efficient

To sum up, there are two lessons learned:

  1. Scale up early
  2. Scale down slowly

But what does this mean?

Scale up early

We learned to scale up early on an average of >= 55% CPU utilization over a period of 60-120 seconds because it takes up to 2-3 minutes until the new instances are in service.

Booting the instance takes about 1 minute. After that, we sync the source code from the admin server before we start the web server (NGINX).

Afterward, the load balancer can start with its health checks. Depending on your health check configuration, it can take up to 30 seconds to get the instance into service.

Scale down slowly

The time required for a metric to meet a threshold to scale down should be greater than the time to scale up.

We scale down instance per instance when the average CPU utilization is smaller than or equal to 25% over a period of 15 minutes.

Conclusion: Prepare for traffic peaks and grow your business strategically using Auto Scaling

Don’t underestimate the success of your advertising activities.

If you are not able to deal with the traffic peaks of your Magento shop due to marketing campaigns, you will face serious consequences.

Potential customers may become frustrated if your site is loading slow or at worst, not available at all.
As a result, they may leave your shop and buy from your competitors.
They will lose trust and may never come back. This directly leads to lost sales and reputation.

It’s pretty simple: Your e-commerce shop has to run at all times so that customers can buy, with a small number of visitors, and at traffic peaks.

That is why you should prepare with Auto Scaling. With Auto Scaling you guarantee that your site flexibly and automatically adjusts to the amount of traffic.
Traffic peaks will no longer be a problem. Your Magento shop will run smoothly all the time.

An emerging e-commerce business needs to autoscale cloud deployment and the best Magento hosting there is.

MGT-Commerce is your ideal partner for managed hosting on AWS.
Contact us now and we will assist you in finding the best solutions for your business.

No Comments

Be the first to start the conversation.

Leave a Reply

*