Skip to main content

Elastic Load Balancer (ELB): Ensuring High Availability

What is Load Balancing?​

Load balancing is the process of distributing incoming network traffic across multiple servers to ensure that no single server becomes overwhelmed, enhancing the application's availability and reliability.

For a deeper dive into the concept of load balancing, check out the System Design section. Below, we cover essential concepts about Load Balancers (LB) and AWS ELB.

Why Use AWS ELB?​

Ease of Management​

AWS ELB provides a fully managed service, handling maintenance, patching, and scaling of the load balancer infrastructure. This allows you to focus on building and enhancing your application while AWS takes care of the operational aspects.

Multi-AZ for High Availability​

AWS ELB automatically provisions multiple load balancer nodes across each selected Availability Zone (AZ), ensuring redundancy and resilience. If one node fails, others seamlessly take over, keeping your application running smoothly.

Automatic Failover​

  • Same-Region Failover: AWS ELB automatically manages failover within the same region. If your load balancer is spread across multiple AZs, AWS routes traffic to healthy nodes, ensuring high availability. If a node in one AZ fails, traffic is redirected to nodes in other AZs.

  • Cross-Region Failover: For failover across regions, Route 53 works with ELB. You can configure Route 53 to redirect traffic to a secondary region if the primary region's ELB fails. For example, if an ELB in Mumbai is unavailable, Route 53 can direct traffic to a backup region like us-west-1. Latency routing in Route 53 can also direct users to the nearest or most suitable region based on their location, optimizing latency and user experience.

Elastic Scaling​

  • Scaling ELB: AWS ELBs automatically scale their capacity in response to changing traffic loads, adjusting resources to manage traffic spikes or decreases. This scaling is managed at the regional level.

  • Scaling Instances: ELB works with Auto Scaling Groups to manage instances. It can scale up by adding more nodes as traffic demands increase and scale down when traffic decreases.

Health Checks​

ELBs perform regular health checks on registered targets (like EC2 instances) to ensure they are functional. If a target fails the health check, the load balancer stops routing traffic to it until it recovers.

Example: If one of your web application instances goes down, the load balancer will detect this and stop sending traffic to it, ensuring users are not directed to a non-responsive server.

DNS Name Instead of IP​

Instead of accessing a service via 192.168.1.1, users can access it via a DNS name like my-alb-1234567890.us-west-2.elb.amazonaws.com. If the backend infrastructure changes, the domain name can still point to the new infrastructure without affecting the user experience.

Key Terms​

  • Target Groups: Target groups manage a collection of targets (e.g., EC2 instances or containers) that receive traffic from an Elastic Load Balancer (ELB). Each target group has its own health checks to assess the health of its targets. While target groups are often associated with Auto Scaling Groups (ASGs) to automatically add or remove instances based on scaling activities, it is not mandatory. You can also manually add or remove instances from target groups without using an ASG.

  • Port Mapping: Specifies which port on the target group should receive incoming traffic. For instance, an Application Load Balancer (ALB) listening on port 80 (HTTP) can route traffic to target instances listening on port 8080.

Types of AWS ELB​

Application Load Balancer (ALB)​

ALB operates at the application layer (Layer 7 of the OSI model) and can distribute traffic across multiple target groups based on URL paths, host headers, and other request attributes.

  • DNS Name: AWS ALB provides a DNS name like my-alb-1234567890.us-west-2.elb.amazonaws.com. This DNS name can point to the ALB, and even if the load balancer reboots or the underlying IP changes, AWS updates the DNS record accordingly.

  • Advanced Routing: ALB can route traffic based on URL paths, host headers, and other request attributes, enabling sophisticated routing rules.

  • Sticky Sessions: ALB supports sticky sessions, which bind a user's session to a specific server. This is useful for stateful applications like chat applications using WebSocket.

  • Hides Client IP: ALB uses headers like X-Forwarded-For to relay the original client IP to backend servers. Although the client IP is not directly visible to the server, this header helps applications identify the original requester.

  • SSL Termination: ALB can terminate SSL/TLS connections, offloading encryption/decryption from backend servers. This simplifies SSL certificate management and reduces the computational load on servers.

Example: For a secure site, ALB can decrypt HTTPS traffic and forward it as HTTP to backend servers, reducing the need for SSL management on each server.

Network Load Balancer (NLB)​

NLB operates at Layer 4 (Network Layer), which is optimal for TCP traffic and provides consistent performance for real-time applications.

  • Static IP: NLB provides a static IP address for each Availability Zone (AZ) where it is deployed.

    Example: Suppose we deploy an NLB in us-west-2 and select two AZs: us-west-2a and us-west-2b. AWS assigns a static IP address like 198.51.100.10 for us-west-2a and 198.51.100.11 for us-west-2b.

  • Low Latency: NLB routes traffic within the same AZ, reducing cross-AZ data transfer to improve latency and performance. This is particularly beneficial for applications requiring low-latency communication.

  • Original IP: NLB preserves the original client IP and source port, passing them to backend servers. This is unlike ALB, where the original IP is hidden and relayed via headers.

  • Long-running Connections: NLB supports long-lived TCP connections, which remain open for extended periods. This is ideal for applications that require continuous communication between the client and server, such as real-time gaming or financial trading systems.