AWS Builder Center

AWS Load Balancer Explained: How Traffic Reaches Your Applications

Understanding Elastic Load Balancing, Application Load Balancers, Network Load Balancers, and high availability in AWS.

AWS Load Balancer Explained: How Traffic Reaches Your Applications

1. Introduction

When deploying an application to AWS, launching an EC2 instance is often one of the first steps. But what happens when your application starts receiving thousands of requests? What if one server becomes overloaded or stops responding?
Running an application on a single server can create a bottleneck and a single point of failure. To build applications that can handle changing traffic and recover from individual server failures, we need a way to distribute requests across multiple targets.
This is where AWS Elastic Load Balancing (ELB) becomes important.
ELB automatically distributes incoming traffic across configured targets, such as EC2 instances, containers, and IP addresses. It works with other AWS services to help build scalable and highly available application architectures.

2. How AWS Elastic Load Balancing Works

A load balancer acts as the entry point for incoming application traffic. Instead of clients communicating directly with individual application servers, they send requests to the load balancer's endpoint.
The load balancer then routes requests to registered targets according to the selected load balancer type, listener rules, target health, and other configuration settings.
Consider a web application deployed on multiple EC2 instances:
1
2
3
4
5
6
7
8
9
10
11
12
13
Users
|
v
Application Load Balancer
|
+-------+-------+
| | |
v v v
EC2-A EC2-B EC2-C
| | |
+-------+-------+
|
Application Services
In this architecture:
  • Listener: Checks for incoming connection requests on a configured protocol and port, such as HTTPS on port 443.
  • Listener rules: Determine how requests should be routed, where supported by the load balancer type.
  • Target group: Organizes the registered targets that receive traffic.
  • Health checks: Help determine whether registered targets are healthy enough to receive requests.
For example, if EC2-B fails its health checks, the load balancer can stop routing requests to it while suitable healthy targets remain available.
One important point: a load balancer does not automatically create additional EC2 instances. It distributes traffic among the targets configured for it.

3. Understanding the Main AWS Load Balancer Types

AWS provides different load balancer types because applications have different networking and routing requirements.

Application Load Balancer (ALB)

An Application Load Balancer operates at Layer 7 of the OSI model, the application layer. It is designed for HTTP and HTTPS traffic.
Its main advantage is application-aware routing. It can route requests using information such as URL paths, hostnames, and HTTP headers.
For example, an application might use these rules:
  • example.com/products → Product service
  • example.com/orders → Order service
  • api.example.com → API service
This approach is useful for websites, REST APIs, and applications built using multiple services.

Network Load Balancer (NLB)

A Network Load Balancer operates at Layer 4, the transport layer. It handles connections using protocols such as TCP, UDP, and TLS.
Unlike an ALB, it does not use HTTP paths to decide where to send a request. Instead, it operates using network and transport-layer information.
NLB is useful when applications require high-performance connection handling, support for particular network protocols, or static IP addresses.

ALB vs NLB

CapabilityApplication Load BalancerNetwork Load Balancer
OSI layerLayer 7Layer 4
Routing decisionsApplication-level informationNetwork and transport-level information
Common use casesWebsites, HTTP APIs, microservicesHigh-performance TCP/UDP/TLS workloads
Path-based routingSupportedNot supported
Static IP addressesTypically accessed through its DNS nameSupports static IP addresses per enabled Availability Zone
Practical rule: Choose ALB when you need HTTP-aware routing. Consider NLB when you need Layer 4 traffic handling or its specific networking capabilities.

4. Integrating a Load Balancer with EC2 Auto Scaling

A load balancer becomes more powerful when combined with Amazon EC2 Auto Scaling.
These services solve different problems:
  • Elastic Load Balancing distributes incoming traffic across registered targets.
  • EC2 Auto Scaling adjusts the number of EC2 instances according to configured scaling policies and conditions.
For example, imagine an online store experiences a major increase in visitors during a seasonal sale.
  1. The load balancer distributes incoming requests across the registered application instances.
  2. Monitoring metrics indicate that demand has increased.
  3. EC2 Auto Scaling launches additional instances if the configured scaling policies require them.
  4. The new instances become eligible to receive traffic after registration and successful health checks.
  5. When demand decreases, Auto Scaling can remove instances according to its scale-in policies.
This creates a more flexible architecture than relying on a fixed number of servers.
However, Auto Scaling does not instantly respond to every traffic spike. Scaling behavior depends on the selected metrics, thresholds, cooldown or warm-up settings, and instance launch time.

5. Designing for High Availability Across Availability Zones

A load balancer alone does not guarantee high availability. The architecture behind it matters just as much.
For a more resilient design, you can enable the load balancer across multiple Availability Zones and deploy application targets in more than one zone.
1
2
3
4
5
6
7
8
Users
|
v
AWS Load Balancer
/ \
v v
Availability Zone A Availability Zone B
EC2-A, EC2-B EC2-C, EC2-D
If a target becomes unhealthy, the load balancer can route requests to other healthy targets. Distributing targets across Availability Zones can also reduce dependence on a single zone.
For stronger resilience, the application should be designed to avoid depending on local state stored on only one instance. Shared data stores, appropriate session handling, and resilient downstream services may also be necessary.

6. Security and Monitoring Considerations

Load balancing is not only about distributing requests. It is also part of the application's networking and security design.
Consider these practices:
  • Use HTTPS: Configure TLS termination and certificates appropriately, often using AWS Certificate Manager.
  • Restrict network access: Configure security groups and target access so application instances accept traffic only from intended sources.
  • Monitor performance: Use Amazon CloudWatch metrics to observe request volume, latency, healthy targets, and errors.
  • Configure health checks carefully: Choose suitable paths, protocols, ports, and thresholds so health checks reflect the application's readiness.
  • Review access logs: Where supported and enabled, use load balancer access logs to investigate traffic patterns and troubleshoot requests.
The correct configuration depends on the load balancer type and the application's requirements.

7. Common Mistakes to Avoid

Mistake 1: Assuming a load balancer creates more servers.
A load balancer distributes traffic; EC2 Auto Scaling or another provisioning mechanism is responsible for adding capacity.
Mistake 2: Deploying every target in one Availability Zone.
This can leave the application dependent on that zone. Consider a multi-AZ architecture where appropriate.
Mistake 3: Ignoring unhealthy targets.
Misconfigured health checks may cause healthy applications to be marked unhealthy, or unhealthy applications to continue receiving traffic.
Mistake 4: Choosing a load balancer without considering the protocol.
ALB and NLB support different routing capabilities. Select the type based on the application's traffic and networking requirements.
Mistake 5: Forgetting cost.
Load balancers can incur charges based on the selected type, usage, and region. Check current AWS pricing before deploying a production architecture.

8. Conclusion

AWS Elastic Load Balancing is a key component in building scalable and resilient cloud applications. It provides a managed entry point for application traffic and routes requests to registered targets based on the load balancer type and configuration.
Understanding how ELB works with EC2, target groups, health checks, Availability Zones, and Auto Scaling helps you make better architecture decisions.
For a practical learning project, try deploying a small web application on two EC2 instances, placing an Application Load Balancer in front of them, configuring health checks, and observing what happens when one instance becomes unhealthy.
The goal is not just to run an application in the cloud, but to design it so that it can handle traffic and recover from failures.

#AWS #ElasticLoadBalancing #ApplicationLoadBalancer #NetworkLoadBalancer #AmazonEC2 #AutoScaling #CloudArchitecture #DevOps
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article