4.41 What is load balancing

In this lesson we discover what a load balancer is. A load balancer is a server that redirects all incoming external traffic toward multiple EC2 instances behind it. If three users send requests to the load balancer, it dispatches each request to a different instance, which responds back through the balancer to its user. This is exactly why it is called a load balancer — it spreads the incoming traffic evenly across the downstream instances.

Why use an Elastic Load Balancer

  • Spreads the load across multiple downstream instances.
  • Exposes a single DNS endpoint to the outside world.
  • Gracefully handles instance failures with regular health checks.
  • Provides SSL/HTTPS termination for your sites.
  • Enforces session stickiness via cookies (covered later).
  • Provides high availability across multiple availability zones.
  • Separates public traffic from private traffic.

AWS offers four types of load balancers: the Classic Load Balancer (CLB) — version 1 from 2009, supports HTTP, HTTPS and TCP; the Application Load Balancer (ALB) — version 2 from 2016, supports HTTP, HTTPS and WebSocket; the Network Load Balancer (NLB) — version 2 from 2017, supports TCP, UDP and TLS at extremely low latency; and the Gateway Load Balancer. The v2 generations offer more features and are recommended. You can also deploy internal load balancers (private) or external ones (public).

Security is enforced through security groups. A common pattern: users access the load balancer on ports 80 and 443 from 0.0.0.0/0; the EC2 instances behind it only accept inbound traffic on port 80 from the load balancer's security group, never directly from the Internet. The balancer also performs health checks: it probes each instance on a configured port and path; any response other than HTTP 200 marks the instance unhealthy. Common errors include 4xx (client side), 5xx (application side) and 503 (load balancer overloaded or no targets registered). Access logs help debug requests.

Summary

A load balancer is a server that distributes incoming external traffic across multiple EC2 instances, providing a single access point while managing failures transparently. AWS Elastic Load Balancer simplifies this by handling health checks, SSL/HTTPS termination, auto-scaling, and high availability across zones without requiring manual server management. It performs regular health checks on instances and routes traffic away from any that fail, ensuring reliable service delivery.

Key points

  • Load balancer redirects external traffic to multiple downstream EC2 instances, balancing the load across them for improved reliability and availability
  • Provides a single DNS endpoint to users, hiding individual instances and handling instance failures automatically through continuous health checks
  • AWS Elastic Load Balancer is a managed service that eliminates manual setup and maintenance while guaranteeing uptime, high availability, and simplified configuration
  • Health checks are critical: the load balancer sends periodic requests to instances and removes those that don't return a 200 HTTP response
  • Three main types exist: Classic Load Balancer (v1, HTTP/HTTPS/TCP), Application Load Balancer (v2, HTTP/HTTPS/WebSocket), and Network Load Balancer (v2, TCP/UDP), with newer versions recommended
  • Security groups work together: external load balancer allows traffic from anywhere on ports 80/443, while EC2 instances restrict traffic to only the load balancer's security group

FAQ

What is the main purpose of a load balancer?

A load balancer distributes incoming external traffic across multiple backend instances, providing a single access point while transparently managing instance failures and ensuring high availability and reliable service delivery.

How does AWS Elastic Load Balancer check if an instance is healthy?

The load balancer sends periodic health check requests to instances on a specified port and expects a 200 HTTP response. If an instance doesn't respond with 200, it is considered unhealthy and removed from traffic routing.

What are the different types of AWS load balancers and when should each be used?

Classic Load Balancer (v1) supports HTTP/HTTPS/TCP; Application Load Balancer (v2) supports HTTP/HTTPS/WebSocket for complex routing; Network Load Balancer (v2) supports TCP/UDP for extreme performance. AWS recommends using the newer v2 versions for most use cases.