AWS Elastic Load Balancing: A Comprehensive Study Guide
Load balancing concepts (for example, Application Load Balancer)
AWS Elastic Load Balancing (ELB) Concepts
Learning Objectives
After studying this guide, you should be able to:
- Differentiate between the three modern Elastic Load Balancer types (ALB, NLB, and GLB) based on OSI layers and use cases.
- Explain the relationship between Load Balancers and Auto Scaling Groups (ASG) in achieving high availability.
- Describe the mechanism of health checks and how they contribute to application reliability.
- Identify routing rules for Application Load Balancers, including path-based and host-based routing.
Key Terms & Glossary
- Listener: A process that checks for connection requests using the protocol and port you configure.
- Target Group: A logical grouping of targets (like EC2 instances or containers) to which the load balancer routes requests.
- Health Check: A periodic ping or request sent by the load balancer to ensure a target is functioning correctly before sending traffic to it.
- Sticky Sessions (Session Affinity): A feature that binds a user's session to a specific target, ensuring all requests from that user during the session are sent to the same instance.
- SSL Termination: The process of decrypting encrypted traffic at the load balancer level to reduce the computational load on backend servers.
The "Big Idea"
At its core, Load Balancing is the ultimate "traffic cop" of the cloud. It prevents any single server from becoming a bottleneck by distributing incoming application traffic across multiple targets. This decoupling of the entry point (DNS/LB) from the compute resources (EC2/Containers) is what allows cloud architectures to be resilient, scalable, and highly available. Without load balancing, horizontal scaling would be manual and prone to failure.
Formula / Concept Box
| Feature | Application Load Balancer (ALB) | Network Load Balancer (NLB) | Gateway Load Balancer (GLB) |
|---|---|---|---|
| OSI Layer | Layer 7 (Application) | Layer 4 (Transport) | Layer 3 (Network) |
| Protocols | HTTP, HTTPS, gRPC | TCP, UDP, TLS | IP (GENEVE encapsulation) |
| Best For | Web apps, Microservices | Extreme performance, static IPs | Security appliances, firewalls |
| Routing Basis | URL Path, Host, Query String | IP Protocol, Port, Source IP | IP Packets |
Hierarchical Outline
- I. Introduction to Elastic Load Balancing (ELB)
- Automation: Automatically scales to handle traffic spikes.
- Health Monitoring: Stops routing to failed replicas.
- II. Modern Load Balancer Types
- Application Load Balancer (ALB): Best for HTTP/HTTPS; supports advanced routing.
- Network Load Balancer (NLB): High throughput, ultra-low latency; uses static IPs.
- Gateway Load Balancer (GLB): Deploys and manages 3rd-party virtual appliances.
- III. High Availability & Failover
- Multi-AZ Deployment: Distributing traffic across multiple Availability Zones.
- Route 53 Integration: DNS-level failover and inter-region load balancing.
- IV. Integration with Auto Scaling
- Dynamic Membership: ASG adds/removes instances from Target Groups automatically.
Visual Anchors
Load Balancing Request Flow
OSI Layer Mapping
\begin{tikzpicture} \draw[thick, fill=blue!10] (0,3) rectangle (6,3.8) node[pos=.5] {Layer 7: Application (ALB)}; \draw[thick, fill=green!10] (0,2) rectangle (6,2.8) node[pos=.5] {Layer 4: Transport (NLB)}; \draw[thick, fill=orange!10] (0,1) rectangle (6,1.8) node[pos=.5] {Layer 3: Network (GLB)}; \draw[dashed] (-1,0.5) -- (7,0.5) node[right] {OSI Model}; \draw[->, line width=1pt] (-0.5,3.4) -- (0,3.4); \draw[->, line width=1pt] (-0.5,2.4) -- (0,2.4); \draw[->, line width=1pt] (-0.5,1.4) -- (0,1.4); \end{tikzpicture}
Definition-Example Pairs
- Path-based Routing: Routing requests based on the URL path.
- Example: Requests for
example.com/ordersgo to the "Order Service" group, whileexample.com/profilegoes to the "User Service" group.
- Example: Requests for
- Health Checks: The mechanism used to determine if a target is "InService".
- Example: A load balancer sends an HTTP GET request to
/healthevery 30 seconds; if the server returns a 404 three times in a row, the LB stops sending users there.
- Example: A load balancer sends an HTTP GET request to
- Cross-Zone Load Balancing: Distributing traffic evenly across all registered instances in all enabled Availability Zones.
- Example: If AZ-A has 2 instances and AZ-B has 8, cross-zone balancing ensures each instance handles 10% of total traffic regardless of AZ.
Worked Examples
Step-by-Step: Setting up an ALB
- Create Targets: Launch two EC2 instances in different Availability Zones. Install a web server (like Apache) and create a unique
index.htmlon each (e.g., "Server A" and "Server B"). - Define Target Group: In the EC2 Console, create a Target Group (Type: Instance, Protocol: HTTP, Port: 80) and register your two instances.
- Configure LB: Create an Application Load Balancer.
- Select "Internet-facing".
- Select at least two Availability Zones.
- Add a Listener for HTTP on Port 80.
- Associate: Point the Listener to the Target Group created in Step 2.
- Test: Copy the DNS Name of the ALB (e.g.,
my-alb-123.us-east-1.elb.amazonaws.com) into your browser. Refresh repeatedly; you should see the page toggle between "Server A" and "Server B".
Checkpoint Questions
- Which load balancer type would you choose for an application requiring a static IP address for its entry point? (Answer: Network Load Balancer)
- How does an Application Load Balancer distinguish between traffic for
mobile.example.comandweb.example.com? (Answer: Using Host-based routing rules) - If an EC2 instance in a Target Group fails its health check, what does the Load Balancer do immediately? (Answer: It stops routing new requests to that specific instance)
- At which OSI layer does the Gateway Load Balancer operate? (Answer: Layer 3)
- True or False: A Load Balancer can distribute traffic across different AWS Regions. (Answer: False - ELB is regional; Route 53 is used for inter-region load balancing)