Event-Driven Scaling

Introduction

So far we spent a lot of time to talk about auto scaling. We had gone through both theory and hands-on exercies. In fact, we can not only set the threshold of EC2, but also RDS and ELB. Also, we are going to discuss what the things we have to consider when using auto scaling.

Auto Scaling Review

Since we have talked too much about auto scaling previously, here we just mention some important things.

Below shows the most typical case when using auto scaling. It always involves ELB, Auto Scaling and CloudWatch these 3 services.

First of all, we have to set our launch configuration. Secondly, we need to define the auto scaling group. Finally, we have to set the auto scaling policy or scheduled action.

Auto Scaling Consideration

In stead of guessing about resources needs, we prefer to build a flexible system that will react to changes in customer demand and manage costs dynamically.

Be friendly reminded that instances can take several minutes after launch to be fully usable. Thus, we do not set the CPU utilization as above 80% to trigger the alarm. Instead, we set around 60% to trigger.

Scaling Data Stores

In case we are using RDS, we can split our data into large chunks. For example, we can split the user last name into A through M and N through Z. This approach is also called sharding. The benefit is let us have higher performance and better operating efficiency.

Amazon RDS Read Replicas | Cloud Relational Database | Amazon Web Services

On the other hand, if we do not care too much about writing to DB but care the read capacity. Then we may use Read Replicas. It horizontally scales for read-heavy workloads. However, replication is asynchronous. Thus, when we write something and it takes time to reflect on the Read Replicas.

AWS Lambda and Event-driven Scaling

How to configure AWS Lambda SQS Trigger to consume messages only specific  time? | by Furkan Zümrüt | Trendyol Tech | Medium

AWS Lambda is a fully managed services that runs stateless code in response to an event or on a time-based interval. It allows us to run code without managing infrastructure like EC2 and auto scaling groups.

Code run in AWS Lambda has access to the AWS API and can be granted permissions via AWS IAM roles. Use a lambda function to automatically make API calls to other AWS services when scaling happens.

There are some example of scaling-related operations we could perform with AWS Lambda:

  • Scale container-based instances (Docker, Amazon Elastic Container Service and so on).
  • Scale more intelligently using functions e.g. analyze a stream of performance data looking for patterns rather than just events.
  • Since AWS Lambda can scale automatically, consider replacing some EC2 instances with Lambda functions where appropriate.

Conclusion

In this article, we firstly review auto scaling briefly. Then we discuss how we should set the threshold of auto scaling. Furthermore, we talk about RDS scaling. We can do sharding or make a Read Replicas. Finally, we discuss how to use Lambda in auto scaling.

Leave a Reply