Sub topic 1
Why Scale Horizontally and Spread Across Availability Zones
Prerequisites
Assume you understand basic EC2 instances, VPC subnets, security groups, HTTP, and TCP. You should also be able to run AWS CLI commands.
Horizontal Scaling
Vertical scaling makes one server larger, such as changing to an EC2 instance with more CPU or memory. It has a limit and creates a single point of failure.
Horizontal scaling adds more servers and shares work among them. It improves capacity and availability. If one instance fails, other instances can continue serving requests.
An Availability Zone (AZ) is an isolated location within an AWS Region. Deploying instances in multiple AZs reduces the effect of an AZ failure. A subnet belongs to exactly one AZ, so a multi-AZ design uses subnets in different AZs.
Elastic Load Balancing
Elastic Load Balancing (ELB) distributes traffic across registered targets, such as EC2 instances. It checks target health and avoids sending requests to unhealthy targets.
Choose a load balancer based on the traffic it must understand:
| Load balancer | Main traffic | Typical use |
|---|---|---|
| Application Load Balancer | HTTP and HTTPS | Web applications and content-based routing |
| Network Load Balancer | TCP, UDP, and TLS | High-performance or non-HTTP services |
| Gateway Load Balancer | Network appliances | Firewalls and inspection systems |
Application Load Balancer
An Application Load Balancer (ALB) operates at the HTTP layer. It can route requests using host names, URL paths, headers, or query strings. For example, api.example.com can route to an API target group while www.example.com routes to a web target group.
An ALB uses an HTTPS listener to receive encrypted traffic. It can terminate TLS with an AWS Certificate Manager certificate, then forward HTTP or HTTPS traffic to targets.
Network Load Balancer
A Network Load Balancer (NLB) operates at the connection layer. It supports TCP, UDP, and TLS and is suitable when low latency, static IP addresses, or very high connection rates matter. It does not provide ALB-style path or host routing.
Listeners and Routing Rules
A listener waits for connections on a protocol and port, such as HTTPS on port 443. Its default action sends traffic to a target group. ALB listener rules can evaluate conditions in priority order and forward matching requests to different target groups.
Exercise
Why place load-balancer targets in more than one Availability Zone?
Show answer
Multiple AZs let the service continue operating if an instance or an entire AZ becomes unavailable.