2.1.1.1. Designing for Scalability and Elasticity (Auto Scaling, Load Balancing)
š” First Principle: Architectures must dynamically adapt to fluctuating demand by automatically scaling resources proportionally, ensuring consistent performance during peaks and optimal cost-efficiency during lulls.
Scenario: A popular online gaming application experiences massive, unpredictable spikes in traffic during new game releases. The architect needs to ensure the application can scale rapidly to handle these surges without manual intervention and maintain performance.
Scalability and elasticity are critical for cloud-native applications. Scalability refers to a system's ability to handle increasing load, while elasticity is the ability to automatically grow or shrink resources based on demand.
- "Amazon EC2 Auto Scaling": A service that dynamically adjusts
"EC2 instance"
capacity based on demand, using policies and health checks. Ensures performance during peaks and cost savings during lulls.- Key
"Auto Scaling"
Components:- Launch Templates/Configurations: Define how new instances are launched (
"AMI"
, instance type,"security groups"
). - Scaling Policies: Define how to scale (e.g.,
"Target Tracking"
,"Simple/Step Scaling"
,"Scheduled Scaling"
). - Health Checks: Determine if an instance is healthy and should remain in service.
- Launch Templates/Configurations: Define how new instances are launched (
- Key
- "Elastic Load Balancing (ELB)": A service that automatically distributes incoming application traffic across multiple targets, such as
"EC2 instances"
, containers, and"Lambda functions"
, in multiple"Availability Zones"
. Continuously monitors target health and routes traffic only to healthy instances, ensuring high availability and fault tolerance. Supports"Application Load Balancer (ALB)"
,"Network Load Balancer (NLB)"
, and"Gateway Load Balancer (GLB)"
for different protocol and routing needs.
Practical Implementation: Creating a Target Tracking Scaling Policy
{
"AutoScalingGroupName": "my-gaming-app-asg",
"PolicyName": "cpu-utilization-scaling-policy",
"PolicyType": "TargetTrackingScaling",
"TargetTrackingConfiguration": {
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ASGAverageCPUUtilization"
},
"TargetValue": 50.0
}
}
Visual: Auto Scaling and ELB for Scalability and Elasticity
Loading diagram...
ā ļø Common Pitfall: Setting a cooldown period that is too short. This can lead to "flapping," where the "Auto Scaling group"
rapidly scales in and out, causing instability and potentially higher costs.
Key Trade-Offs:
- Aggressiveness vs. Stability: A very aggressive scaling policy (low target utilization, short cooldown) responds quickly to spikes but can be unstable. A more conservative policy is stable but may lag behind sudden traffic surges.
Reflection Question: How does combining "Amazon EC2 Auto Scaling"
with "Elastic Load Balancing"
address both the rapid scaling and high availability requirements for this gaming application, particularly when dealing with unpredictable traffic surges and ensuring fault tolerance across instances?