0
0
AwsConceptBeginner · 4 min read

What is Elastic Load Balancer in AWS: Simple Explanation and Example

An AWS Elastic Load Balancer (ELB) automatically distributes incoming application traffic across multiple targets like servers or containers to improve availability and fault tolerance. It acts like a traffic manager that ensures no single server gets overwhelmed, making your app more reliable and scalable.
⚙️

How It Works

Imagine a busy restaurant with many customers arriving at once. Instead of letting all customers crowd one waiter, the restaurant manager directs each customer to different waiters to keep service smooth and fast. AWS Elastic Load Balancer works similarly by directing incoming internet traffic to multiple servers behind the scenes.

The ELB listens for requests and then sends each request to a healthy server that can handle it. If one server is busy or down, ELB automatically stops sending traffic to it and balances the load among the remaining servers. This way, your application stays available and responsive even if some servers fail or get overloaded.

💻

Example

This example shows how to create a simple Application Load Balancer using AWS CLI that listens on port 80 and forwards traffic to a target group of EC2 instances.

bash
aws elbv2 create-load-balancer --name my-load-balancer --subnets subnet-12345678 subnet-87654321 --security-groups sg-12345678

aws elbv2 create-target-group --name my-targets --protocol HTTP --port 80 --vpc-id vpc-12345678

aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:region:account-id:targetgroup/my-targets/1234567890abcdef --targets Id=i-1234567890abcdef0 Id=i-0abcdef1234567890

aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:region:account-id:loadbalancer/app/my-load-balancer/1234567890abcdef --protocol HTTP --port 80 --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:region:account-id:targetgroup/my-targets/1234567890abcdef
Output
Creates an Application Load Balancer named 'my-load-balancer' that listens on port 80 and forwards requests to the target group 'my-targets' containing specified EC2 instances.
🎯

When to Use

Use an Elastic Load Balancer when you want to improve your application's availability and handle more users without slowing down. It is perfect for websites, APIs, or apps that run on multiple servers and need to stay online even if some servers fail.

For example, if you run an online store, ELB helps by spreading customer requests across many servers so the site stays fast during sales. It also automatically detects unhealthy servers and stops sending traffic to them, keeping your service reliable.

Key Points

  • ELB distributes incoming traffic to multiple healthy servers automatically.
  • It improves fault tolerance by detecting and avoiding unhealthy servers.
  • Supports different types: Application Load Balancer, Network Load Balancer, and Gateway Load Balancer.
  • Helps scale applications smoothly as user demand grows.
  • Works with EC2 instances, containers, and IP addresses as targets.

Key Takeaways

AWS Elastic Load Balancer automatically spreads traffic across multiple servers to keep apps available and fast.
It detects unhealthy servers and stops sending them traffic to avoid downtime.
Use ELB to scale your app and handle more users without slowing down.
There are different ELB types for different needs: Application, Network, and Gateway Load Balancers.
ELB works with various targets like EC2 instances, containers, and IP addresses.