AWS Networking and Content Delivery: Elastic Load Balancing (ELB)
·CloudAWSCertificationsProfessionalDevelopers

AWS Networking and Content Delivery: Elastic Load Balancing (ELB)

Master Elastic Load Balancing (ELB), AWS's highly available service for distributing incoming application traffic across multiple targets. Explore the different types of load balancers (ALB, NLB, CLB), their features, and when to use each for building scalable, fault-tolerant web applications.

Directing the Flow: Understanding Elastic Load Balancing (ELB)

Welcome back to Module 13: Networking and Content Delivery! We've laid the groundwork for your private network with VPC fundamentals, subnets, and routing. Now, it's time to ensure that your applications running within your VPC can handle fluctuating user traffic reliably and scalably. This is where Elastic Load Balancing (ELB) comes into play. For the AWS Certified Cloud Practitioner exam, understanding the purpose of ELB and the different types of load balancers is crucial for designing highly available and fault-tolerant applications.

This lesson will extensively cover Elastic Load Balancing, explaining its core purpose in distributing incoming application traffic across multiple targets. We'll detail the different types of load balancers offered by AWS (Application Load Balancer, Network Load Balancer, and Classic Load Balancer), their unique features, and the scenarios where each is best suited. We'll also include a Mermaid diagram illustrating how ELB works with Amazon EC2 instances to achieve distribution and resilience.

1. What is Elastic Load Balancing (ELB)?

Elastic Load Balancing (ELB) automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, and Lambda functions. It monitors the health of its registered targets and routes traffic only to the healthy ones. ELB automatically scales its own request handling capacity in response to incoming application traffic.

Key Purpose:

  • Load Distribution: Spreads incoming traffic evenly across multiple backend resources, preventing any single resource from becoming overloaded.
  • High Availability: Continuously monitors the health of registered targets and stops sending traffic to unhealthy instances, redirecting it to healthy ones. This improves the fault tolerance of your applications.
  • Scalability: Automatically scales its own capacity to handle traffic spikes, and enables your application to scale horizontally by adding more backend instances.
  • SSL/TLS Termination: Can handle encryption and decryption of traffic, offloading this compute-intensive task from your backend instances.

2. Types of Elastic Load Balancers

AWS offers three types of load balancers, each with different capabilities and best suited for specific use cases.

a. Application Load Balancer (ALB)

  • Layer: Operates at the application layer (Layer 7) of the OSI model.
  • Features:
    • Content-based Routing: Routes requests based on the content of the request (e.g., URL path, host header). For example, traffic to /images can go to one set of servers, and traffic to /api can go to another.
    • Target Groups: Registers targets (EC2 instances, IP addresses, Lambda functions) in target groups. ALB routes traffic to these groups.
    • HTTP/HTTPS: Ideal for HTTP and HTTPS traffic.
    • Path/Host-based Routing, Query String Parameters, HTTP Methods: Advanced routing features.
    • WebSocket Support: Supports long-lived connections.
  • Use Cases: Microservices, container-based applications, web applications with complex routing requirements. It's the most flexible and feature-rich for modern web traffic.

b. Network Load Balancer (NLB)

  • Layer: Operates at the connection layer (Layer 4) of the OSI model.
  • Features:
    • Extreme Performance: Designed for extremely high performance and ultra-low latency. Can handle millions of requests per second.
    • Static IP Addresses: Provides a static IP address per Availability Zone, which can be useful for whitelisting by client applications.
    • TCP/UDP Traffic: Ideal for TCP, UDP, and TLS traffic where extreme performance is required.
  • Use Cases: High-performance gaming, IoT, real-time analytics, applications requiring static IP addresses.

c. Classic Load Balancer (CLB)

  • Layer: Operates at both the request level (Layer 7) and connection level (Layer 4).
  • Features: Legacy load balancer.
  • Use Cases: Older applications. AWS generally recommends using ALBs for HTTP/HTTPS applications and NLBs for TCP/UDP traffic. CLBs are still supported but are not recommended for new applications.

Exam Tip: For the Cloud Practitioner exam, focus on the high-level distinctions:

  • ALB: Best for complex HTTP/HTTPS routing (Layer 7).
  • NLB: Best for extreme performance TCP/UDP with static IPs (Layer 4).
  • CLB: Legacy, generally avoid for new designs.

3. How ELB Works with EC2 Instances

The core functionality of ELB is to distribute incoming requests to a fleet of backend instances, typically EC2 instances, across multiple Availability Zones.

Key Concepts:

  • Listeners: A listener checks for connection requests, using the protocol and port that you configure.
  • Target Groups: Each listener is configured with a default rule that forwards requests to a target group. A target group routes requests to one or more registered targets (e.g., EC2 instances), using the protocol and port number that you specify.
  • Health Checks: ELB periodically sends requests to its registered targets to determine their health. Only healthy targets receive traffic.

Visualizing ELB with EC2 Instances

