Load Balancing
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Load balancing distributes traffic across multiple targets to improve availability, performance, and resilience. This guide covers algorithms, health checks, session persistence, TLS termination, and operational best practices for implementing robust load balancing solutions.
Why This Matters
Load balancing is critical for modern applications because it:
- Improves availability by eliminating single points of failure
- Enhances performance by distributing load across healthy targets
- Enables horizontal scaling to handle traffic spikes
- Provides graceful degradation when targets fail
- Supports zero-downtime deployments with connection draining
- Enables global traffic distribution for multi-region deployments
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
Skill Composition
- Depends on: git-workflow
- Compatible with: None
- Conflicts with: None
- Related Skills: docker, kubernetes
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions
- Backend targets are healthy and responsive
- Network connectivity between load balancer and targets
- Sufficient capacity to handle expected traffic
- Health check endpoints are implemented on all targets
- TLS certificates are available for HTTPS
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives
When configuring load balancers:
- Always validate configuration before applying
- Test health checks against all targets
- Monitor distribution after changes
- Implement gradual rollouts for major changes
- Have rollback plans ready
- Document all changes with clear reasons
Definition of Done (DoD) Checklist
Anti-patterns
- No health checks: Always implement health checks
- Ignoring uneven distribution: Monitor and address distribution issues
- Overusing sticky sessions: Only use when necessary
- Single point of failure: Always have redundancy
- Ignoring TLS: Always use HTTPS in production
- No monitoring: Without monitoring, you can't detect issues
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: load-balancing3description: Load balancing distributes traffic across multiple targets to improve Use when this capability is needed.4---56# Load Balancing78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17Load balancing distributes traffic across multiple targets to improve availability, performance, and resilience. This guide covers algorithms, health checks, session persistence, TLS termination, and operational best practices for implementing robust load balancing solutions.1819## Why This Matters20Load balancing is critical for modern applications because it:2122- **Improves availability** by eliminating single points of failure23- **Enhances performance** by distributing load across healthy targets24- **Enables horizontal scaling** to handle traffic spikes25- **Provides graceful degradation** when targets fail26- **Supports zero-downtime deployments** with connection draining27- **Enables global traffic distribution** for multi-region deployments2829---3031## Core Concepts & Rules3233### 1. Core Principles34- Follow established patterns and conventions35- Maintain consistency across codebase36- Document decisions and trade-offs3738### 2. Implementation Guidelines39- Start with the simplest viable solution40- Iterate based on feedback and requirements41- Test thoroughly before deployment424344## Inputs / Outputs / Contracts45#4647## Skill Composition48* **Depends on**: [git-workflow](..\..\01-foundations\git-workflow/SKILL.md)49* **Compatible with**: None50* **Conflicts with**: None51* **Related Skills**: [docker](..\docker-compose/SKILL.md), [kubernetes](..\kubernetes-deployment/SKILL.md)5253## Quick Start / Implementation Example54551. Review requirements and constraints562. Set up development environment573. Implement core functionality following patterns584. Write tests for critical paths595. Run tests and fix issues606. Document any deviations or decisions6162```python63# Example implementation following best practices64def example_function():65 # Your implementation here66 pass67```686970## Assumptions71- Backend targets are healthy and responsive72- Network connectivity between load balancer and targets73- Sufficient capacity to handle expected traffic74- Health check endpoints are implemented on all targets75- TLS certificates are available for HTTPS7677## Compatibility & Prerequisites7879* **Supported Versions**:80 - Python 3.8+81 - Node.js 16+82 - Modern browsers (Chrome, Firefox, Safari, Edge)83* **Required AI Tools**:84 - Code editor (VS Code recommended)85 - Testing framework appropriate for language86 - Version control (Git)87* **Dependencies**:88 - Language-specific package manager89 - Build tools90 - Testing libraries91* **Environment Setup**:92 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)939495## Test Scenario Matrix (QA Strategy)9697| Type | Focus Area | Required Scenarios / Mocks |98| :--- | :--- | :--- |99| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |100| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |101| **E2E** | User Journey | Critical user flows to test |102| **Performance** | Latency / Load | Benchmark requirements |103| **Security** | Vuln / Auth | SAST/DAST or dependency audit |104| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |105106107## Technical Guardrails & Security Threat Model108109### 1. Security & Privacy (Threat Model)110* **Top Threats**: Injection attacks, authentication bypass, data exposure111- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII112- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager113- [ ] **Authorization**: Validate user permissions before state changes114115### 2. Performance & Resources116- [ ] **Execution Efficiency**: Consider time complexity for algorithms117- [ ] **Memory Management**: Use streams/pagination for large data118- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks119120### 3. Architecture & Scalability121- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection122- [ ] **Modularity**: Decouple logic from UI/Frameworks123124### 4. Observability & Reliability125- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`126- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`127- [ ] **Error Handling**: Standardized error codes, no bare except128- [ ] **Observability Artifacts**:129 - **Log Fields**: timestamp, level, message, request_id130 - **Metrics**: request_count, error_count, response_time131 - **Dashboards/Alerts**: High Error Rate > 5%132133134## Agent Directives135When configuring load balancers:1361371. **Always validate** configuration before applying1382. **Test health checks** against all targets1393. **Monitor distribution** after changes1404. **Implement gradual rollouts** for major changes1415. **Have rollback plans** ready1426. **Document all changes** with clear reasons143144## Definition of Done (DoD) Checklist145146- [ ] Tests passed + coverage met147- [ ] Lint/Typecheck passed148- [ ] Logging/Metrics/Trace implemented149- [ ] Security checks passed150- [ ] Documentation/Changelog updated151- [ ] Accessibility/Performance requirements met (if frontend)152153154## Anti-patterns1551. **No health checks**: Always implement health checks1562. **Ignoring uneven distribution**: Monitor and address distribution issues1573. **Overusing sticky sessions**: Only use when necessary1584. **Single point of failure**: Always have redundancy1595. **Ignoring TLS**: Always use HTTPS in production1606. **No monitoring**: Without monitoring, you can't detect issues161162## Reference Links & Examples163164* Internal documentation and examples165* Official documentation and best practices166* Community resources and discussions167168169## Versioning & Changelog170171* **Version**: 1.0.0172* **Changelog**:173 - 2026-02-22: Initial version with complete template structure174175---176> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.177<!-- tomevault:4.0:skill_md:2026-04-13 -->