Mastering AWS Elastic Load Balancing: Focus on Application Load Balancer (ALB)
Load balancing concepts (for example, Application Load Balancer [ALB])
Mastering AWS Elastic Load Balancing: Focus on Application Load Balancer (ALB)
Learning Objectives
After studying this guide, you should be able to:
- Distinguish between the three modern types of AWS Elastic Load Balancers (ALB, NLB, GLB).
- Explain how the Application Load Balancer operates at Layer 7 of the OSI model.
- Configure routing rules based on paths, hostnames, and query strings.
- Describe the integration between Elastic Load Balancing and EC2 Auto Scaling for high availability.
- Implement health checks to ensure traffic is only routed to healthy targets.
Key Terms & Glossary
- Listener: A process that checks for connection requests using a specific protocol and port.
- Target Group: A logical grouping of targets (like EC2 instances or containers) to which the load balancer routes traffic.
- Health Check: A periodic ping or request sent by the load balancer to a target to verify it is functioning correctly.
- Layer 7 (Application Layer): The OSI layer that handles high-level protocols like HTTP and HTTPS, allowing for content-aware routing.
- GENEVE Protocol: The protocol used by Gateway Load Balancers to encapsulate traffic for third-party virtual appliances.
The "Big Idea"
At its core, a load balancer is the single entry point for your application. Instead of users connecting directly to a single server, they connect to the load balancer. This decouples the client from the backend, allowing you to add or remove servers dynamically without the user ever knowing. It transforms a fragile, single-server setup into a resilient, scalable system that can survive instance failures and massive traffic spikes.
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 | GENEVE |
| Best For | Web apps, Microservices | Extreme performance, Static IPs | Firewalls, Intrusion Detection |
| Routing Logic | Path, Host, Query String | IP Protocol, Port | IP Packets (Raw) |
Hierarchical Outline
- Load Balancing Fundamentals
- Entry Point: Users connect to a DNS name (Route 53) pointing to the LB.
- Automation: Automatically updates when instances are added/removed.
- Modern Elastic Load Balancing (ELB) Types
- Application Load Balancer (ALB): Content-based routing.
- Network Load Balancer (NLB): High throughput, low latency.
- Gateway Load Balancer (GLB): Third-party security appliances.
- Application Load Balancer Deep Dive
- Listeners: Rules define how traffic is handled.
- Target Groups: Routes to EC2, ECS, or IP addresses.
- Routing Rules:
- Path-based:
example.com/imagesvsexample.com/api. - Host-based:
app1.example.comvsapp2.example.com.
- Path-based:
- Resiliency and Scalability
- Auto Scaling Integration: ALB adds new instances to Target Groups automatically.
- Cross-Zone Load Balancing: Distributes traffic across all Availability Zones.
Visual Anchors
Load Balancer Data Flow
OSI Layer Positioning
\begin{tikzpicture}[node distance=1.5cm] \draw[thick] (0,0) rectangle (6,1) node[midway] {Layer 7: Application (ALB)}; \draw[thick] (0,-1.2) rectangle (6,-0.2) node[midway] {Layer 4: Transport (NLB)}; \draw[thick] (0,-2.4) rectangle (6,-1.4) node[midway] {Layer 3: Network (GLB)}; \draw[->, thick] (-1,0.5) -- (-1,-2.4) node[midway, left, rotate=90] {Deep Packet Inspection Levels}; \end{tikzpicture}
Definition-Example Pairs
- Path-Based Routing: Routing requests to different target groups based on the URL path.
- Example: Requests for
example.com/videogo to a cluster of optimized media servers, whileexample.com/imagesgo to a different cluster.
- Example: Requests for
- Host-Based Routing: Routing requests based on the host field in the HTTP header.
- Example: Routing
orders.acme.comto one application andshipping.acme.comto another, even if they share the same load balancer.
- Example: Routing
- Sticky Sessions (Affinity): Ensuring a client's requests are consistently sent to the same backend instance.
- Example: A shopping cart application that stores session data locally on an EC2 instance (rather than a database) requires the user to stay on that specific instance during their session.
Worked Examples
Exercise: Deploying a Basic ALB
- Prepare Targets: Launch two EC2 instances in different subnets (AZ1 and AZ2). Install a simple web server (Apache) on both.
- Create Target Group:
- Name:
my-web-targets. - Target type:
Instances. - Health check:
HTTPon path/index.html.
- Name:
- Configure ALB:
- Name:
my-application-lb. - Scheme:
Internet-facing. - Listeners: Port
80(HTTP). - Subnets: Select the subnets where your instances reside.
- Name:
- Register Targets: Add your two EC2 instances to the
my-web-targetsgroup. - Test: Copy the DNS name of the ALB and paste it into a browser. Refresh several times; you should see the response alternate between Server 1 and Server 2.
Checkpoint Questions
- Which load balancer type is best suited for an application requiring static IP addresses and handling millions of requests per second?
- Answer: Network Load Balancer (NLB).
- A developer wants to route traffic to different microservices based on the URL path. Which ELB should they use?
- Answer: Application Load Balancer (ALB).
- How does a load balancer know if an EC2 instance has crashed and should no longer receive traffic?
- Answer: Through Health Checks; if the instance fails to respond to the ping/request, the LB marks it as unhealthy and stops routing traffic to it.
- What protocol does the Gateway Load Balancer use to communicate with virtual appliances?
- Answer: The GENEVE protocol.