DEV Community

Cover image for ๐Ÿš€Amazon ELB Demystified: Your Ultimate Guide to Routing Traffic & Scaling Apps in AWS (2025 Edition)
PHANI KUMAR KOLLA
PHANI KUMAR KOLLA

Posted on

๐Ÿš€Amazon ELB Demystified: Your Ultimate Guide to Routing Traffic & Scaling Apps in AWS (2025 Edition)

Okay, fellow cloud enthusiasts and Dev.to community! As someone who's been navigating the AWS cloud for over three plus years and loves helping others "get it," I'm thrilled to tackle a foundational yet incredibly powerful service: Amazon Elastic Load Balancing (ELB). Whether you're just starting your cloud journey or you're a seasoned pro looking to fine-tune your architecture, understanding ELB is key to building resilient, scalable, and high-performing applications.

Let's dive in!

Ever had your awesome application buckle under unexpected traffic? ๐Ÿ˜ฌ Your users see a dreaded error page, your team scrambles, and that crucial launch... well, it doesn't go as planned. We've all been there or heard the horror stories.

In today's fast-paced digital world, application availability and performance are non-negotiable. Customers expect seamless experiences, and businesses rely on their applications to be up and running 24/7. That's where Amazon Elastic Load Balancing (ELB) steps in as a critical hero in your AWS architecture. It's the traffic cop, the resilience booster, and the scalability enabler, all rolled into one managed service.

This deep dive will equip you with everything you need to know about ELB: from the absolute basics to advanced tips, helping you choose the right load balancer, configure it effectively, and avoid common pitfalls. By the end, you'll be ready to route traffic like a pro!

Table of Contents


Why Elastic Load Balancing Matters

In today's cloud-native world, applications are rarely monolithic giants running on a single, oversized server. Instead, we build distributed systems, microservices, and containerized applications designed for resilience and agility. Amazon ELB is a cornerstone service that makes this modern approach feasible and manageable.

Here's why it's so crucial:

  • High Availability & Fault Tolerance: ELB automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers (ECS/EKS), Lambda functions, and IP addresses, in multiple Availability Zones (AZs). If one instance or AZ goes down, ELB reroutes traffic to healthy ones, keeping your application online.
  • Scalability: As traffic to your application changes, ELB automatically scales its request-handling capacity. Coupled with Auto Scaling groups for your backend fleet, you can achieve true elasticity, handling peak loads gracefully and scaling down to save costs during quieter periods.
  • Improved Security: ELB provides a secure frontend for your applications. You can terminate SSL/TLS connections at the load balancer, offloading this work from your backend instances. Integration with AWS WAF (Web Application Firewall) on ALBs adds another layer of protection against common web exploits. Security Groups for ELBs and targets allow fine-grained traffic control.
  • Simplified Operations: ELB is a managed service. AWS handles the provisioning, maintenance, and scaling of the load balancing infrastructure, so you don't have to. This frees up your team to focus on building features, not managing infrastructure.

According to recent cloud trends, the adoption of microservices and serverless architectures continues to surge. ELB, particularly Application Load Balancers, is pivotal in routing traffic effectively within these complex environments. AWS continuously enhances ELB; for instance, features like attribute-based instance selection and improved integrations are regularly rolled out, underscoring its dynamic role in the AWS ecosystem.

Image 1


What's a Load Balancer? Understanding ELB in Simple Terms

Okay, let's break it down. What exactly is a load balancer?

Imagine a popular restaurant on a busy Saturday night. If there was only one host trying to seat everyone, greet people, and manage the waiting list, things would quickly become chaotic, and service would be slow.

A load balancer is like a team of super-efficient hosts for your application.
When users try to access your application (send requests), they don't go directly to one of your servers. Instead, they hit the load balancer first. The load balancer then intelligently distributes these incoming requests across a pool of available backend servers (your "targets").

Why is this distribution important?

  • No Single Point of Failure: If one server crashes or needs maintenance, the load balancer simply stops sending traffic to it and uses the other healthy servers. Your users barely notice!
  • Efficient Resource Use: It prevents any single server from being overwhelmed, ensuring smoother performance for everyone.
  • Easy Scaling: Need to handle more traffic? Just add more servers to the pool, and the load balancer will start using them.

