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.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: devops10 tags: load-balancer, ha, health-checks, sticky-sessions, blue-green, canary, aws-alb, haproxy, nginx11---1213## Overview1415Configures 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).1617## When to Use This Skill1819- Running multiple instances of an app behind a load balancer.20- Implementing zero-downtime deploys or canary releases.21- Adding high availability or geographic distribution.2223## Prerequisites2425- Multiple backend instances (or containers/pods) of the same app.26- Health check endpoint on the app (`/health` or `/ready`).27- DNS or cloud load balancer service.2829## Steps30311. **Choose LB type**:32 - Layer 7 (ALB, Nginx, HAProxy) for HTTP features (path routing, headers, canary).33 - Layer 4 (NLB, HAProxy TCP) for raw TCP/UDP or when you need extreme performance.34352. **Health checks**:36 - Path, interval, timeout, healthy/unhealthy thresholds.37 - Separate liveness vs readiness if using Kubernetes.38 - Use a dedicated lightweight endpoint that checks critical dependencies (DB, cache) or a simpler one.39403. **Algorithms**:41 - Round robin (default, even distribution).42 - Least connections (good for long-lived connections).43 - IP hash / source IP (for sticky sessions when state is local).44454. **Sticky sessions** (when unavoidable):46 - Cookie-based (preferred) or source IP.47 - Document why sticky is needed and plan to remove it.48495. **SSL termination**:50 - Terminate at LB (recommended) — backends can stay on HTTP.51 - Or pass-through (rare).52536. **Connection draining / deregistration**:54 - Deregistration delay (AWS) or slow start / drain timeout.55 - Essential for zero-downtime deploys.56577. **Traffic splitting**:58 - Blue-green: two target groups, switch listener rule or DNS.59 - Canary: weighted target groups (ALB, Nginx, HAProxy, or service mesh).60 - Header or cookie based routing for A/B.61628. **Output**:63 - Config for the chosen LB (ALB listener + target group Terraform, Nginx upstream + server block, HAProxy frontend/backend).64 - Health check endpoint recommendation for the app.65 - Blue-green and canary deployment scripts or Terraform.66 - Monitoring (LB 5xx, latency, healthy host count).6768## Examples6970AWS 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.7172## Edge Cases & Error Handling7374- **All backends unhealthy**: LB should return 503 or a maintenance page. Configure a fallback.75- **Session affinity breaking deploys**: Use cookie-based affinity with proper drain.76- **gRPC / WebSocket**: Ensure the LB supports the protocol (ALB supports gRPC, Nginx needs special config).7778## Verification79801. Deploy multiple backends.812. Send traffic — it is distributed (check logs or metrics on each backend).823. Kill one backend — health check removes it, traffic continues on the others.834. Perform a blue-green or canary deploy — no or minimal user impact.845. Success: Traffic is balanced, unhealthy instances are automatically removed, and advanced deployment strategies work without downtime.8586## References8788- [AWS ALB Documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html)89- [Nginx Upstream](https://nginx.org/en/docs/http/ngx_http_upstream_module.html)90- [HAProxy](https://www.haproxy.org/)91- [Blue-Green Deployments](https://martinfowler.com/bliki/BlueGreenDeployment.html)