Optimizing Performance on AWS: An Overview of AWS Elastic Load Balancing

Christopher Adamson
7 min readSep 17, 2023

--

As applications grow, it becomes increasingly important to distribute traffic across multiple servers to optimize performance, availability, and scalability. AWS Elastic Load Balancing (ELB) is a service that automatically distributes incoming application traffic across multiple targets and virtual appliances. ELB offers several load balancing solutions that provide various levels of availability, scalability, and management.

In this article, we will provide an overview of AWS Elastic Load Balancing and how it can be used to improve performance on AWS. We will cover the different types of load balancers offered, key features, and best practices for implementation.

Types of Elastic Load Balancers

AWS offers three types of load balancers:

Application Load Balancer

The Application Load Balancer is one of the key load balancing solutions offered by Elastic Load Balancing. It is ideal for

load balancing HTTP and HTTPS traffic and provides advanced request routing targeted at modern application architectures.

Some key features of the Application Load Balancer:

· Operates at layer 7 and can make routing decisions based on advanced content like headers, HTTP method, query string parameters, etc. This enables very fine-grained control over traffic.

· Supports path-based and host-based routing to route to different target groups based on the URL path or host field in the request. Useful for routing microservices traffic.

· Integrated with many AWS services like ECS, Lambda, CodeDeploy, WAF, Access Logs, AWS Certificate Manager, and AWS Global Accelerator.

· Offers ports 80 and 443 forHTTP and HTTPS along with support for HTTP/2 and websocket protocols.

· Can insert headers like X-Forwarded-For containing connection information.

· Provides metrics and access logs for monitoring and troubleshooting.

· Offers security through integrated firewalls, TLS termination, and validation of target health.

· Highly scalable and can handle volatile workloads with fast scaling. Can distribute loads across multiple AZs.

Some best practices when using Application Load Balancers:

· Enable access logging and monitoring from the start

· Stick to default security groups and lock down access

· Use multiple target groups for routing microservices

· Spread load balancer nodes across AZs for higher availability

· Configure health checks appropriate for your application

· Consider using WAF to protect against web attacks

With robust features tailored to modern applications, the Application Load Balancer should be considered for most HTTP/HTTPS workloads running on AWS.

Network Load Balancer

The Network Load Balancer operates at the connection level (Layer 4) and can handle millions of requests per second. Some key features include:

· Ideal for load balancing TCP and UDP traffic. Supports ports 25, 80, 443, 1024–65535.

· Capable of handling volatile workloads and provides high throughput and low latency.

· Integrated with various AWS services like Auto Scaling, Lambda, CodeDeploy, Access Logs.

· Uses static IP addresses for the load balancer nodes. This aids in whitelisting and firewall rules.

· Supports Elastic IPs and preserves source IP addresses for backend servers.

· Utilizes cross-zone load balancing to distribute traffic evenly across targets in enabled Availability Zones.

· Offers robust monitoring and metrics through CloudWatch. Can load test using generated traffic.

· Highly scalable and capable of massive load spikes. Can scale target groups dynamically.

Best practices for using Network Load Balancers:

· Enable access logs for monitoring and troubleshooting.

· Spread load balancer nodes across AZs for better fault tolerance.

· Configure health checks based on your workload protocols.

· Use NLB with Auto Scaling groups for scaling target servers.

· Consider Vaccinating target groups when migrating traffic or updating applications.

· Use separate NLBs for public and private traffic isolation.

With high performance, low overhead, and dynamic scaling capabilities, Network Load Balancers are ideal for TCP and UDP traffic that needs massive scale and throughput. Perfect for distributed workloads using UDP protocols.

Classic Load Balancer

The Classic Load Balancer was the original Elastic Load Balancing offering by AWS. It operates at either the transport layer (Layer 4) or application layer (Layer 7). Some key aspects:

· Supports both HTTP/HTTPS and TCP/SSL protocols for routing decisions.

· Can load balance EC2 instances, containers, IP addresses, Lambda functions.

· Offers basic load balancing algorithms like round robin, least outstanding requests, random.

· Health checks can be TCP, HTTP/HTTPS, HTTP Code, SSL Negotiation.

· Sticky sessions can bind users to specific backend instance.

· Cross-zone load balancing spreads traffic more evenly across enabled Availability Zones.

