⚖️

C++ Load BalancerC++17

Production-quality TCP/HTTP load balancer — built from scratch, no libraries

Connecting…
Listen Port—TCP/HTTP frontend
Healthy Backends—waiting…
Active Connections—across all backends
AlgorithmLCLeast Connections
Polls Done0every 2 seconds
Backend Servers
Waiting for data… start the load balancer first.
Connection Distribution
Traffic split across all backends
Total Connections Over Time
⚡ Live Load Test

Fire concurrent HTTP requests directly to the load balancer and watch how it distributes traffic across backends in real time. Connection counts above animate as the requests hit.

1255075100
⚡
Fire requests to see them distributed across backends
Watch the backend connection counts animate above in real time
Algorithm

ℹ Apply via: kill -HUP $(pgrep load_balancer) after editing lb.conf

Live Stats JSON
Waiting for data…
Configuration
Port—
Stats Port—
Algorithmlc — Least-Connections
Thread Pool16 workers
Health Checkevery 5 s
Connection: closeinjected ✓
SIGHUP reloadalgo + weights
Event Log
load_balancer dashboard log
[2026-10-06 15:43:08] INFO Dashboard started. Connecting to stats endpoint…[2026-10-06 15:43:08] INFO Polling: /api/stats[2026-10-06 15:43:08] INFO Start LB: ./scripts/start.sh[2026-10-06 15:43:08] INFO Test: curl http://13.206.180.74:8080/
Architecture
Thread Model (single process)
• Main threadaccept() loop :8080
• Worker pool (16)handle_client() × N
• Health checkHTTP HEAD every 5 s
• Stats threadJSON on :8081
• SIGHUP threadsigwait() reload
Key Design Decisions
• TOCTOU-freeSingle mutex for select + increment
• atomic<Algorithm>Lock-free reads in worker threads
• SO_REUSEADDRInstant restart after crash
• Retry on failureNext healthy backend on connect fail
• sigwait()Safe async signal handling
🔀
4 Algorithms
LC · RR · IP-hash · Rendezvous HRW
⚖️
Weighted Backends
Per-backend traffic ratios
❤️
Health Checks
HTTP HEAD every 5 seconds
🧵
Thread Pool
Fixed 16 workers, no unbounded spawning
🔒
Connection Cap
Hard limit per backend — skip at capacity
🔁
SIGHUP Reload
Live config — zero downtime
📊
Stats Endpoint
JSON on :8081/stats
⚡
No Libraries
Pure C++17 · POSIX sockets only