# Load Balancing Algorithms

> Choose load-balancing tiers and algorithms (round-robin, least-conn, consistent hash, Maglev-style) for L4 vs L7, with affinity and health-check guidance. Use when designing traffic distribution or fixing imbalance.

- Skill: `deangrant/load-balancing-algorithms` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add deangrant/load-balancing-algorithms`
- Raw SKILL.md: https://api.skillmd.com/api/skills/deangrant/load-balancing-algorithms/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: deangrant (https://skillmd.com/u/deangrant)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/deangrant/load-balancing-algorithms

---


# Load Balancing Algorithms

Use this skill when distributing traffic across backends.

---

## 1. Problem shape

Goals: availability, scale, latency. Homogeneous short HTTP vs variable work?
Need affinity (sessions/cache) or fully stateless? Flash crowds may need
admission **before** the LB.

---

## 2. L4 vs L7

- **L7:** content routing (URL, headers, cookies).
- **L4:** TLS passthrough, raw TCP/UDP, max PPS.

---

## 3. Algorithms (common)

| Algo | When |
| ---- | ---- |
| Round-robin / WRR | Homogeneous backends |
| Least connections | Variable request cost |
| Consistent hash / Maglev | Affinity, cache locality, graceful churn |
| Random / power-of-two | Simple good-enough with peer metrics |

Prefer **stateless backends** over sticky sessions when possible. Health checks
must match readiness (not just liveness).

---

## 4. Quick checklist

- [ ] L4 vs L7 chosen deliberately.
- [ ] Algorithm matches workload skew.
- [ ] Affinity justified or eliminated.
- [ ] Health checks = ready to serve.
- [ ] Imbalance metrics watched (p99 per backend).

See [reference.md](reference.md) and [examples.md](examples.md).

