Load Balancer — Distributing Traffic for High Availability and Scalability¶
A Load Balancer is a networking service that distributes incoming client requests across multiple servers, virtual machines, containers, or Kubernetes Pods. By spreading traffic intelligently, load balancers improve availability, scalability, fault tolerance, performance, and reliability. Modern cloud platforms such as AWS, Microsoft Azure, and Google Cloud provide fully managed load balancing services that automatically handle traffic distribution, health monitoring, SSL termination, and failover. Every Cloud Architect, DevOps Engineer, Platform Engineer, Site Reliability Engineer (SRE), Network Engineer, and Security Engineer should understand load balancing concepts.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand Load Balancers
- Compare Layer 4 and Layer 7 Load Balancing
- Learn traffic distribution algorithms
- Configure health checks
- Understand high availability
- Compare cloud load balancing services
- Design production-ready load-balanced architectures
Prerequisites¶
Complete:
- Routing
- NAT Gateway
- Internet Gateway
- DNS Fundamentals
- Cloud Networking Basics
Why Do We Need a Load Balancer?¶
Imagine your application runs on one server.
As traffic grows:
- Slow Performance
- Server Overload
- Downtime
- Single Point of Failure
Instead:
Traffic is distributed automatically.
What is a Load Balancer?¶
A Load Balancer is:
It receives client requests and forwards them to healthy backend servers.
Benefits:
- High Availability
- Scalability
- Fault Tolerance
- Improved Performance
Basic Architecture¶
The client communicates only with the Load Balancer.
Load Balancing Workflow¶
The backend server is selected according to a routing algorithm.
Layer 4 Load Balancer¶
Operates at:
Uses:
- Transmission Control Protocol (TCP)
- User Datagram Protocol (UDP)
Decisions are based on:
- Source IP
- Destination IP
- Port Numbers
Examples:
- AWS Network Load Balancer
- Azure Load Balancer
- Google Cloud TCP/UDP Load Balancer
Layer 7 Load Balancer¶
Operates at:
Routes traffic based on:
- URL Path
- Host Header
- HTTP Headers
- Cookies
- HTTP Methods
Examples:
- AWS Application Load Balancer
- Azure Application Gateway
- Google Cloud HTTP(S) Load Balancer
Layer 4 vs Layer 7¶
| Layer 4 | Layer 7 |
|---|---|
| TCP/UDP | HTTP/HTTPS |
| Faster | Smarter Routing |
| IP & Port Based | Content Based |
| Lower Latency | Advanced Features |
Traffic Distribution Algorithms¶
Common algorithms include:
Round Robin¶
Even distribution.
Least Connections¶
Traffic goes to the server with the fewest active connections.
Useful for:
- Long-lived Sessions
- APIs
- Databases
Least Response Time¶
Chooses the backend responding the fastest.
Useful for:
- Performance Optimization
- Dynamic Workloads
IP Hash¶
Client IP determines the backend.
Useful for:
- Session Persistence
- Stateful Applications
Health Checks¶
Load Balancers continuously monitor backend health.
Example:
Healthy:
Unhealthy:
Unhealthy servers are automatically removed from traffic rotation.
SSL/TLS Termination¶
Instead of every server handling Transport Layer Security (TLS):
Benefits:
- Reduced CPU Usage
- Centralised Certificate Management
- Simpler Backend Configuration
Session Persistence (Sticky Sessions)¶
Some applications require clients to reach the same backend.
Example:
Subsequent requests continue going to Server 2 until the session expires.
High Availability¶
Without Load Balancer:
With Load Balancer:
No manual intervention is required.
Auto Scaling Integration¶
Modern cloud load balancers integrate with Auto Scaling.
AWS Load Balancers¶
AWS Elastic Load Balancing (ELB) includes:
- Application Load Balancer (ALB)
- Network Load Balancer (NLB)
- Gateway Load Balancer (GWLB)
- Classic Load Balancer (Legacy)
Application Load Balancer (ALB)¶
Supports:
- HTTP
- HTTPS
- Path-Based Routing
- Host-Based Routing
- Web Applications
- Microservices
- Kubernetes Ingress
Network Load Balancer (NLB)¶
Supports:
- TCP
- UDP
- TLS
- High Performance
- Static IP Addresses
Gateway Load Balancer (GWLB)¶
Designed for:
- Network Appliances
- Firewalls
- Intrusion Detection System / Intrusion Prevention System (IDS/IPS)
- Security Inspection
Azure Load Balancers¶
Azure provides:
- Azure Load Balancer (Layer 4)
- Azure Application Gateway (Layer 7)
- Azure Front Door (Global Layer 7)
Google Cloud Load Balancers¶
Google Cloud provides:
- Global HTTP(S) Load Balancer
- Regional HTTP(S) Load Balancer
- TCP Load Balancer
- SSL Proxy Load Balancer
- Internal Load Balancer
One major advantage:
Clients connect to the nearest Google edge location.
Kubernetes Perspective¶
Kubernetes uses Load Balancers for:
- Service Type: LoadBalancer
- Ingress Controllers
- External APIs
- Multi-Service Routing
Example:
Enterprise Architecture¶
Traffic is distributed across multiple application servers.
Cloud Perspective¶
Load Balancers provide:
- High Availability
- Automatic Failover
- SSL Offloading
- Health Monitoring
- Horizontal Scaling
- Global Traffic Distribution
AWS CLI Example¶
List Load Balancers.
Azure CLI Example¶
List Load Balancers.
Google Cloud CLI Example¶
List forwarding rules.
Common Load Balancer Types¶
| Type | Use Case |
|---|---|
| Layer 4 | TCP/UDP Applications |
| Layer 7 | HTTP/HTTPS Applications |
| Internal | Private Services |
| External | Internet Applications |
| Global | Multi-Region Applications |
Hands-on Lab¶
Task 1¶
List AWS Load Balancers.
Task 2¶
List Azure Load Balancers.
Task 3¶
List Google Cloud forwarding rules.
Task 4¶
Design:
- Public Load Balancer
- Three Application Servers
using Round Robin distribution.
Task 5¶
Configure health checks for:
Task 6¶
Compare:
- Layer 4
- Layer 7
routing decisions.
Task 7¶
Design a Kubernetes architecture using:
- Cloud Load Balancer
- Ingress Controller
- Multiple Services
- Pods
Task 8¶
Draw a production architecture including:
- Internet
- Load Balancer
- Auto Scaling Group
- Application Servers
- Database
- Monitoring
Explain how traffic flows when one application server becomes unavailable.
Production Troubleshooting¶
Problem:
Check:
- Backend Health
- Health Check Endpoint
- Target Registration
- Security Rules
- Domain Name System (DNS)
- Application Logs
Workflow:
Cloud Comparison¶
| AWS | Azure | Google Cloud |
|---|---|---|
| ALB | Application Gateway | HTTP(S) Load Balancer |
| NLB | Azure Load Balancer | TCP Load Balancer |
| GWLB | Azure Firewall Integration | Internal Load Balancer |
| ELB | Azure Front Door | Global Anycast Load Balancer |
Common Mistakes¶
❌ Using one backend server.
✅ Deploy multiple backend instances.
❌ Poor health check configuration.
✅ Use lightweight, reliable health endpoints.
❌ Exposing backend servers directly.
✅ Route traffic through the Load Balancer.
❌ Ignoring SSL certificate management.
✅ Centralise certificates on the Load Balancer when appropriate.
❌ Using sticky sessions unnecessarily.
✅ Design stateless applications whenever possible.
Best Practices¶
- Deploy multiple backend servers.
- Enable health checks.
- Use HTTPS for all public services.
- Terminate SSL/TLS at the Load Balancer when appropriate.
- Prefer stateless applications.
- Integrate with Auto Scaling.
- Monitor latency, error rates, and backend health.
- Deploy across multiple Availability Zones or regions.
Interview Questions¶
Beginner¶
- What is a Load Balancer?
- Why is a Load Balancer needed?
- What is a health check?
- What is Round Robin?
Intermediate¶
- Compare Layer 4 and Layer 7 Load Balancers.
- Explain SSL termination.
- What are sticky sessions?
- How does Auto Scaling work with Load Balancers?
Architect Level¶
- Design a highly available web application using cloud load balancers.
- Explain global load balancing for a multi-region application.
- How would you troubleshoot intermittent 503 errors from a production Load Balancer?
Summary¶
In this lesson, you learned:
- Load Balancers
- Layer 4 and Layer 7 Load Balancing
- Traffic Distribution Algorithms
- Health Checks
- SSL/TLS Termination
- Session Persistence
- High Availability
- Auto Scaling Integration
- AWS ELB
- Azure Load Balancer
- Google Cloud Load Balancer
Load Balancers are essential components of modern cloud architectures. They distribute client requests across multiple backend resources, improve availability, enable horizontal scaling, and provide intelligent traffic management. Combined with Auto Scaling, health checks, and cloud-native services, load balancers ensure applications remain highly available and responsive under varying workloads.
Key Takeaways¶
- A Load Balancer distributes traffic across multiple backend resources.
- Layer 4 load balancers route based on TCP/UDP information, while Layer 7 load balancers route based on application-layer information such as URLs and HTTP headers.
- Health checks automatically remove unhealthy servers from service.
- SSL/TLS termination simplifies certificate management and reduces backend overhead.
- Load Balancers work closely with Auto Scaling to handle changing traffic.
- Managed cloud load balancers improve availability, scalability, and resilience.
What's Next?¶
In the next lesson, you'll learn about Private Connectivity.
You'll explore:
- What Private Connectivity is
- Site-to-Site VPN
- Dedicated Private Links
- AWS Direct Connect
- Azure ExpressRoute
- Google Cloud Interconnect
- Hybrid Cloud Networking
By the end of the lesson, you'll understand how organisations securely connect on-premises data centres with cloud environments without sending sensitive traffic across the public Internet.