AWS Elastic Load Balancer

Sumant Mishra
5 min readJan 18, 2019

Amazon Elastic Load balancing is a highly available service that distributes incoming traffics across healthy Amazon EC2 instances (targets) in multiple Availability Zones and includes options that provide flexibility and control of incoming requests to Amazon EC2 instances.

Think of a popular content distribution platform which enables publishers, authors and content providers to create, sell, manage and deliver their digital content over the internet. Millions of users login every day, receive millions of requests every second and lots of download requests. How do such high usage platforms manage incoming traffic, while making the system fault tolerant, highly available and cost-effective.

Amazon Elastic Load Balancing is a service which increases the fault tolerance of applications, detects unhealthy instances and routes incoming traffics to only healthy instances. An advantage of having access to a large number of EC2 instances on AWS is the ability to provide a more consistent experience to the end user. Consistency can be ensured by balancing the traffic load across more than one server.

Amazon Elastic Load Balancing supports routing and load balancing of HTTP, HTTPS, TCP and SSL traffic to Amazon EC2 instances. Elastic Load Balancing provides a stable, single Canonical Name record (CNAME) entry point for Domain Name System(DNS) configuration and supports both health checks for Amazon EC2 instances to ensure traffic is not routed to unhealthy instances. Also, Elastic Load Balancing can scale in and out automatically to meet the demands of increased application traffic and is highly available within a region itself as a service.

Configuration

To configure a load balancer, target groups are created, and then targets are registered with target groups. Load balancers are most effective if it is ensured that each Availability Zone has at least one registered target. Listeners are created to check connection requests from clients.

Target groups

Target groups are used to route requests to one or more registered targets. At the time of creating listener rules, target groups, target type and conditions are specified. Traffic is forwarded to the corresponding target group when a rule condition is met. There are two possible target types:

  • Instance: The targets can be specified by Instance ID
  • IP: The targets can be specified by IP

In case of IP target types, IP addresses can be specified from one of the following CIDR (Classless Inter-Domain Routing) blocks:

  • The VPC subnets for the target group
  • 10.0.0.0/8 (RFC 1918)
  • 100.64.0.0/10 (RFC 6598)
  • 172.16.0.0/12 (RFC 1918)
  • 192.168.0.0/16 (RFC 1918)

Listeners

Amazon Each Load Balancer must have one or more listeners configured. Listeners check for connection requests, for example, a CNAME configured to the A record name of the load balancer.

Each listener is configured with a protocol and a port. When a listener is configured, a rule is specified for routing requests which forwards requests to the specified target group.

Health Checks

To check the status of EC2 instances, load balancer periodically pings, attempts connections and sends requests to EC2 instances. This process of status checking is termed as Health Checks. Status of healthy instances are marked as InService and for unhealthy instances OutOfService. Load balancers route traffic to only healthy instances and stop routing requests to unhealthy instances. But Load Balancers continue to perform Health Check on all registered instances.

Sticky Sessions

By default, Load Balancers distribute incoming traffic evenly across instances. But with the Sticky Session feature, it is possible to instruct Load Balancer and send all the requests for a session can be sent to one EC2 instance.

Load Balancer State

A load balancer can be in one of the following three states:

  • provisioning: The load balancer set up is in process
  • active: The load balancer is ready to route incoming traffics.
  • failed: The load balancer failed to set up.

Cross-Zone Load Balancing

By default, each load balancer node distributes incoming traffic evenly across the registered targets in its Availability Zone only. To make sure that incoming traffic is routed evenly across all the registered targets in all Availability Zones, Cross-Zone load balancing needs to be enabled.

For higher fault tolerance, it is recommended to maintain approximately equivalent numbers of instances in each Availability Zone.

Deletion Protection

To prevent load balancers from being deleted accidentally, deletion protection can be enabled. By default, deletion protection is disabled. Deletion protection must be disabled before deleting the load balancer.

Connection Idle Timeout

When a client sends a request through a Load balancer, it maintains two connections. For each connection, Load balancer manages an idle timeout. If no data is sent or received by the time that the idle timeout period elapses, the load balancer closes the connection.

By default, 60 seconds is set as an idle timeout for each connection by Elastic Load Balancers.

Types of Load Balancers

Amazon Elastic Load Balancing supports three types of load balancers:

  • Classic Load Balancers
  • Application Load Balancers
  • Network Load Balancers

Classic Load Balancer

A Classic Load Balancer distributes incoming traffics evenly across multiple healthy EC2 instances. Enabling Cross-Zone Load Balancing distributes traffic evenly across all registered instances in all enabled Availability Zones. This reduces fault tolerance. Load balancers serve as a single point of contact and all incoming traffic routed through Load balancers which increases the availability of applications.

It is recommended to choose Classic Load Balancer when an existing application is running in the EC2-Classic Network.

Application Load Balancer

Application Load Balancers function at the seventh layer (application layer) of the Open Systems Interconnections (OSI) model. Application Load Balancers operate at request level and provide advanced routing. Listeners check for connection requests from clients and then forwards requests to one or more target groups based on the defined rules. Each rule is configured with a target group, condition and priority. It is recommended to define a default rule for each listener. Application Load Balancers evaluate the rules in priority order and forward the traffic to the target group only when the condition is met. Targets can be added or removed from the Load Balancers depending on the need without disrupting the flow of traffic to the application.

It is recommended to choose an Application Load Balancer when a flexible feature set for web applications with HTTP and HTTPS traffic is needed.

Network Load Balancers

Network Load Balancers function at the fourth layer of the Open Systems Interconnection (OSI) model. NLBs operate at connection level and are capable of handling millions of requests per second. On receiving a connection request it opens a TCP connection to the selected target on the port specified in the listener configuration. It is recommended to choose a Network Load Balancer when ultra-high performance and static IP addresses are needed for an application.

References

The best reference for further readings on Elastic Load Balancing is AWS documentation:
Elastic Load Balancing Documentation

--

--

Sumant Mishra

Fullstack Architect || TOGAF 9 || AWSCSAA || Cloud Practitioner || NodeJS || React & Angular || Docker || Coder