· Provides access logs and monitoring through CloudWatch metrics.

· Scales automatically to meet traffic demands.

· Integrates with Auto Scaling, Route 53, ECS, and AWS certificate manager.

Best practices for Classic Load Balancers:

· Enable access logging for auditing requests.

· Configure multiple listeners for separating traffic.

· Use multiple CLBs for isolation between public and private.

· Ensure health check settings match your application needs.

· Spread load balancer nodes across all Availability Zones.

· Upgrade to Network or Application LB if possible.

While Classic Load Balancers are still supported, Network and Application LB provide more features and flexibility around monitoring, security, and microservices deployments. Consider upgrading legacy CLBs.

Key Features

Some key features offered by Elastic Load Balancing include auto scaling, where load balancers can automatically scale up or down based on traffic demands to maintain maximum performance during spikes and reduce costs during lulls. Load balancers also perform automatic health checks on targets and only send traffic to healthy resources, automatically removing unhealthy instances until restored. Elastic Load Balancers provide high availability by operating regionally to reduce the impact of an availability zone outage. Finally, ELBs integrate with other AWS security services like security groups and VPCs and utilize SSL/TLS encryption for secure connections.

Best Practices

To optimize performance on AWS using Elastic Load Balancing, some best practices include offloading TLS termination by using load balancers to handle encryption/decryption allowing backend servers to focus on application delivery. Also, distribute load balancer nodes across multiple availability zones to increase fault tolerance. Using separate load balancers for public and private traffic isolates loads. Enabling access logs provides valuable data for monitoring and troubleshooting. Finally, utilize auto scaling by configuring autoscaling policies based on load balancer metrics like requests/connections per target.

Tutorial

In this tutorial, we will walk through setting up Elastic Load Balancing (ELB) to improve performance and availability of applications on AWS. ELB automatically distributes incoming traffic across multiple EC2 instances which allows you to achieve greater levels of fault tolerance and optimized performance.

Prerequisites

Before starting, make sure you have the following:

· An AWS account

· EC2 instances created in at least two Availability Zones

· Appropriate IAM permissions to create ELB resources

Steps

1. Determine the type of load balancer

Based on your traffic type, decide if you need an Application Load Balancer for HTTP/HTTPS or a Network Load Balancer for TCP/UDP. Application LB is ideal for most web workloads.

2. Create the load balancer

In the EC2 console, go to Load Balancers and click Create Load Balancer. Select the balancer type and choose internet-facing or internal.

3. Configure load balancer settings

Give the ELB a name, select the VPC and subnets to deploy it in, and configure security groups, health checks and any advanced settings.

4. Register EC2 target instances

On the Add EC2 Instances page, select the instances to register with the load balancer. The instances should cover multiple AZs.

5. Configure listeners

Listeners check for connection requests and forwards them to targets. Create HTTP/HTTPS listeners for App LB or TCP/UDP for Network LB.

6. Distribute traffic with listeners

You can send traffic to different target groups from each listener to distribute specific traffic types.

7. Verify load balancer configuration

Check your DNS name assigned to the ELB and test traffic is forwarded to EC2 instances. You can also view access logs.

8. Consider auto scaling groups

Combine ELB with auto scaling groups that can automatically add or remove EC2 instances based on demand.

Following these steps allows you to leverage Elastic Load Balancing to distribute loads across EC2 instances for better performance and availability. Make sure to follow ELB best practices around spreading resources across AZs, enabling access logs, and configuring health checks. Refer to the AWS documentation for additional tips and configuration options.

AWS CLI Examples for Elastic Load Balancing

Here are some AWS CLI examples that could be included in the Elastic Load Balancing tutorial:

Create an application load balancer

Register targets with the load balancer

Create a listener for the load balancer

Configure a health check

Create an auto scaling group

These examples demonstrate some common CLI commands for creating and configuring core ELB components like the load balancer itself, target registrations, listeners, health checks and integrating with auto scaling. Refer to the AWS CLI reference documentation for additional options.

Conclusion

Elastic Load Balancing provides a managed, automated way to distribute loads across targets for better performance, availability, and scalability on AWS. Following load balancing best practices allows you to optimize workloads even as traffic fluctuates. Combining Elastic Load Balancing with other AWS services creates a powerful, robust infrastructure for delivering applications.

--

--