AWS Certified Developer - Associate
Load Balancing AutoScaling
Elastic LoadBalancer Overview
In this lesson, we explore how load balancing works on AWS using Elastic Load Balancers (ELBs). We explain key features, architectural considerations, and best practices for configuring ELBs to ensure high availability, reliability, and scalability for your applications.
Imagine load balancing as similar to an office building’s receptionist. Just as a receptionist directs visitors—whether employees, new hires, or delivery personnel—to the correct floor or department, an ELB receives incoming traffic and distributes it to the appropriate backend resources, such as EC2 instances, ECS tasks, or Lambda functions.
When multiple EC2 instances are involved, each with its own IP address, an ELB enables end users to use a single DNS entry rather than tracking individual IP addresses. The load balancer then automatically routes requests to the correct backend resources.
Key Features of Elastic Load Balancers
Elastic Load Balancers are a fully managed service from AWS, meaning that AWS takes care of the underlying hardware, networking, and software. Your primary task is to set the operating rules. The main features include:
High Availability and Fault Tolerance
ELBs distribute traffic both across servers and multiple Availability Zones (AZs). If one AZ encounters an issue, the load balancer routes traffic to healthy instances in other zones—thus preventing any single server from becoming overwhelmed.Public vs. Private Deployment
Configure your load balancer to be public (accessible via the internet) or private (restricted to internal use). This flexibility allows you to tailor the load balancer to your security requirements.Simplified DNS Management
Each ELB gets a DNS entry that remains constant even when the underlying IP addresses change. This eliminates the need to update DNS records frequently.Health Checks
ELBs perform periodic health checks using HTTP, HTTPS, or TCP protocols on specified ports. If a server fails these checks, it is temporarily taken out of the rotation until it recovers.
Availability Zones and Load Balancer Deployment
Elastic Load Balancers support multi-AZ deployments. When creating an ELB, you select the Availability Zones and subnets where it will reside. Note that these subnets are for deploying the load balancer nodes, not necessarily for placing your EC2 instances. For example, you might deploy load balancer nodes in public subnets that route traffic to EC2 instances located in private subnets within the same AZ.
When setting up your ELB, assign specific subnets for its nodes. These nodes balance incoming traffic to target resources in the same or different subnets within each AZ.
Cross-Zone Load Balancing
Cross-zone load balancing is essential for managing traffic distribution across Availability Zones. Consider a scenario where one AZ has two instances while another has only one. Without cross-zone balancing, the single instance might receive an excessive amount of traffic relative to its capacity. Enabling cross-zone load balancing ensures that traffic is evenly distributed across all instances, regardless of the number of instances in each AZ. This feature is enabled by default.
Public and Private Load Balancers
The subnet selected for your ELB determines whether it is public or private:
- Public Load Balancer: Deployed in a public subnet to handle internet traffic.
- Private Load Balancer: Deployed in a private subnet to manage internal traffic.
A common two-tier architecture example includes:
- An API layer (frontend) in a public subnet behind a public load balancer.
- A backend database in a private subnet, accessible only through secure channels.
Alternatively, all EC2 instances may reside in private subnets, with a public ELB delivering external requests while keeping the backend secure.
Target Groups and Listener Rules
Target groups are collections of resources (like EC2 instances) that receive traffic for specific applications. After creating target groups for different services, you define listener rules on the ELB to route requests based on criteria such as hostname or URL path. For instance:
- Requests for "appone.com" are forwarded to Target Group A.
- Requests for "apptwo.com" with the URL path "/auth" are routed to Target Group B.
A listener listens for incoming connections on a specified protocol and port, matches incoming requests to the defined rules, and then forwards them to the appropriate target group.
Health Checks and Target Registration
After registering your targets with a target group, configure health checks to continuously monitor their performance. The ELB sends periodic health check requests via HTTP, HTTPS, or TCP. If a target does not return the expected response, it is marked as unhealthy and removed from the traffic routing until it passes health checks again.
Connection Draining
Connection draining enables you to gracefully deregister targets from the ELB. For example, if an EC2 instance needs to be removed (manually or due to failing health checks), connection draining ensures that existing connections are allowed to complete before deregistration occurs. During this period, no new requests are sent to the draining instance.
Tip
Connection draining helps maintain session integrity during scaling events and minimizes the impact of instance deregistration on end users.
Types of Elastic Load Balancers
AWS offers three main types of load balancers, each designed for specific use cases:
- Application Load Balancer (ALB):
Optimized for HTTP and HTTPS traffic with advanced routing capabilities. - Network Load Balancer (NLB):
Ideal for handling TCP traffic with low latency and high performance. - Gateway Load Balancer:
Provides a single entry point for routing traffic to a fleet of third-party virtual appliances.
Summary
- ELBs efficiently distribute incoming traffic across multiple servers using a single DNS entry, while supporting various backend platforms such as EC2, Lambda, ECS, and IP addresses.
- They are designed for high availability, offering multi-AZ deployments and the option for public or private configurations.
- Target groups serve as logical links between the ELB and backend resources, with health checks ensuring that traffic is only routed to healthy instances.
- Listeners and listener rules determine how incoming requests are processed and directed.
- Cross-zone load balancing promotes an even traffic distribution, independent of the number of instances in each Availability Zone.
- Connection draining allows for the graceful removal of targets, ensuring that existing connections are not abruptly severed.
- AWS provides three distinct load balancer types—Application, Network, and Gateway—to suit a variety of application requirements.
With this comprehensive overview, you now have a clear understanding of the functionality and configuration options of Elastic Load Balancers, as well as the importance of features like health checks, cross-zone load balancing, and connection draining in creating a resilient and scalable AWS architecture.
For further details and best practices on AWS load balancing, refer to the AWS Documentation.
Watch Video
Watch video content