In the context of AWS, Elastic Load Balancing (ELB) is a managed service that provides this capability automatically and, well, elastically. It can scale up or down based on demand, ensuring your application remains available and responsive.

Think of it as a smart traffic director for the internet, ensuring requests get to the right place efficiently and reliably.


Deep Dive into Amazon Elastic Load Balancing

Now that we understand the "what" and "why," let's get into the "how" with Amazon ELB. This service isn't just one thing; it's a family of load balancers designed for different needs.

Core ELB Components

Regardless of the ELB type you choose, you'll encounter these fundamental building blocks:

  1. Load Balancer: This is the central resource that receives incoming traffic and distributes it. Each load balancer has a DNS name that your clients use to access your application.
  2. Listeners: A listener checks for connection requests from clients, using the protocol and port that you configure (e.g., HTTP on port 80, HTTPS on port 443). Each load balancer must have at least one listener. You can define rules for listeners (especially with ALBs) to route requests to different target groups.
  3. Target Groups: A target group is used to route requests to one or more registered targets. When you create a listener rule, you specify a target group and conditions. Health checks are configured at the target group level. Targets can be:
    • EC2 instances
    • Containers (via Amazon ECS or EKS)
    • Lambda functions (for ALBs)
    • IP addresses (can be on-premises servers connected via Direct Connect or VPN)
  4. Rules (for Application Load Balancers): Listener rules determine how an ALB routes incoming requests. Each rule consists of a priority, one or more actions, and one or more conditions (e.g., path-based, host-based).

Key Features of ELB

Across the ELB family, you'll find a rich set of features:

  • High Availability: Automatically distributes traffic across multiple Availability Zones within a region.
  • Automatic Scaling: ELB itself scales its capacity up or down based on traffic patterns.
  • Robust Security:
    • Operates within your Amazon Virtual Private Cloud (VPC).
    • Integrates with Security Groups and Network ACLs.
    • SSL/TLS termination (offloading decryption/encryption from backends).
    • Support for AWS Certificate Manager (ACM) for free SSL/TLS certificates.
    • Integration with AWS WAF for ALBs.
  • Monitoring & Logging:
    • Detailed metrics published to Amazon CloudWatch (e.g., request count, latency, error rates).
    • Access Logs provide detailed information about requests sent to your load balancer (can be stored in S3 and analyzed).
  • Connection Draining (Deregistration Delay): Ensures in-flight requests are completed before an instance is deregistered or terminated.

The Critical Role of Health Checks

Health checks are the unsung heroes of load balancing. ELB periodically sends requests (pings, connection attempts, or HTTP GETs to a specific path) to its registered targets to test their status.

  • How they work: If a target fails a specified number of consecutive health checks, ELB marks it as unhealthy and stops sending traffic to it.
  • Recovery: Once a target passes a specified number of consecutive health checks, ELB marks it as healthy again and resumes sending traffic.

Why are they SO important?
Without effective health checks, your load balancer might unknowingly send users to failing or unresponsive application instances, leading to errors and a poor user experience.

Configurable Parameters:

  • Health Check Protocol & Port: HTTP, HTTPS, TCP.
  • Ping Path (for HTTP/S): A specific URL path (e.g., /health or /status).
  • Healthy/Unhealthy Threshold: Number of consecutive successes/failures to change state.
  • Timeout: Time to wait for a response.
  • Interval: Time between health checks.

Pro Tip: Your health check endpoint should be lightweight and accurately reflect the health of the application on the instance, not just if the server is up.

Types of Elastic Load Balancers

AWS offers different types of load balancers, each optimized for specific use cases:

Application Load Balancer (ALB)

  • Layer: Operates at Layer 7 (Application Layer) of the OSI model.
  • Protocols: HTTP, HTTPS, gRPC.
  • Key Features:
    • Advanced Request Routing: Path-based (/api/*, /images/*), host-based (blog.example.com, api.example.com), HTTP header, query string, source IP CIDR based routing.
    • Microservices & Containers: Ideal for routing traffic to services in Amazon ECS, EKS, or EC2 instances running microservices.
    • Lambda as a Target: Invoke Lambda functions via HTTP/S.
    • Sticky Sessions (Target Group Level): Route requests from a specific client to the same target.
    • Redirects & Fixed Responses: Configure rules to redirect HTTP to HTTPS, or return fixed HTTP responses.
    • Authentication: Authenticate users via OIDC or Cognito before routing to targets.
    • WebSockets & HTTP/2 Support.
    • AWS WAF Integration.
  • Use Cases: Modern web applications, microservices, container-based applications, serverless applications.
# Example: Creating a basic Application Load Balancer using AWS CLI
aws elbv2 create-load-balancer \
    --name my-app-alb \
    --type application \
    --subnets subnet-xxxxxxxxxxxxxxxxx subnet-yyyyyyyyyyyyyyyyy \
    --security-groups sg-zzzzzzzzzzzzzzzzz

# Note: You'd then create target groups, listeners, and rules.
Enter fullscreen mode Exit fullscreen mode

Network Load Balancer (NLB)

  • Layer: Operates at Layer 4 (Transport Layer).
  • Protocols: TCP, UDP, TLS.
  • Key Features:
    • Ultra-High Performance: Can handle millions of requests per second with very low latencies.
    • Static IP per AZ: Can be assigned an Elastic IP address per Availability Zone, providing a static frontend IP.
    • Source IP Preservation: Preserves the client-side source IP address (seen by backend instances).
    • Long-Lived Connections: Ideal for applications that require long-lived TCP connections.
    • TLS Termination: Can offload TLS processing from your backend fleet at scale.
  • Use Cases: TCP/UDP based traffic, applications requiring extreme performance and low latency, IoT, gaming, financial trading platforms, situations needing static IPs for whitelisting.
# Example: Creating a basic Network Load Balancer using AWS CLI
aws elbv2 create-load-balancer \
    --name my-network-nlb \
    --type network \
    --scheme internet-facing \
    --subnets subnet-xxxxxxxxxxxxxxxxx subnet-yyyyyyyyyyyyyyyyy

# Note: You'd then create target groups and listeners.
Enter fullscreen mode Exit fullscreen mode

Gateway Load Balancer (GWLB)

  • Layer: Operates at Layer 3 (Network Layer) and Layer 4 (Transport Layer).
  • Protocols: IP (routes all IP packets).
  • Key Features:
    • Deploy, Scale, and Manage Third-Party Virtual Appliances: Designed to integrate virtual appliances like firewalls, Intrusion Detection/Prevention Systems (IDS/IPS), and Deep Packet Inspection (DPI) systems.
    • Transparent Network Gateway: Acts as a single entry and exit point for all traffic for a VPC.
    • Scalability & Resilience for Appliances: Provides these benefits for your fleet of virtual appliances.
  • Use Cases: Centralizing security appliances, traffic inspection, integrating partner network appliances into your AWS environment.

A Note on Classic Load Balancer (CLB)

The Classic Load Balancer is the previous generation of ELB. It provides basic load balancing across multiple EC2 instances and operates at both Layer 4 and Layer 7.

Important: While CLBs still exist for older applications, AWS recommends using Application Load Balancers or Network Load Balancers for new applications due to their richer feature sets, better performance, and more flexible pricing. If you're still using CLB, consider planning a migration!

Selecting Between ELB Types: Making the Right Choice

Choosing the right ELB type is crucial for your application's architecture. Here's a simplified decision guide:

  • Do you need advanced request routing based on content (path, host, headers)? Are you load balancing HTTP/HTTPS/gRPC traffic for web apps, microservices, or containers?
    • โžก๏ธ Application Load Balancer (ALB) is your best bet.
  • Do you need ultra-high performance for TCP/UDP traffic, static IP addresses per AZ, or source IP preservation for non-HTTP traffic?
    • โžก๏ธ Network Load Balancer (NLB) is the way to go.
  • Are you deploying and managing a fleet of third-party virtual network/security appliances (e.g., firewalls, IDS/IPS)?
    • โžก๏ธ Gateway Load Balancer (GWLB) is designed for this.
  • Do you have an existing application using a Classic Load Balancer?
    • โžก๏ธ For new applications, avoid CLB. For existing ones, plan to migrate to ALB or NLB.

Image 2

What factors most influence your choice of load balancer type? Share your thoughts in the comments!


Real-World Use Case: Scaling Microservices with ALB

Let's imagine we're building an e-commerce platform. To make it scalable and maintainable, we've decided on a microservices architecture. We have separate services for:

  • product-catalog-service
  • order-management-service
  • user-profile-service

Each service will be deployed as a set of EC2 instances (or ECS tasks) within an Auto Scaling group.

Challenge: How do we route incoming API requests (e.g., https://api.myecom.com/products, https://api.myecom.com/orders) to the correct microservice and ensure the system is scalable and resilient?

Solution: Application Load Balancer (ALB)

Hereโ€™s a high-level setup:

  1. Create an Application Load Balancer:

    • Choose "application" type.
    • Select your VPC and at least two subnets in different Availability Zones for high availability.
    • Assign a security group that allows inbound traffic on port 443 (HTTPS) from the internet.
  2. Define Listeners:

    • Create an HTTPS listener on port 443.
    • Associate an SSL/TLS certificate (from AWS Certificate Manager).
  3. Create Target Groups:

    • product-service-tg: For instances running the product catalog service.
      • Protocol: HTTP (ALB handles HTTPS termination).
      • Health Check Path: /health/products
    • order-service-tg: For instances running the order management service.
      • Health Check Path: /health/orders
    • user-service-tg: For instances running the user profile service.
      • Health Check Path: /health/users
    • Register your EC2 instances or ECS tasks with their respective target groups.
  4. Configure Listener Rules (Path-Based Routing):

    • Rule 1 (Priority 10):
      • Condition: Path is /products*
      • Action: Forward to product-service-tg
    • Rule 2 (Priority 20):
      • Condition: Path is /orders*
      • Action: Forward to order-service-tg
    • Rule 3 (Priority 30):
      • Condition: Path is /users*
      • Action: Forward to user-service-tg
    • Default Rule (Lowest Priority):
      • Action: Return a fixed response (e.g., 404 Not Found) or forward to a default target group.

Impact & Benefits:

  • Independent Scaling: Each microservice (product, order, user) can scale independently based on its specific load, managed by its Auto Scaling group and target group.
  • Simplified Routing: The ALB handles the complexity of routing requests to the correct backend service.
  • Enhanced Availability: If one microservice experiences issues, the others remain unaffected. The ALB's health checks will route traffic away from unhealthy instances of that service.
  • Centralized SSL/TLS Termination: Simplifies certificate management and reduces computational load on backend services.
  • Blue/Green Deployments: You can easily implement blue/green deployments per microservice by using weighted target groups or by updating listener rules to point to a new version of a service.

Security & Cost Notes:

  • Security: Ensure security groups for your target instances only allow traffic from the ALB's security group on the application port (e.g., HTTP port 8080). Integrate AWS WAF with the ALB for an extra layer of security.
  • Cost: ALB pricing is based on Load Balancer Capacity Units (LCUs) consumed per hour and the number of new connections, active connections, processed bytes, and rule evaluations. Monitor your usage via CloudWatch.

This kind of setup is incredibly common and powerful for modern application architectures!


Common Mistakes and Pitfalls with ELB (And How to Avoid Them!)

While ELB is robust, misconfigurations can lead to headaches. Here are some common pitfalls:

  1. Misconfigured Health Checks:
    • The Pitfall: Health check path is incorrect (e.g., / instead of /api/health), port is wrong, timeout is too short, or thresholds are too aggressive/lenient. This leads to healthy instances being marked unhealthy, or unhealthy instances receiving traffic.
    • Avoidance: Triple-check your health check settings. Ensure the health check endpoint is lightweight and truly reflects application health. Test it manually!
  2. Incorrect Security Group Rules:
    • The Pitfall: Forgetting to allow traffic from the ELB's security group to the target instances' security group on the specific listener port. Or, for public ELBs, not allowing inbound traffic from 0.0.0.0/0 (or your desired CIDRs) to the ELB listener ports.
    • Avoidance: Draw out your traffic flow. Ensure your ALB's SG allows inbound from clients (e.g., 0.0.0.0/0 on 80/443) and your Target's SG allows inbound from ALB's SG on the target port (e.g., 8080).
  3. Choosing the Wrong ELB Type:
    • The Pitfall: Using an NLB when you need Layer 7 features like path-based routing (ALB territory), or sticking with a Classic Load Balancer for new applications.
    • Avoidance: Revisit the "Selecting Between ELB Types" section. Understand your application's needs (protocol, routing complexity, performance) before provisioning.
  4. Ignoring ELB Scaling Behavior & Pre-warming (Less of an issue now, but good to know):
    • The Pitfall: Historically, for massive, sudden traffic spikes, ELBs needed time to scale. While modern ELBs scale much more proactively, extremely abrupt massive spikes might still see some initial latency or errors.
    • Avoidance: For most use cases, ELB scales automatically. For truly massive, predictable flash sales, you could contact AWS Support to discuss pre-warming, but this is rare now. Generally, ensure your backend Auto Scaling is responsive.
  5. Not Monitoring Key ELB Metrics:
    • The Pitfall: Flying blind. Not watching CloudWatch metrics like HTTPCode_ELB_5XX (ELB-generated errors), HTTPCode_Target_5XX (target-generated errors), HealthyHostCount, UnHealthyHostCount, TargetResponseTime, RequestCount.
    • Avoidance: Set up CloudWatch Alarms for critical metrics. Regularly review dashboards. These metrics are your first line of defense in troubleshooting.
  6. SSL/TLS Certificate Mismanagement:
    • The Pitfall: Using expired certificates, misconfiguring certificates, or not enforcing HTTPS redirection.
    • Avoidance: Use AWS Certificate Manager (ACM) for automated certificate provisioning and renewal. Configure HTTP to HTTPS redirection rules on your ALB.
  7. Cross-Zone Load Balancing Misunderstanding:
    • The Pitfall: For NLBs, cross-zone load balancing is disabled by default. If you have targets in multiple AZs but only enable one AZ in your NLB, or if cross-zone is off and one AZ has more targets/capacity, traffic might not distribute evenly as expected. For ALBs, it's always enabled and free.
    • Avoidance: Understand the default behavior. For NLBs, enable cross-zone load balancing if you want traffic distributed evenly across all registered targets in all enabled AZs (note: this has a data transfer cost).

Image 3
(Image Credits: ByteByteGo)

What's the trickiest ELB issue you've ever had to troubleshoot? Share your war stories!


Pro Tips and Hidden Gems for ELB Mastery

Ready to level up your ELB game? Here are some tips and lesser-known features:

  • ALB: Weighted Target Groups for Canary/Blue-Green:
    • Route a percentage of traffic to one target group and the rest to another. Perfect for canary releasing new features or A/B testing. You can gradually shift traffic.
  • ALB: Lambda as a Target:
    • Build powerful serverless web applications by directly invoking Lambda functions from your ALB. Simplifies architecture for certain use cases.
  • ALB: Advanced Request Routing Conditions:
    • Go beyond just path-based. Use HTTP header conditions, query string parameters, source IP CIDRs, or HTTP request methods to make highly specific routing decisions.
  • ALB: Built-in Authentication:
    • Offload user authentication to the ALB by integrating with Amazon Cognito or any OIDC-compliant identity provider. Users are authenticated before their requests reach your targets.
  • NLB: Static IP Addresses per AZ:
    • Crucial when consumers of your service need to whitelist specific IP addresses. NLBs provide one static IP per AZ enabled.
  • NLB: TLS Termination:
    • While NLB is Layer 4, it can terminate TLS traffic. This allows you to offload TLS processing for TCP-based applications at extremely high performance.
  • Enable and Analyze Access Logs:
    • ELB access logs are invaluable for troubleshooting, security analysis, and understanding traffic patterns. Store them in S3 and query them with Amazon Athena. You can find out client IPs, latencies, request paths, user agents, etc.
  • Fine-tune Deregistration Delay (Connection Draining):
    • When an instance is being terminated or deregistered, ELB waits for this configured period to allow in-flight requests to complete. Adjust this based on how long your typical requests take to process. Default is 300 seconds.
  • Understand Cross-Zone Load Balancing Costs (NLB):
    • For ALBs, cross-zone is always on and free. For NLBs, it's optional and incurs inter-AZ data transfer charges. Evaluate if the benefit of even distribution across AZs (when target counts differ per AZ) outweighs the cost for your NLB.
  • Leverage Idle Timeout Settings:
    • Both ALB and NLB have an idle timeout (default 60s for ALB, 350s for NLB TCP). If no data is sent or received over a connection for this duration, the connection is closed. Adjust if you have very long-running operations, but be cautious.
  • Use AWS CLI/SDK/CloudFormation for Automation:
    • Manage your ELBs as code. This allows for repeatable deployments, version control, and integration into CI/CD pipelines. Boto3 (Python SDK) is great for scripting ELB operations.
# Example Boto3 snippet to describe an ALB (conceptual)
import boto3

client = boto3.client('elbv2', region_name='us-east-1')

try:
    response = client.describe_load_balancers(
        Names=['my-app-alb']
    )
    print(response['LoadBalancers'])
except Exception as e:
    print(f"Error: {e}")
Enter fullscreen mode Exit fullscreen mode

Conclusion & Your Next Steps with ELB

Phew! We've covered a lot of ground on Amazon Elastic Load Balancing. From its fundamental role in ensuring high availability and scalability to the nuances of choosing between ALB, NLB, and GWLB, ELB is undeniably a powerhouse service in the AWS cloud.

Key Takeaways:

  • ELB is essential: For any serious application on AWS, ELB provides the resilience, scalability, and manageability you need.
  • Choose wisely: ALB for Layer 7 smarts, NLB for Layer 4 speed and static IPs, GWLB for virtual appliances.
  • Configure carefully: Health checks, security groups, and listener rules are critical for proper function.
  • Monitor and automate: Use CloudWatch for insights and IaC tools for management.

Where to Go From Here?

  1. AWS Official Documentation:
  2. AWS Workshops & Tutorials:
    • Search the AWS Workshops site for "ELB" or specific load balancer types. Many tutorials involve setting up ELBs as part of broader application deployments.
  3. Relevant AWS Certifications:
    • AWS Certified Solutions Architect - Associate: ELB is a core topic.
    • AWS Certified Developer - Associate: Understanding how to integrate applications with ELB.
    • AWS Certified SysOps Administrator - Associate: Managing and troubleshooting ELBs.
    • AWS Certified Solutions Architect - Professional & DevOps Engineer - Professional: Advanced ELB architectures and best practices.

Image 4

Experiment with ELB in your own AWS account. Set up a simple web server fleet behind an ALB, play with path-based routing, or test the performance of an NLB. The best way to learn is by doing!


What are your favorite ELB features or use cases? Did this guide help clarify anything for you?

I'd love to hear your thoughts and experiences in the comments below!

๐Ÿš€ If this post helped you, please consider:

  • Following me here on Dev.to for more AWS deep dives and cloud insights!
  • Leaving a comment or a reaction โ€“ it helps others discover this content.
  • Bookmarking this post for future reference.
  • Connecting with me on LinkedIn: LinkedIn โ€“ let's build our cloud networks!

Thanks for reading, and happy load balancing!

Top comments (5)

Collapse
 
nevodavid profile image
Nevo David

Love how you packed so much practical stuff in here - honestly learned a bunch just reading through it.

Collapse
 
pkkolla profile image
PHANI KUMAR KOLLA

Thanks for your kind words @nevodavid, this gives boost to me to produce high quality content.

Collapse
 
dotallio profile image
Dotallio

Weighted target groups <3

Collapse
 
pkkolla profile image
PHANI KUMAR KOLLA

Absolutely my friend :-)

Collapse
 
pkkolla profile image
PHANI KUMAR KOLLA

Planning for a high traffic day?
Confused how to use AWS ELB to route traffic on a high volume day?
You are at right place.