
AWS Load Balancer: Complete Beginner-Friendly Guide
When an application becomes popular, many users may access it at the same time. Sending all traffic to a single server can overload the server and cause slow performance or downtime.
What Is an AWS Load Balancer?
An AWS Load Balancer is a managed service that distributes incoming application traffic across multiple targets, such as EC2 instances.
A simple architecture looks like this:
1
2
3
4
5
6
7
Users
|
v
Load Balancer
/ | \
v v v
EC2-1 EC2-2 EC2-3Instead of users connecting directly to one server, they connect to the Load Balancer.
The Load Balancer then forwards requests to appropriate backend targets.
Why Do We Need a Load Balancer?
A Load Balancer provides several important benefits:
- High Availability – traffic can be distributed across multiple servers.
- Scalability – applications can handle increasing traffic more effectively.
- Fault Tolerance – unhealthy servers can be removed from normal traffic.
- Better Performance – requests are distributed instead of overloading one server.
- Health Checks – AWS can continuously check the health of registered targets.
- Security – the Load Balancer can act as the public entry point while backend servers remain more restricted.
Types of AWS Load Balancers
AWS provides different types of Elastic Load Balancing for different use cases.
1. Application Load Balancer (ALB)
The Application Load Balancer works at the application layer, commonly called Layer 7.
It is commonly used for:
- HTTP/HTTPS applications
- Web applications
- REST APIs
- Microservices
- Path-based routing
- Host-based routing
Example:
1
2
3
4
5
6
7
8
User
|
v
ALB
|
+----> Web Servers
|
+----> API Servers2. Network Load Balancer (NLB)
The Network Load Balancer operates primarily at Layer 4.
It is designed for high-performance network traffic such as TCP and UDP.
It is useful when applications require:
- Very high performance
- Low latency
- TCP traffic
- UDP traffic
- TLS traffic
3. Gateway Load Balancer (GWLB)
The Gateway Load Balancer is designed for deploying, scaling, and managing network security appliances.
Examples include:
- Firewalls
- Intrusion Detection Systems
- Intrusion Prevention Systems
- Other network inspection appliances
Understanding Application Load Balancer (ALB)
For beginners working with AWS web applications, ALB is especially important.
A typical ALB architecture looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
Internet
|
v
Application Load
Balancer
|
Listener
|
Target Group
/ \
v v
EC2-1 EC2-2
Apache ApacheLet's understand each component.
1. Load Balancer
The Load Balancer is the entry point for incoming application traffic.
Users access the Load Balancer instead of directly accessing individual EC2 instances.
2. Listener
A Listener checks for incoming connection requests on a specific protocol and port.
Common examples are:
1
2
HTTP → Port 80
HTTPS → Port 443For example:
1
2
3
4
5
6
Internet
|
v
ALB
|
+---- HTTP Listener :803. Listener Rules
Listener rules determine how the ALB should handle incoming requests.
For example:
1
2
IF path = /api
THEN send traffic to API Target GroupAnother example:
1
2
IF host = shop.example.com
THEN send traffic to Shop Target GroupThis makes ALB useful for applications containing multiple services.
4. Target Group
A Target Group contains the backend targets that receive traffic from the Load Balancer.
For example:
1
2
3
4
5
6
7
Target Group
|
+---- EC2-1
|
+---- EC2-2
|
+---- EC2-3The ALB forwards requests to targets registered in the appropriate Target Group.
5. Targets
Targets are the backend resources that actually run your application.
For a simple AWS lab, your targets might be:
1
2
EC2-1 → Apache Web Server
EC2-2 → Apache Web Server6. Health Checks
Health checks are one of the most important Load Balancer features.
The Load Balancer checks whether registered targets are healthy.
For a simple web server, the health check path is commonly:
1
/Example:
1
2
3
4
5
6
7
ALB
|
+---- EC2-1 → Healthy
|
+---- EC2-2 → Healthy
|
+---- EC2-3 → UnhealthyIf a target becomes unhealthy, the Load Balancer can stop sending normal traffic to that target.
Security Groups with an ALB
A good architecture is to allow users to reach the ALB while restricting direct access to the EC2 instances.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
Internet
|
| HTTP/HTTPS
v
ALB-SG
|
| HTTP
v
EC2-SG
|
v
EC2 InstancesThe ALB Security Group can allow HTTP/HTTPS from the Internet.
The EC2 Security Group can allow HTTP traffic only from the ALB Security Group.
This helps prevent users from directly accessing the backend servers.
HTTP, HTTPS, SSL and TLS
For web applications, you will often see:
1
2
HTTP → Port 80
HTTPS → Port 443HTTPS uses TLS encryption to protect data in transit.
People often say "SSL certificate," but modern HTTPS uses TLS. SSL is the older protocol family.
With an ALB, TLS can be terminated at the Load Balancer.
For example:
1
2
3
4
5
6
7
8
9
User
|
| HTTPS
v
ALB
|
| HTTP
v
EC2The ALB handles the client TLS connection.
You can also configure encrypted traffic between the ALB and backend targets when your architecture requires it:
1
2
3
4
5
6
7
8
9
User
|
| HTTPS
v
ALB
|
| HTTPS
v
EC2AWS Certificate Manager (ACM) can be used to manage certificates for HTTPS listeners.
ALB Path-Based Routing
One powerful ALB feature is path-based routing.
For example:
1
2
3
4
example.com/api
|
v
API Target GroupWhile:
1
2
3
4
example.com/images
|
v
Image Target GroupThis allows different parts of an application to use different backend services.
ALB Host-Based Routing
ALB can also route traffic based on the hostname.
For example:
1
2
3
4
api.example.com
|
v
API Target Groupand:
1
2
3
4
www.example.com
|
v
Web Target GroupThis allows multiple applications or services to share the same Load Balancer.
ALB with Auto Scaling
A common production architecture combines:
ALB + Target Group + Auto Scaling Group + EC2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Users
|
v
ALB
|
v
Target Group
|
+----------+----------+
| | |
EC2 EC2 EC2
^ ^ ^
| | |
+---- Auto Scaling ---+When traffic increases, Auto Scaling can launch additional instances according to the configured scaling policy.
The Load Balancer can then distribute traffic among healthy targets.
Simple AWS ALB Lab
A beginner-friendly lab can be built using:
- 2 EC2 instances
- Apache Web Server
- 1 Target Group
- 1 Application Load Balancer
- 2 Security Groups
You can use EC2 User Data to install Apache automatically, so you do not need to manually SSH into the instances just to install the web server.
Example User Data:
1
2
3
4
5
6
7
8
9
apt update -y
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
echo "<h1>Hello from EC2 Server</h1>" > /var/www/html/index.htmlYou can customize each server with a different message:
1
2
EC2-1 → Hello from Server 1
EC2-2 → Hello from Server 2Then access the ALB DNS name in your browser.
Complete ALB Traffic Flow
The easiest way to remember an ALB is:
1
2
3
4
5
6
7
8
9
10
11
12
13
User
↓
Load Balancer
↓
Listener
↓
Listener Rule
↓
Target Group
↓
Healthy Target
↓
ApplicationFor HTTPS:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
User
↓
HTTPS :443
↓
ALB
↓
TLS Termination
↓
Listener
↓
Target Group
↓
EC2
↓
ApplicationALB vs NLB
| Feature | ALB | NLB |
|---|---|---|
| Main Layer | Layer 7 | Layer 4 |
| HTTP/HTTPS | Yes | Yes |
| TCP | Not its primary focus | Yes |
| UDP | No | Yes |
| Path-based routing | Yes | No |
| Host-based routing | Yes | No |
| Application-aware routing | Yes | No |
| High-performance network traffic | Not its primary purpose | Yes |
Easy way to remember:
ALB = Application
NLB = Network
Final Takeaway
An AWS Load Balancer is an important service for building highly available and scalable applications.
The most important ALB concepts to remember are:
1
2
3
4
5
6
7
8
9
10
11
ALB
↓
Listener
↓
Listener Rule
↓
Target Group
↓
Targets
↓
Health ChecksOnce you understand this sequence, you have a strong foundation for learning more advanced AWS architectures such as:
- ALB + Auto Scaling
- ALB + Route 53
- ALB + HTTPS/TLS
- ALB + ACM
- ALB + ECS
- ALB + Microservices
The simple idea is:
The Load Balancer receives the traffic, checks the available targets, and sends the request to a healthy backend server.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article