Install any skill in seconds. Free to start, no credit card required.
Get Started Free →When distributing traffic across multiple servers or regions, use this skill to select and configure the appropriate load balancing solution (L4/L7, cloud-managed, self-managed, or Kubernetes ingress) with proper health checks and session management.
.claude/skills/ancoleman-load-balancing-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-07 | ✗→✓ | ▲ Improved | 136% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 139% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 100% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 150% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 162% | 0% |
Distribute traffic across infrastructure using the appropriate load balancing approach, from simple round-robin to global multi-region failover.
Use load-balancing-patterns when:
Layer 4 (L4) - Transport Layer:
Layer 7 (L7) - Application Layer:
For detailed comparison including performance benchmarks and hybrid approaches, see references/l4-vs-l7-comparison.md.
| Algorithm | Distribution Method | Use Case | |-----------|-------------------|----------| | Round Robin | Sequential | Stateless, similar servers | | Weighted Round Robin | Capacity-based | Different server specs | | Least Connections | Fewest active connections | Long-lived connections | | Least Response Time | Fastest server | Performance-sensitive | | IP Hash | Client IP-based | Session persistence | | Resource-Based | CPU/memory metrics | Varying workloads |
Shallow (Liveness): Is the process alive?
/health/live or /liveDeep (Readiness): Can the service handle requests?
/health/ready or /readyHealth Check Hysteresis: Different thresholds for marking up vs down to prevent flapping
For complete health check implementation patterns, see references/health-check-strategies.md.
Application Load Balancer (ALB) - Layer 7:
Network Load Balancer (NLB) - Layer 4:
Global Accelerator - Layer 4 Global:
Application LB (L7): Global HTTPS LB, Cloud CDN integration, Cloud Armor (WAF/DDoS) Network LB (L4): Regional TCP/UDP, pass-through balancing, session affinity Cloud Load Balancing: Single anycast IP, global distribution, backend buckets
Application Gateway (L7): WAF integration, URL-based routing, SSL termination, autoscaling Load Balancer (L4): Basic and Standard SKUs, health probes, HA ports Traffic Manager (Global): DNS-based routing (priority, weighted, performance, geographic)
For complete cloud provider configurations and Terraform examples, see references/cloud-load-balancers.md.
Best for: General-purpose HTTP/HTTPS load balancing, web application stacks
Capabilities:
Basic configuration:
nginxupstream backend { least_conn; server backend1.example.com:8080 weight=3; server backend2.example.com:8080 weight=2; keepalive 32; } server { listen 80; location / { proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
For complete NGINX patterns and advanced configurations, see references/nginx-patterns.md.
Best for: Maximum performance, database load balancing, resource efficiency
Capabilities:
Basic configuration:
haproxyfrontend http_front bind *:80 default_backend web_servers backend web_servers balance roundrobin option httpchk GET /health server web1 192.168.1.101:8080 check server web2 192.168.1.102:8080 check
For complete HAProxy patterns, see references/haproxy-patterns.md.
Best for: Microservices, Kubernetes, service mesh integration
Capabilities:
For complete Envoy patterns, see references/envoy-patterns.md.
Best for: Docker/Kubernetes environments, dynamic configuration, ease of use
Capabilities:
For complete Traefik patterns, see references/traefik-patterns.md.
| Controller | Best For | Strengths | |------------|----------|-----------| | NGINX Ingress (F5) | General purpose | Stability, wide adoption, mature features | | Traefik | Dynamic environments | Easy configuration, service discovery | | HAProxy Ingress | High performance | Advanced L7 routing, reliability | | Envoy (Contour/Gateway) | Service mesh | Rich L7 features, extensibility | | Kong | API-heavy apps | JWT auth, rate limiting, plugins | | Cloud Provider | Single-cloud | Native cloud integration |
yamlapiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: app-ingress annotations: nginx.ingress.kubernetes.io/ssl-redirect: "true" nginx.ingress.kubernetes.io/affinity: "cookie" spec: ingressClassName: nginx tls: - hosts: - app.example.com secretName: app-tls rules: - host: app.example.com http: paths: - path: /api pathType: Prefix backend: service: name: api-service port: number: 80 - path: / pathType: Prefix backend: service: name: web-service port: number: 80
For complete Kubernetes ingress examples and Gateway API patterns, see references/kubernetes-ingress.md.
Cookie-Based: Load balancer sets cookie to track server affinity
IP Hash: Hash client IP to select backend server
Drawbacks: Uneven load distribution, session lost on server failure, complicates scaling
Architecture: Stateless application servers + centralized session storage (Redis, Memcached)
Benefits:
JWT (JSON Web Tokens): Server generates signed token, client stores and sends with requests
Benefits:
For complete session management patterns and code examples, see references/session-persistence.md.
Route users to nearest server based on geographic location:
Primary/secondary region configuration:
Combine load balancing with CDN:
For complete global load balancing examples with Terraform, see references/global-load-balancing.md.
Choose L4 when:
Choose L7 when:
Choose Cloud-Managed when:
Choose Self-Managed when:
Complete working examples available in examples/ directory:
Cloud Providers:
examples/aws/alb-terraform.tf - AWS ALB with path-based routingexamples/aws/nlb-terraform.tf - AWS NLB for TCP load balancingSelf-Managed:
examples/nginx/http-load-balancing.conf - NGINX HTTP reverse proxyexamples/haproxy/http-lb.cfg - HAProxy configurationexamples/envoy/basic-lb.yaml - Envoy cluster configurationexamples/traefik/kubernetes-ingress.yaml - Traefik IngressRouteKubernetes:
examples/kubernetes/nginx-ingress.yaml - NGINX Ingress with TLSexamples/kubernetes/traefik-ingress.yaml - Traefik IngressRouteexamples/kubernetes/gateway-api.yaml - Gateway API configurationThroughput: Requests per second, bytes transferred, connection rate Latency: Request duration (p50, p95, p99), backend response time, SSL handshake time Errors: HTTP error rates (4xx, 5xx), backend connection failures, health check failures Resource Utilization: CPU, memory, active connections, connection queue depth Health: Healthy/unhealthy backend count, health check success rate
Enable access logs for request/response details, client IPs, response times, error tracking
Symptoms: One server receives disproportionate traffic Causes: Sticky sessions with few clients, IP hash with NAT concentration, long-lived connections Solutions: Switch to least connections, disable sticky sessions, implement connection draining
Symptoms: Servers rapidly transition between healthy/unhealthy Causes: Health check timeout too short, threshold too low, network instability Solutions: Increase interval and timeout, implement hysteresis, use deep health checks
Symptoms: Users logged out when server fails Causes: Sticky sessions without replication, in-memory sessions Solutions: Implement shared session store (Redis), use client-side tokens (JWT)
Related Skills:
infrastructure-as-code - Deploy load balancers via Terraform/Pulumikubernetes-operations - Ingress controllers for K8s traffic managementnetwork-architecture - Network design and topology for load balancingdeploying-applications - Blue-green and canary deployments via load balancersobservability - Load balancer metrics, access logs, distributed tracingsecurity-hardening - WAF integration, rate limiting, DDoS protectionservice-mesh - Envoy as both ingress and service mesh proxyimplementing-tls - TLS termination and certificate management| Use Case | Recommended Solution | |----------|---------------------| | HTTP web app (AWS) | ALB | | Non-HTTP protocol (AWS) | NLB | | Kubernetes HTTP ingress | NGINX Ingress or Traefik | | Maximum performance | HAProxy | | Service mesh | Envoy | | Docker Swarm | Traefik | | Multi-cloud portable | NGINX or HAProxy | | Global distribution | CloudFlare, AWS Global Accelerator |
| Traffic Pattern | Algorithm | |-----------------|-----------| | Stateless, similar servers | Round Robin | | Stateless, different capacity | Weighted Round Robin | | Long-lived connections | Least Connections | | Performance-sensitive | Least Response Time | | Session persistence needed | IP Hash or Cookie | | Varying server load | Resource-Based |
| Service Type | Check Type | Interval | Timeout | |--------------|------------|----------|---------| | Web app | HTTP /health | 10s | 3s | | API | HTTP /health/ready | 10s | 5s | | Database | TCP connect | 5s | 2s | | Critical service | HTTP deep check | 5s | 3s | | Background worker | HTTP /live | 30s | 5s |
Load balancing is essential for distributing traffic, ensuring high availability, and enabling horizontal scaling. Choose L4 for raw performance and non-HTTP protocols, L7 for intelligent content-based routing. Prefer cloud-managed load balancers for simplicity and auto-scaling, self-managed for multi-cloud portability and advanced features. Implement proper health checks with hysteresis, avoid sticky sessions when possible, and monitor key metrics continuously.
For deployment patterns, see examples in examples/aws/, examples/nginx/, examples/kubernetes/, and other provider directories.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 16,547 | 18,233 | +10% | 1 | 1 | 0% | 2,745 | 6,564 | +139% | 0 | 0 | — |
case-02 | pass→pass | 18,494 | 13,725 | -26% | 1 | 1 | 0% | 2,884 | 5,772 | +100% | 0 | 0 | — |
case-03 | pass→pass | 24,526 | 10,128 | -59% | 1 | 1 | 0% | 2,147 | 5,361 | +150% | 0 | 0 | — |
case-04 | pass→pass | 15,561 | 15,062 | -3% | 1 | 1 | 0% | 2,285 | 5,994 | +162% | 0 | 0 | — |
case-05 | pass→pass | 16,133 | 19,777 | +23% | 1 | 1 | 0% | 2,398 | 6,831 | +185% | 0 | 0 | — |
case-06 | pass→pass | 11,199 | 7,011 | -37% | 1 | 1 | 0% | 1,959 | 4,840 | +147% | 0 | 0 | — |
case-07 | fail→pass | 17,631 | 12,693 | -28% | 1 | 1 | 0% | 2,311 | 5,465 | +136% | 0 | 0 | — |
case-08 | pass→pass | 9,860 | 10,332 | +5% | 1 | 1 | 0% | 1,668 | 4,869 | +192% | 0 | 0 | — |
case-09 | pass→pass | 17,913 | 11,032 | -38% | 1 | 1 | 0% | 1,899 | 5,237 | +176% | 0 | 0 | — |
case-10 | pass→pass | 11,950 | 11,249 | -6% | 1 | 1 | 0% | 2,031 | 5,429 | +167% | 0 | 0 | — |
case-11 | pass→pass | 15,617 | 13,986 | -10% | 1 | 1 | 0% | 2,104 | 5,581 | +165% | 0 | 0 | — |
case-12 | pass→pass | 8,696 | 7,991 | -8% | 1 | 1 | 0% | 1,442 | 4,794 | +232% | 0 | 0 | — |
case-13 | pass→pass | 6,643 | 10,940 | +65% | 1 | 1 | 0% | 1,165 | 5,581 | +379% | 0 | 0 | — |
case-14 | pass→pass | 9,322 | 5,213 | -44% | 1 | 1 | 0% | 1,059 | 4,670 | +341% | 0 | 0 | — |
case-15 | pass→pass | 4,553 | 5,575 | +22% | 1 | 1 | 0% | 916 | 4,660 | +409% | 0 | 0 | — |
case-16 | pass→pass | 22,527 | 15,027 | -33% | 1 | 1 | 0% | 2,138 | 5,837 | +173% | 0 | 0 | — |
case-17 | pass→pass | 19,233 | 26,644 | +39% | 1 | 1 | 0% | 3,345 | 7,045 | +111% | 0 | 0 | — |
case-18 | pass→pass | 15,068 | 12,775 | -15% | 1 | 1 | 0% | 2,444 | 5,674 | +132% | 0 | 0 | — |
case-19 | pass→pass | 18,185 | 20,702 | +14% | 1 | 1 | 0% | 2,888 | 6,907 | +139% | 0 | 0 | — |
case-20 | pass→pass | 3,781 | 3,972 | +5% | 1 | 1 | 0% | 670 | 4,290 | +540% | 0 | 0 | — |
case-21 | pass→pass | 9,038 | 6,591 | -27% | 1 | 1 | 0% | 1,704 | 4,730 | +178% | 0 | 0 | — |
case-22 | pass→pass | 15,354 | 18,384 | +20% | 1 | 1 | 0% | 2,722 | 6,694 | +146% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +5 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.