Load Balancing & Auto Scaling
Scalability, elasticity and high availability, and how Elastic Load Balancing and EC2 Auto Scaling deliver them.
What it is
An app that runs on one server has two problems: when traffic grows, the server gets slow, and when the server fails, the app is down. This group covers the two services that fix both:
- Elastic Load Balancing spreads requests over many servers and stops sending traffic to failed ones.
- Amazon EC2 Auto Scaling adds and removes servers as the load changes, and replaces failed ones.
Used together, across several Availability Zones, they're the standard design for almost every web application on AWS.
Scalability and high availability
Scalability means a system can handle a bigger load by adapting. There are two kinds. The course explains them with a call centre:
Vertical scalability (scale up and down)
Make the instance bigger, like replacing a junior phone operator with a senior one who handles more calls.
- Example: move an app from a
t3.microto at3.large. On EC2 the range runs fromt3.nano(0.5 GiB of memory) to high-memory U instances with up to 32 TiB. - Common for systems that aren't distributed, such as a database. RDS and ElastiCache scale vertically.
- There's always a hardware limit, and changing size usually means a restart.
Horizontal scalability (scale out and in)
Add more instances, like hiring more operators. This is also called elasticity when it happens automatically with demand.
- Needs a distributed system: the app must work when requests land on any instance.
- Normal for modern web applications, and straightforward on AWS with Auto Scaling groups and load balancers.
High availability
High availability means running the app in at least two data centres (Availability Zones), so it survives losing one, like having call centres in two cities.
- Active: instances in every AZ serve traffic at once (horizontal scaling across AZs).
- Passive: a standby waits in another AZ and takes over on failure (for example RDS Multi-AZ).
- For EC2: an Auto Scaling group and a load balancer, both set to use several AZs.
Scalability is about load; high availability is about failure. They usually go together, but one doesn't guarantee the other: ten instances in one AZ scale well but go down with the AZ.
In this group
Load balancing
Elastic Load Balancing
What a load balancer does, health checks, the four types, security groups.
Application Load Balancer
Layer 7 routing by path, host, header and query string.
Network Load Balancer
Layer 4 TCP/UDP, static IPs, extreme performance.
Gateway Load Balancer
Send traffic through firewalls and other virtual appliances.
Sticky sessions and cross-zone
Keeping a user on one target, and spreading load across AZs.
SSL/TLS, SNI and draining
HTTPS on load balancers, many certificates, deregistration delay.
Auto Scaling
Auto Scaling groups
Min, desired and max capacity, launch templates, health checks.
Scaling policies
Target tracking, step, scheduled, predictive; cooldowns, warm pools, instance refresh.
Exam tips
- "Handle more load by adding instances", "elastic" → horizontal scaling with an Auto Scaling group.
- "Survive the failure of an AZ / data centre" → instances in at least two AZs behind a load balancer.
- "Database needs more power" → usually vertical scaling (a bigger instance class), or read replicas.
- "Highly available and scalable web tier" → ALB + Auto Scaling group across multiple AZs.