Load Balancing & Traffic
In our Lego city analogy, load balancing and traffic management are like the international highways and traffic controllers that direct cars between countries. When your city spans AWS, Azure, and GCP, you need smart systems to distribute traffic, reroute during failures, and ensure users always reach the nearest, healthiest service.
This chapter explores how Terraform provisions load balancers and traffic routing policies across multiple clouds for resilience and global reach.
Key Concepts
1. Cloud‑Specific Load Balancers
- AWS Application Load Balancer (ALB): Layer 7 routing, SSL termination, health checks.
- Azure Load Balancer / Application Gateway: Distributes traffic across VMs, supports SSL offloading.
- GCP Load Balancer: Global load balancing with cross‑region failover.
2. DNS‑Based Global Traffic Routing
- AWS Route 53: Weighted routing, latency‑based routing, failover policies.
- Azure Traffic Manager: DNS‑based routing across regions/providers.
- GCP Cloud DNS: Global DNS with policy‑based routing.
- Multi‑Cloud Strategy: Use DNS services to direct traffic to the nearest healthy cloud provider.
3. Health Checks & Failover
- Each load balancer continuously checks instance health.
- Traffic is routed only to healthy targets.
- Failover policies ensure traffic is redirected to another cloud during outages.
4. Traffic Management Patterns
- Active‑Active: Distribute traffic across multiple clouds simultaneously.
- Active‑Passive: Primary cloud handles traffic, secondary cloud is standby.
- Geo‑Routing: Direct users to nearest region/provider.
Hands‑On Lab / Demo
Lab: Multi‑Cloud Load Balancing Setup
DNS Routing (AWS Route 53 Example):
resource "aws_route53_record" "multi_cloud_dns" {
zone_id = aws_route53_zone.main.id
name = "app.example.com"
type = "A"
alias {
name = aws_lb.aws_alb.dns_name
zone_id = aws_lb.aws_alb.zone_id
evaluate_target_health = true
}
}
GCP Load Balancer:
resource "google_compute_global_address" "default" {
name = "gcp-global-ip"
}
Azure Load Balancer:
resource "azurerm_lb" "azure_lb" {
name = "azure-lb"
location = "East US"
resource_group_name = azurerm_resource_group.rg.name
sku = "Standard"
}
AWS ALB:
resource "aws_lb" "aws_alb" {
name = "aws-alb"
load_balancer_type = "application"
subnets = [aws_subnet.public1.id, aws_subnet.public2.id]
}
Pro Tips & Best Practices
- Use DNS‑based routing for global traffic management.
- Always enable health checks for resilience.
- Document routing policies (active‑active vs active‑passive).
- Encrypt traffic with SSL certificates.
- Test failover scenarios regularly.
Summary & Cheatsheet
- Load Balancers: ALB (AWS), Azure LB, GCP LB.
- DNS Routing: Route 53, Traffic Manager, Cloud DNS.
- Patterns: Active‑Active, Active‑Passive, Geo‑Routing.
- Best practice: Health checks, SSL, documented policies.
Quick mnemonic: Balance → Route → Check → Failover
The Hackers Notebook
Load balancing and traffic management are the global traffic controllers of multi‑cloud deployments. By configuring ALBs, Azure Load Balancers, GCP Load Balancers, and DNS‑based routing, you ensure resilience, scalability, and seamless user experiences across providers.
