Aws Series High Availability and Scaling
Post Date : 2023-12-30T09:31:02+07:00
Modified Date : 2023-12-30T09:31:02+07:00
Category: systemdesign aws
Tags: aws
Vertical Scaling vs Horizontal Scaling
Vertical Scaling
Eg:
- Increase your EC2 RAM
- Increase your EC2 CPU
- …
Horizontal Scaling
Eg:
- Add new EC2
- Add new EC2
- …
But we dont’ only scale EC2, it should include other parts:
- Database
- VPC
- AZ
- …
The 3W’s of Scaling
What do we scale?
- What sort of resource, we’re going to scale. How do we define template?
Where do we scale?
- When applying the model, where does it go? Should we scale out database? Or Webservers?
When do we scale?
- How do we know we need more? CloudWatch alarms can tell us it’s time to add more resources.
Launch Template
- A launch template specifies the needed settings that go into building out an EC2 instance. It is a collection of settings you can configure so you dont’ have to walk through the EC2 wizard over and over.
It’s a heart of auto scaling feature.
Let’s compare Lauch Template with Configurations:
Launch Template
- Capable of leveraging all EC2 auto scaling features.
- Supports versioning
- More granularity
- AWS recommends this approach
Configuration
- Only for certain EC2 auto scaling features
- Immutable
- Limited configuration options
- Try not to use them
What can be included inside a Launch Template?
- AMI
- EC Instance Size
- Security Groups
- Potentially networking information( if you use autoscaling, this part should be set inside autoscaling group configuration)
- Potentially UserData
Scaling EC2 Instances with Auto Scaling Groups
- Creating a High Available application
- Remember spread the resources out over multiple AZs and utilize load balancers
Auto Scaling Groups
- Contain a collection of EC2 Instances that are treated as collective group for purposes of scaling and management.
Auto Scaling Steps
LifeCycle
Step Scaling
Simple Scaling
- Relies on metrics for scaling needs
Example: Add 1 instances if CPU Utilization metric > 80%
Target Tracking
- Uses a Scaling metric and value that ASG should maintain at all times
Eg: Maintain ASGAverageCPUUtilization = 50%
Instance Warm-up and CoolDown
Warm-Up: stops instances from being placed behind the load balancer, failing the health check, and being terminated prematurely
CoolDown: Pauses Auto Scaling for a set amount of time. Help you avoid runaway scaling events. -> prevent over doing auto scaling
Avoid Thrashing: You want to create instances quickly and spin them down slowly
Scaling Types
- Reactive Scaling: Measure and determine if you need to create/remove resources
- Schedule Scaling: Have a predictable workload, create a scaling event to get your resources ready to go before they’re actually needed -> shopping events(black Friday, Christmas, Hoildays)
- Predictive Scaling: AWS uses it machine learning algorithms to determine when you’ll need to scale. They are reevaluated every 24 hours to create a forecast for the next 48 hours
Key Figures
- Desired: initial value
- Min: minimum value
- Max: maximum value
Scaling Relational Databases
4 Types of Scaling
- Vertical Scaling : resize
- Scaling Storage: storage can be resized, but it’s only able to go up, not down
- Read replicas: creating read-only copies of your data can help spread out the workload
- Aurora serverless: We can offload autoscale to AWS. Excels with unpredictable workloads
Scaling Non-Relational Databases
DynamoDB
- AWS does all the heavy lifting for you
- Just 2 options: provisioned(predictable workload) and on-demand(sporadic workload)
- You can switch between 2 options, but only twice per 24hours per table
Some figures
RCU(read capacity unit)
- DynamoDB Unit of measurement for reads per second for an item up to 4KB in size.
- One strongly consistent read per second
- Two eventually consistent read per second
So how many RCUs for 1 strongly consistent read per second for object that are 7KB in size?
1 RCU = 4 KB/ 1 strongly consistent read Round up to the next nearest amount for the item size = 8KB/4KB = 2 RCU
WCU(write capacity unit)
- DynanoDB Unit of measurement for writes per second for an item up to 1KB in size
So how many WCUs for 1 write per second for an object that is 3KB in size?
1 WCU = 1KB * 1 write per second
3KB * 1 WCU = 3 WCU
Disaster Recovery Strategies
RPO (Recovery Point Objective)
- How much data you can afford to lose?
- Typically speaking, the lower time, the greater the cost
RTO (Recovery Time Objective)
- How fast do you want to fail over? How much time can the business afford?
- Typically speaking, the lower the time, the more expensive the cost
Backup and Restore
Simplest Disaster Recovery Strategy
- Restore the system from your backup
Pilot Light
Warm StandBy
Active/Active Failover