Elastic Load Balancing
Overview
Elastic Load Balancing (ELB) automatically distributes incoming application traffic across multiple targets, such as EC2 instances, containers, IP addresses, and Lambda functions. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones.
Key Features
- High Availability: Distribute traffic across multiple targets
- Health Checks: Automatically detect unhealthy targets
- Auto Scaling: Integrate with Auto Scaling groups
- SSL/TLS Termination: Handle SSL certificates centrally
- Session Affinity: Maintain session state
- Multiple Protocols: HTTP, HTTPS, TCP, UDP, TLS
- Cross-Zone Load Balancing: Distribute traffic across AZs
- Access Logs: Detailed request logging
Interview Topics
1. Load Balancer Types
- Application Load Balancer (ALB): Layer 7 load balancing
- Network Load Balancer (NLB): Layer 4 load balancing
- Classic Load Balancer (CLB): Legacy load balancer
- Gateway Load Balancer (GWLB): Transparent network gateway
2. ALB Features
- Path-Based Routing: Route based on URL path
- Host-Based Routing: Route based on host header
- Query String Parameters: Route based on query parameters
- HTTP Headers: Route based on custom headers
- Target Groups: Group targets for routing
3. NLB Features
- TCP/UDP Load Balancing: Protocol-level load balancing
- Static IP Addresses: Fixed IP addresses
- Preserve Source IP: Maintain client IP addresses
- High Performance: Ultra-low latency
- Health Checks: TCP health checks
4. Target Groups
- Instance Targets: EC2 instances
- IP Targets: IP addresses
- Lambda Targets: Lambda functions
- ALB Targets: Nested load balancers
- Health Check Configuration: Custom health checks
5. Security Features
- SSL/TLS Termination: Centralized certificate management
- WAF Integration: Web application firewall
- Security Groups: Network-level security
- IAM Policies: Access control
- VPC Integration: Private network deployment
Common Interview Questions
Basic Questions
-
What is Elastic Load Balancing and when would you use it?
- Distribute traffic across multiple targets
- Improve application availability
- Handle varying load
- Provide fault tolerance
-
What are the different types of load balancers in AWS?
- Application Load Balancer (ALB): Layer 7
- Network Load Balancer (NLB): Layer 4
- Classic Load Balancer (CLB): Legacy
- Gateway Load Balancer (GWLB): Network gateway
-
How do you create an Application Load Balancer?
aws elbv2 create-load-balancer \ --name my-alb \ --subnets subnet-12345678 subnet-87654321 \ --security-groups sg-12345678
Advanced Questions
-
How do you configure path-based routing with ALB?
Resources: ALB: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Name: MyALB Subnets: - subnet-12345678 - subnet-87654321 TargetGroup1: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: Name: WebTargetGroup Port: 80 Protocol: HTTP VpcId: vpc-12345678 TargetGroup2: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: Name: APITargetGroup Port: 8080 Protocol: HTTP VpcId: vpc-12345678 Listener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: LoadBalancerArn: !Ref ALB Port: 80 Protocol: HTTP DefaultActions: - Type: forward TargetGroupArn: !Ref TargetGroup1 PathRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule Properties: ListenerArn: !Ref Listener Priority: 1 Conditions: - Field: path-pattern Values: ["/api/*"] Actions: - Type: forward TargetGroupArn: !Ref TargetGroup2 -
What is the difference between ALB and NLB?
- ALB: Layer 7, content-based routing, HTTP/HTTPS
- NLB: Layer 4, protocol-based routing, TCP/UDP
- ALB: More features, higher latency
- NLB: Better performance, fewer features
-
How do you configure SSL termination on a load balancer?
- Upload SSL certificate to ACM
- Configure HTTPS listener
- Set up certificate in listener
- Configure security groups for HTTPS
Troubleshooting Questions
-
What if targets are failing health checks?
- Check target health status
- Verify security group rules
- Check application configuration
- Review health check settings
-
How do you troubleshoot load balancer issues?
- Check target health
- Verify security groups
- Review access logs
- Monitor CloudWatch metrics
Best Practices
1. Load Balancer Selection
- Use ALB for HTTP/HTTPS applications
- Use NLB for TCP/UDP applications
- Use GWLB for network gateway scenarios
- Consider performance requirements
2. Target Group Configuration
- Configure appropriate health checks
- Set reasonable health check intervals
- Use multiple targets for availability
- Monitor target health
3. Security
- Use HTTPS for web applications
- Configure security groups properly
- Implement WAF for protection
- Use IAM policies for access control
4. Performance
- Enable cross-zone load balancing
- Use appropriate instance types
- Monitor performance metrics
- Optimize health check settings
5. Monitoring
- Enable access logs
- Set up CloudWatch alarms
- Monitor target health
- Track performance metrics
Use Cases
1. Web Applications
- HTTP/HTTPS load balancing
- Session management
- SSL termination
- Content-based routing
2. Microservices
- Service discovery
- API routing
- Load distribution
- Health monitoring
3. Container Applications
- ECS/EKS integration
- Container health checks
- Service mesh integration
- Auto-scaling support
4. High Availability
- Multi-AZ deployment
- Fault tolerance
- Disaster recovery
- Auto-scaling integration
Integration Patterns
1. Auto Scaling Integration
- Target group registration
- Health check integration
- Scaling policies
- Capacity management
2. VPC Integration
- Private subnets
- Security group configuration
- VPC endpoints
- Network isolation
3. Container Integration
- ECS service integration
- EKS service integration
- Container health checks
- Service discovery
4. Serverless Integration
- Lambda function targets
- API Gateway integration
- Event-driven architecture
- Function scaling
Security Considerations
1. Network Security
- Configure security groups
- Use private subnets
- Implement network ACLs
- Monitor network traffic
2. Application Security
- Use HTTPS for web traffic
- Implement WAF protection
- Validate input data
- Monitor for attacks
3. Access Control
- Use IAM roles and policies
- Implement least privilege
- Monitor access patterns
- Regular access reviews
4. Data Protection
- Encrypt data in transit
- Use secure protocols
- Implement proper logging
- Monitor data access
Cost Optimization
1. Load Balancer Selection
- Choose appropriate type
- Optimize for use case
- Monitor usage patterns
- Consider reserved capacity
2. Target Optimization
- Right-size targets
- Use appropriate instance types
- Implement auto-scaling
- Monitor resource usage
3. Data Transfer
- Optimize data transfer
- Use compression
- Monitor bandwidth usage
- Implement caching
4. Monitoring Costs
- Track load balancer costs
- Monitor target costs
- Optimize health checks
- Use cost allocation tags
Performance Optimization
1. Load Distribution
- Enable cross-zone load balancing
- Use appropriate algorithms
- Monitor distribution patterns
- Optimize target placement
2. Health Check Optimization
- Set appropriate intervals
- Configure reasonable timeouts
- Use appropriate protocols
- Monitor health check performance
3. SSL/TLS Optimization
- Use appropriate cipher suites
- Implement session resumption
- Optimize certificate management
- Monitor SSL performance
4. Network Optimization
- Choose appropriate instance types
- Use enhanced networking
- Optimize security groups
- Monitor network performance
Disaster Recovery
1. Multi-Region Deployment
- Deploy across regions
- Use Route 53 for routing
- Implement failover procedures
- Monitor regional health
2. Backup Strategies
- Backup load balancer configuration
- Document target configurations
- Maintain health check settings
- Test recovery procedures
3. Recovery Procedures
- Document recovery steps
- Test failover scenarios
- Maintain recovery documentation
- Train recovery teams
4. Monitoring and Alerting
- Monitor load balancer health
- Set up regional alerting
- Track recovery metrics
- Maintain operational procedures
Migration Strategies
1. From Classic Load Balancer
- Plan migration strategy
- Configure equivalent ALB/NLB
- Test functionality
- Migrate traffic gradually
2. From On-Premises Load Balancers
- Map existing configuration
- Configure equivalent AWS load balancer
- Test thoroughly
- Migrate applications
3. Application Migration
- Plan load balancer requirements
- Configure appropriate type
- Test with applications
- Monitor performance
Common Pitfalls
1. Configuration Issues
- Incorrect security group rules
- Poor health check configuration
- Inadequate target configuration
- Misconfigured routing rules
2. Performance Problems
- Suboptimal load balancer type
- Poor target placement
- Inadequate monitoring
- Performance misconfigurations
3. Security Issues
- Inadequate security groups
- Poor SSL configuration
- Insufficient monitoring
- Security misconfigurations
4. Cost Management
- Over-provisioned resources
- Inefficient target usage
- High data transfer costs
- Poor cost monitoring
Resources
Interview angle
- “ALB, NLB or GWLB?” - ALB for HTTP and HTTPS with path and host routing, the default for web apps and containers. NLB for TCP and UDP, extreme throughput, static IPs, or when you need to preserve the client IP at layer 4. GWLB for inserting third-party network appliances.
- “How does health checking interact with deploys?” - the target is only sent traffic once it passes; deregistration delay lets in-flight requests finish before the instance leaves. Too-aggressive health check thresholds during a rolling deploy cause a capacity dip that reads as an outage.
- “How do you do zero-downtime deploys behind an ALB?” - two target groups and a weighted listener rule, shifting traffic gradually. That gives you canary and instant rollback without DNS changes and their TTL delays.
- “Where does TLS terminate?” - at the load balancer with an ACM certificate, usually. Re-encrypt to the target when the network between them is not trusted or compliance requires end-to-end encryption.
- “How does the client IP survive?” -
X-Forwarded-Forfor ALB, since it is a layer 7 proxy. NLB can preserve the real source IP directly. Rate limiting or geo-blocking on the wrong field is the bug this causes.