Cloud Load Balancing
Distributing traffic across resources with Google Cloud Load Balancing
Google Cloud Load Balancing is a fully distributed, software-defined managed service for distributing traffic across applications and regions. It offers a range of load balancing options to support different types of traffic, from global external HTTP(S) traffic to internal TCP/UDP traffic within a single region.
Key Features
Autoscaling: Handles increases in traffic without pre-warming
Global and Regional: Distribute traffic globally or within specific regions
Integrated with Google Cloud: Works with Cloud CDN, Cloud Armor, and Monitoring
Intelligent traffic distribution: Based on capacity, proximity, and health
Layer 4 and Layer 7 support: Protocol and application-level load balancing
Modern protocols: Support for HTTP/2 and QUIC
Security features: Integration with Cloud Armor for DDoS protection and WAF capabilities
Load Balancing Types
Global Load Balancers
Global External Application Load Balancer
Global HTTP(S), gRPC traffic
HTTP, HTTPS, HTTP/2, gRPC
Integrate with Cloud CDN and Cloud Armor
Global External Proxy Network Load Balancer
Global TCP traffic
TCP, SSL
TLS termination, preserves client source IP
Global External Classic Application Load Balancer (Legacy)
HTTP(S) traffic
HTTP, HTTPS
Predecessor to Global External Application Load Balancer
Regional Load Balancers
Regional External Application Load Balancer
Regional HTTP(S) traffic
HTTP, HTTPS, HTTP/2, gRPC
Lower latency within a region
Regional Internal Application Load Balancer
Internal HTTP(S) traffic
HTTP, HTTPS, HTTP/2, gRPC
Private traffic inside VPC
Regional External Network Load Balancer
Regional TCP/UDP traffic
TCP, UDP, ICMP
Preserves client source IP
Regional Internal Network Load Balancer
Internal TCP/UDP traffic
TCP, UDP
Internal RFC 1918 clients
Cross-region Internal Network Load Balancer
Internal traffic across regions
TCP, UDP
Multi-region internal services
Choosing the Right Load Balancer
HTTP(S) Traffic:
Global reach needed: Global External Application Load Balancer
Single region traffic: Regional External Application Load Balancer
Internal services: Regional Internal Application Load Balancer
TCP/UDP Traffic:
Global TCP: Global External Proxy Network Load Balancer
Regional TCP/UDP with preserved client IPs: Regional External Network Load Balancer
Internal TCP/UDP: Regional Internal Network Load Balancer
Cross-region internal: Cross-region Internal Network Load Balancer
Deployments with Terraform
Global External Application Load Balancer
This setup creates a globally distributed HTTP load balancer for a web application:
Regional Internal Application Load Balancer
This setup creates a regional internal HTTP load balancer for internal microservices:
Regional External Network Load Balancer
This setup creates a regional external TCP load balancer that preserves client IP addresses:
Implementation with gcloud CLI
Global External Application Load Balancer
Regional Internal Application Load Balancer
Advanced Configurations
Custom Headers and URL Rewrites
For Application Load Balancers, you can configure custom headers and URL rewrites:
Weighted Traffic Distribution
For Global Application Load Balancers, you can implement weighted traffic distribution for A/B testing or canary deployments:
Session Affinity
Configure session affinity to route requests from the same client to the same backend:
SSL Policies for Enhanced Security
Create a custom SSL policy for HTTPS load balancers:
Cloud Armor Integration for WAF and DDoS Protection
Add Cloud Armor security policy to your load balancer:
Load Balancing Patterns
Multi-Regional Active-Active
Deploy a global load balancer with backend services in multiple regions for high availability:
Internal Microservices Architecture
Create internal load balancers for microservices communication:
CDN Integration Pattern
Integrate Cloud CDN with Application Load Balancer for static content:
Monitoring and Logging
CloudWatch Metrics for Load Balancers
Setting Up Alerting Policies
Best Practices
Choose the right load balancer: Match your load balancer type to your traffic patterns and requirements
Implement health checks properly: Design health checks that accurately reflect service health, not just connectivity
Utilize Cloud CDN: Enable Cloud CDN for static content to reduce backend load and improve user experience
Implement security layers: Use Cloud Armor for WAF capabilities and DDoS protection
Configure appropriate session affinity: Choose the correct affinity method based on your application requirements
Set up proper monitoring: Configure dashboards and alerts for key metrics like latency, errors, and traffic
Design for high availability: Use multiple regions for global services and multiple zones for regional services
Optimize backend instance groups: Use managed instance groups with autoscaling for dynamic workloads
Define custom headers for backend routing: Add custom headers to help backend services identify traffic source
Implement graceful backend transitions: Use weighted traffic distribution for canary releases
Configure appropriate timeouts: Adjust timeout settings based on backend service response characteristics
Troubleshooting
Common Issues and Solutions
5xx Errors from Load Balancer
Check backend service health
Verify backend instance capacity
Inspect backend service logs for errors
Confirm firewall rules allow health check traffic
High Latency
Check backend service resource utilization
Verify proper region selection for regional load balancers
Enable and optimize Cloud CDN for cacheable content
Use network performance tests to identify bottlenecks
SSL/TLS Certificate Problems
Verify certificate validity and domain names
Check SSL policy configuration
Ensure certificates are properly uploaded and linked
Look for certificate mismatch errors in logs
Load Balancer Not Distributing Traffic Evenly
Review balancing mode settings
Check instance group health and capacity
Verify session affinity settings
Inspect health check pass/fail rates
Diagnostic Commands
Further Reading
Last updated