Elastic Load BalancersExplore AWS Elastic Load Balancers (ALB, NLB, GWLB), their advanced features like host-based and path-based routing, and how to address DNS challenges.
ByAnis Mer_

Elastic Load Balancers

Distributing Traffic Across Your Application

As your application grows, handling increasing traffic effectively becomes crucial. This is where Elastic Load Balancers (ELBs) come in. ELBs automatically distribute incoming traffic across multiple instances or resources, ensuring availability, scalability, and fault tolerance.

In this article, we’ll explore what ELBs are, how they work, their types, and advanced features like host-based and path-based routing. We’ll also address DNS-related challenges like DNS_PROBE_FINISHED_NXDOMAIN and provide tips for optimal configurations.


What is an Elastic Load Balancer?

An Elastic Load Balancer (ELB) is a managed service in AWS that acts as a traffic distributor, sending incoming requests to multiple backend resources like EC2 instances, containers, or Lambda functions.

Key Features:

  1. Automatic Traffic Distribution: Spreads incoming traffic across healthy resources.
  2. High Availability: Ensures your application remains operational even if some resources fail.
  3. Scalability: Automatically adjusts to handle changes in traffic.
  4. Secure Connections: Supports HTTPS and SSL termination for secure communication.

Mental Model: ELB as a Digital Receptionist

Think of an ELB as a receptionist for a busy office:

  • Incoming calls (requests) arrive at the receptionist.
  • The receptionist evenly distributes the calls to available employees (resources).
  • If an employee is unavailable (unhealthy), the receptionist skips them and directs the call elsewhere.

Types of Elastic Load Balancers

AWS offers three types of load balancers, each designed for specific use cases:

1. Application Load Balancer (ALB)

The ALB operates at Layer 7 of the OSI model, the application layer, which means it routes traffic based on the content of the HTTP or HTTPS request. This includes headers, hostnames, and URL paths. Unlike Network Load Balancers that focus solely on connections, ALBs offer advanced request routing features, such as:

  • Host-Based Routing: Direct traffic based on the domain name in the Host header (e.g., api.example.com vs. www.example.com).
  • Path-Based Routing: Route requests to different targets depending on the URL path (e.g., /admin to admin servers, /user to user servers).
  • SSL Termination: Decrypt incoming HTTPS traffic at the ALB and pass unencrypted traffic to backend instances, reducing their workload.

Why It Matters: This makes ALBs ideal for modern web applications that rely on microservices or serve multiple domains and APIs through a single entry point.

  • Best For: HTTP and HTTPS traffic.
  • Key Features:
    • Routes traffic based on content (e.g., URLs, headers).
    • Supports host-based and path-based routing.
    • Integrates with AWS services like ECS and Lambda.

Example:
Route requests for myapp.com/api to your backend API servers and requests for myapp.com/images to a storage service.


2. Network Load Balancer (NLB)

  • Best For: High-performance, low-latency applications.
  • Key Features:
    • Operates at the TCP/UDP layer.
    • Handles millions of requests per second.
    • Designed for extreme performance and static IPs.

Important Note:
NLBs may handle DNS-related traffic for high-performance workloads. Ensure that DNS port 53 is allowed in your security group configurations. DNS relies on port 53 (UDP/TCP), and blocking it can disrupt DNS resolution for applications relying on NLBs.

Example:
Use an NLB to distribute traffic for a high-speed financial trading application.


3. Gateway Load Balancer (GWLB)

  • Best For: Deploying and managing third-party virtual appliances like firewalls or intrusion detection systems.
  • Key Features:
    • Handles traffic at the network layer.
    • Simplifies deployment of virtual appliances at scale.

Example:
Deploy a firewall appliance to inspect all incoming and outgoing traffic.


How Elastic Load Balancers Work

  1. Client Request: A user sends a request to the ELB.
  2. DNS Resolution: The user’s DNS resolves the ELB’s DNS name (e.g., myapp-alb-1234.us-east-1.elb.amazonaws.com) to an IP address.
    • AWS recommends using Route53 for this purpose, as it acts as one of the best DNS servers for managing application traffic.
  3. Health Check: The ELB checks the health of backend targets (e.g., EC2 instances) and routes traffic only to healthy resources.
  4. Traffic Distribution: The ELB spreads requests across all available targets based on the selected load-balancing algorithm.
  5. Response: The backend resource processes the request and sends a response back to the user via the ELB.

Advanced Features of Application Load Balancers

Host-Based Routing

Host-based routing allows the ALB to route traffic based on the Host header in the HTTP request. For example:

  • Traffic to api.example.com can be routed to API servers.
  • Traffic to www.example.com can be routed to a web server group.

Mental Model:
Think of the ALB as a receptionist redirecting visitors based on their appointment type. Visitors for "Sales" go to Floor 1, and those for "Support" go to Floor 2.


Path-Based Routing

Path-based routing enables the ALB to route traffic based on the URL path of the HTTP request. For example:

  • Requests to /dashboard are sent to servers handling user dashboards.
  • Requests to /admin are sent to administrative servers.

Mental Model:
It’s like a call center menu where callers press 1 for Sales or 2 for Support. The system redirects them based on their input.


Addressing Common DNS Challenges

Error: DNS_PROBE_FINISHED_NXDOMAIN

Occurs when DNS cannot resolve a domain name. This often happens with ELBs when:

  • CNAME records are misconfigured.
  • DNS changes haven’t propagated due to high TTL settings.

Fix:

  • Verify that Route53’s DNS records (e.g., A or CNAME) point to the correct ELB name.
  • Set low TTL values for DNS records to ensure quick propagation.

Error: DNS server not responding

Occurs if resources cannot communicate with a DNS server.

  • Fix: Ensure instances and ELBs are configured to use Amazon-provided DNS servers or Route53 for internal name resolution.

Scaling DNS Traffic with ELBs

Elastic Load Balancers work seamlessly with Route53 to handle DNS traffic effectively.

  • TTL Settings: Use low TTL values to ensure DNS changes propagate quickly during scaling events.
  • Latency-Based Routing: Combine ELBs with Route53’s latency-based routing for optimal performance across regions.
  • Monitor DNS Queries: Use AWS CloudWatch to track DNS query volume and detect potential bottlenecks.

Big Words Defined

  • Elastic Load Balancer (ELB): A managed AWS service that distributes traffic across multiple resources.
  • Application Load Balancer (ALB): Routes HTTP/HTTPS traffic based on content (layer 7).
  • Network Load Balancer (NLB): Routes TCP/UDP traffic with low latency (layer 4).
  • Gateway Load Balancer (GWLB): Routes and inspects network traffic for advanced use cases.
  • DNS Resolution: The process of translating a domain name into an IP address.
  • DNS Port 53: The port used for DNS traffic over UDP and TCP protocols.

What’s Next?

Next, we’ll explore Autoscaling — how to dynamically adjust your resources to handle traffic demands while integrating seamlessly with DNS for high availability.

Back