Overview
Configures load balancers (AWS ALB/NLB, Nginx, HAProxy) for high availability with proper health checks, traffic distribution algorithms (round-robin, least connections, ip-hash), sticky sessions when needed, SSL termination, connection draining, and advanced traffic splitting (blue-green, canary, A/B).
When to Use This Skill
- Running multiple instances of an app behind a load balancer.
- Implementing zero-downtime deploys or canary releases.
- Adding high availability or geographic distribution.
Prerequisites
- Multiple backend instances (or containers/pods) of the same app.
- Health check endpoint on the app (
/health or /ready).
- DNS or cloud load balancer service.
Steps
Choose LB type:
- Layer 7 (ALB, Nginx, HAProxy) for HTTP features (path routing, headers, canary).
- Layer 4 (NLB, HAProxy TCP) for raw TCP/UDP or when you need extreme performance.
Health checks:
- Path, interval, timeout, healthy/unhealthy thresholds.
- Separate liveness vs readiness if using Kubernetes.
- Use a dedicated lightweight endpoint that checks critical dependencies (DB, cache) or a simpler one.
Algorithms:
- Round robin (default, even distribution).
- Least connections (good for long-lived connections).
- IP hash / source IP (for sticky sessions when state is local).
Sticky sessions (when unavoidable):
- Cookie-based (preferred) or source IP.
- Document why sticky is needed and plan to remove it.
SSL termination:
- Terminate at LB (recommended) — backends can stay on HTTP.
- Or pass-through (rare).
Connection draining / deregistration:
- Deregistration delay (AWS) or slow start / drain timeout.
- Essential for zero-downtime deploys.
Traffic splitting:
- Blue-green: two target groups, switch listener rule or DNS.
- Canary: weighted target groups (ALB, Nginx, HAProxy, or service mesh).
- Header or cookie based routing for A/B.
Output:
- Config for the chosen LB (ALB listener + target group Terraform, Nginx upstream + server block, HAProxy frontend/backend).
- Health check endpoint recommendation for the app.
- Blue-green and canary deployment scripts or Terraform.
- Monitoring (LB 5xx, latency, healthy host count).
Examples
AWS ALB Terraform for a blue-green setup, an Nginx config with least-conn and sticky cookie, an HAProxy example with canary weighting, and health check implementation guidance are included.
Edge Cases & Error Handling
- All backends unhealthy: LB should return 503 or a maintenance page. Configure a fallback.
- Session affinity breaking deploys: Use cookie-based affinity with proper drain.
- gRPC / WebSocket: Ensure the LB supports the protocol (ALB supports gRPC, Nginx needs special config).
Verification
- Deploy multiple backends.
- Send traffic — it is distributed (check logs or metrics on each backend).
- Kill one backend — health check removes it, traffic continues on the others.
- Perform a blue-green or canary deploy — no or minimal user impact.
- Success: Traffic is balanced, unhealthy instances are automatically removed, and advanced deployment strategies work without downtime.
References
1---2name: load-balancer-config3description: Configures load balancers for high availability, health checking, and traffic distribution. Use when distributing traffic across multiple backend instances.4license: Apache-2.05---67## Overview89Configures load balancers (AWS ALB/NLB, Nginx, HAProxy) for high availability with proper health checks, traffic distribution algorithms (round-robin, least connections, ip-hash), sticky sessions when needed, SSL termination, connection draining, and advanced traffic splitting (blue-green, canary, A/B).1011## When to Use This Skill1213- Running multiple instances of an app behind a load balancer.14- Implementing zero-downtime deploys or canary releases.15- Adding high availability or geographic distribution.1617## Prerequisites1819- Multiple backend instances (or containers/pods) of the same app.20- Health check endpoint on the app (`/health` or `/ready`).21- DNS or cloud load balancer service.2223## Steps24251. **Choose LB type**:26 - Layer 7 (ALB, Nginx, HAProxy) for HTTP features (path routing, headers, canary).27 - Layer 4 (NLB, HAProxy TCP) for raw TCP/UDP or when you need extreme performance.28292. **Health checks**:30 - Path, interval, timeout, healthy/unhealthy thresholds.31 - Separate liveness vs readiness if using Kubernetes.32 - Use a dedicated lightweight endpoint that checks critical dependencies (DB, cache) or a simpler one.33343. **Algorithms**:35 - Round robin (default, even distribution).36 - Least connections (good for long-lived connections).37 - IP hash / source IP (for sticky sessions when state is local).38394. **Sticky sessions** (when unavoidable):40 - Cookie-based (preferred) or source IP.41 - Document why sticky is needed and plan to remove it.42435. **SSL termination**:44 - Terminate at LB (recommended) — backends can stay on HTTP.45 - Or pass-through (rare).46476. **Connection draining / deregistration**:48 - Deregistration delay (AWS) or slow start / drain timeout.49 - Essential for zero-downtime deploys.50517. **Traffic splitting**:52 - Blue-green: two target groups, switch listener rule or DNS.53 - Canary: weighted target groups (ALB, Nginx, HAProxy, or service mesh).54 - Header or cookie based routing for A/B.55568. **Output**:57 - Config for the chosen LB (ALB listener + target group Terraform, Nginx upstream + server block, HAProxy frontend/backend).58 - Health check endpoint recommendation for the app.59 - Blue-green and canary deployment scripts or Terraform.60 - Monitoring (LB 5xx, latency, healthy host count).6162## Examples6364AWS ALB Terraform for a blue-green setup, an Nginx config with least-conn and sticky cookie, an HAProxy example with canary weighting, and health check implementation guidance are included.6566## Edge Cases & Error Handling6768- **All backends unhealthy**: LB should return 503 or a maintenance page. Configure a fallback.69- **Session affinity breaking deploys**: Use cookie-based affinity with proper drain.70- **gRPC / WebSocket**: Ensure the LB supports the protocol (ALB supports gRPC, Nginx needs special config).7172## Verification73741. Deploy multiple backends.752. Send traffic — it is distributed (check logs or metrics on each backend).763. Kill one backend — health check removes it, traffic continues on the others.774. Perform a blue-green or canary deploy — no or minimal user impact.785. Success: Traffic is balanced, unhealthy instances are automatically removed, and advanced deployment strategies work without downtime.7980## References8182- [AWS ALB Documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html)83- [Nginx Upstream](https://nginx.org/en/docs/http/ngx_http_upstream_module.html)84- [HAProxy](https://www.haproxy.org/)85- [Blue-Green Deployments](https://martinfowler.com/bliki/BlueGreenDeployment.html)