graph TD
    UserTraffic[User Traffic] --> ELB[Elastic Load Balancer]
    
    subgraph "AWS Region"
        subgraph "Availability Zone 1"
            EC2Instance1[EC2 Instance 1]
        end
        subgraph "Availability Zone 2"
            EC2Instance2[EC2 Instance 2]
        end
        subgraph "Availability Zone 3"
            EC2Instance3[EC2 Instance 3]
        end
    end

    ELB -- Routes traffic to healthy instances --> EC2Instance1
    ELB -- Routes traffic to healthy instances --> EC2Instance2
    ELB -- Routes traffic to healthy instances --> EC2Instance3

    EC2Instance1 -- Health Check --> ELB
    EC2Instance2 -- Health Check --> ELB
    EC2Instance3 -- Health Check --> ELB

    style UserTraffic fill:#FFD700,stroke:#333,stroke-width:2px,color:#000
    style ELB fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style EC2Instance1 fill:#90EE90,stroke:#333,stroke-width:2px,color:#000
    style EC2Instance2 fill:#90EE90,stroke:#333,stroke:#333,stroke-width:2px,color:#000
    style EC2Instance3 fill:#90EE90,stroke:#333,stroke-width:2px,color:#000

This diagram illustrates how a single Elastic Load Balancer distributes incoming user traffic across multiple EC2 instances spread across different Availability Zones, providing high availability and scalability for the application.

4. Benefits of Using Elastic Load Balancing

  • Increased Fault Tolerance: By distributing traffic across multiple healthy targets, a single instance failure does not impact the overall application availability. ELB automatically takes unhealthy instances out of rotation.
  • Improved Scalability: Works seamlessly with Amazon EC2 Auto Scaling to handle increases in traffic by automatically adding or removing instances.
  • Reduced Operational Overhead: ELB is a fully managed service, meaning AWS handles the maintenance, patching, and scaling of the load balancer itself.
  • Security Features: Integrated with AWS WAF for Layer 7 protection and supports SSL/TLS termination to offload encryption from your backend instances.
  • Sticky Sessions: Can be configured to route a client's requests to the same target instance for the duration of their session.

5. Practical Example: Creating an Application Load Balancer (Conceptual CLI)

While a full ELB setup requires setting up target groups and registering instances, here's a conceptual AWS CLI command to create an Application Load Balancer.

# 1. Create a Load Balancer (ALB)
# Replace 'my-alb' with a unique name for your load balancer.
# Replace 'subnet-0123456789abcdef0' and 'subnet-0fedcba9876543210' with your actual subnet IDs (from different AZs).
# Replace 'sg-0123456789abcdef0' with a Security Group that allows inbound HTTP/HTTPS traffic.

ALB_ARN=$(aws elbv2 create-load-balancer \
    --name my-alb \
    --subnets subnet-0123456789abcdef0 subnet-0fedcba9876543210 \
    --security-groups sg-0123456789abcdef0 \
    --scheme internet-facing \
    --type application \
    --query 'LoadBalancers[0].LoadBalancerArn' --output text)

echo "Application Load Balancer ARN: $ALB_ARN"

# 2. Create a Target Group
# This defines how the load balancer routes requests to registered targets.
# Replace 'my-target-group' with a unique name.

TG_ARN=$(aws elbv2 create-target-group \
    --name my-target-group \
    --protocol HTTP \
    --port 80 \
    --vpc-id vpc-0123456789abcdef0 \
    --health-check-protocol HTTP \
    --health-check-path / \
    --healthy-threshold 5 \
    --unhealthy-threshold 2 \
    --interval 30 \
    --query 'TargetGroups[0].TargetGroupArn' --output text)

echo "Target Group ARN: $TG_ARN"

# 3. Create a Listener (for HTTP traffic on port 80)
# This listens for incoming connections and forwards them to the target group.

aws elbv2 create-listener \
    --load-balancer-arn $ALB_ARN \
    --protocol HTTP \
    --port 80 \
    --default-actions Type=forward,TargetGroupArn=$TG_ARN

echo "Listener created for ALB."

# 4. (Conceptual) Register instances with the target group (e.g., EC2 instances from your Auto Scaling Group)
# aws elbv2 register-targets --target-group-arn $TG_ARN --targets Id=i-0123456789abcdef0 Id=i-0fedcba9876543210

Explanation:

  • create-load-balancer: Provisions the ALB itself, specifying its subnets (for multi-AZ deployment) and security groups.
  • create-target-group: Defines where the load balancer sends traffic, including health check parameters.
  • create-listener: Configures the load balancer to listen on a specific port/protocol and forward requests to a target group.

This setup creates the load balancing infrastructure, which will then seamlessly distribute incoming traffic to your application instances, exemplifying the HA and scalability benefits of ELB.

Conclusion: Orchestrating Traffic for Resilience

Elastic Load Balancing (ELB) is a cornerstone service for building scalable, highly available, and fault-tolerant applications on AWS. By automatically distributing incoming traffic, continuously monitoring target health, and seamlessly integrating with other AWS services like EC2 Auto Scaling, ELB ensures that your applications can adapt to changing demand and remain resilient in the face of failures. For the AWS Certified Cloud Practitioner exam, understanding the purpose of ELB and the distinct use cases for Application Load Balancers, Network Load Balancers, and the legacy Classic Load Balancer is essential for designing robust cloud architectures.


Knowledge Check

?Knowledge Check

A company needs to distribute incoming HTTP and HTTPS traffic to multiple backend EC2 instances running a microservices application. They also require advanced routing capabilities based on URL path. Which type of Elastic Load Balancer is best suited for this scenario?

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn