Automating EC2 Instance Scaling for Variable Traffic with Zero Downtime

0

Hello AWS Community,

I have a client who operates a website on an EC2 instance with 64 GB of RAM, which can handle peak traffic from 7 PM to 12 AM. During off-peak hours, the website can function efficiently on an instance with just 8 GB of RAM.

To optimize costs and maintain performance, I want to automate the process of scaling up to the 64 GB instance during peak hours while using the 8 GB instance during off-peak times, all without any downtime or disruption to user experience.

My initial thought is to use an Application Load Balancer (ALB) to route traffic between the instances. Here are my key requirements:

Automated Scaling: Automatically spin up the 64 GB instance during peak hours and route traffic accordingly.

Zero Downtime: Ensure that users experience no interruption during the traffic diversion process.

Cost Efficiency: Minimize costs by only utilizing the larger instance when necessary.

Has anyone implemented a similar setup? What AWS services and strategies would you recommend to achieve this, considering the need for zero downtime? Any insights or best practices would be greatly appreciated!

Thank you! Pritam

  • Is there a reason you need to change instance sizes vs horizontally scaling multiple 8GB instances? The issue with an ALB approach is that there will be 2 instances running for a brief period. So if your application supports 2 instances running at once, why not just scale normally vs changing sizes and adding complexity of 2 ASGs?

1 Answer
1

Thank you for posting your question.

Sorry for long answer, I'd approach this in following steps:

1. Set up Auto Scaling Groups (ASGs):

  • Create two ASGs: one for the 64 GB instance and one for the 8 GB instance.
  • Configure the 64 GB ASG with a minimum of 1 instance and a maximum of X instances (depending on your expected peak traffic).
  • Configure the 8 GB ASG with a minimum of 1 instance and a maximum of Y instances (depending on your expected off-peak traffic).

2. Configure Application Load Balancer (ALB):

  • Create an ALB and configure two target groups, one for each ASG.
  • Set up health checks to ensure that only healthy instances receive traffic.
  • Configure the ALB to use weighted target group routing.

3. Implement Auto Scaling Policies:

  • Create CloudWatch alarms to monitor your website's traffic patterns.
  • Set up auto scaling policies to automatically scale the 64 GB ASG up and down based on the traffic thresholds.
    • Scale up the 64 GB ASG during peak hours (e.g., 7 PM to 12 AM).
    • Scale down the 64 GB ASG and scale up the 8 GB ASG during off-peak hours.
  • Use the weighted target group routing to gradually shift traffic between the two instance types during scaling operations.

Lastly I'd advise to test it thoroughly making sure that:

  • Seamless transition between the 64 GB and 8 GB instances.
  • Verify that the user experience is not disrupted during the scaling process.
  • Monitor the system's performance and adjust the scaling policies as needed.

Additionally, refer following documentation, you might find them helpful as alternate approaches to handle the same situation:

Comment here if you have additional questions, happy to help.

Abhishek

profile pictureAWS
EXPERT
answered a month ago
profile pictureAWS
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions