OpenBalancer Logo OpenBalancer
v1.4.0-stable • MIT Core • Python 3.11+

Technical Documentation

Complete engineering reference, kernel event loop architecture, configuration schema, Prometheus metrics, and interactive developer tools.

What is OpenBalancer? #

OpenBalancer is an ultra-fast, asynchronous load balancer and API reverse proxy built specifically for high-throughput AI model inference clusters, microservice meshes, and mission-critical API routing. Written from the ground up on non-blocking Python asyncio raw sockets, OpenBalancer eliminates unnecessary middleware layers to deliver sub-millisecond p99 routing overhead.

💡
100% Data Sovereignty & Zero Vendor Lock-in: OpenBalancer runs completely standalone with zero external cloud dependencies, third-party analytics trackers, or closed telemetry beacons. It is ideal for isolated VPCs, air-gapped on-premise servers, and GDPR/HIPAA regulated infrastructure.

Core Architectural Highlights

  • Non-Blocking Asynchronous Socket Loop: Pipes incoming client requests to upstream backends asynchronously using raw TCP stream readers and writers without threading locks.
  • AI LLM Streaming & SSE Passthrough: Zero response buffering for text/event-stream and application/grpc, ensuring instant token-by-token streaming with constant O(1) memory consumption.
  • Active Background Health Probing: Continuously interrogates upstream backend health paths at configurable intervals with sub-millisecond latency tracking.
  • Automatic Circuit Breaking: Immediately isolates flapping or failing upstream nodes after consecutive probe failures, preventing cascading microservice collapse.
  • Prometheus Telemetry & JSON Status: Native built-in endpoints at /openbalancer/status and /metrics for turnkey Grafana observability.

Quickstart & Installation #

Get OpenBalancer running in under 60 seconds using Docker, Docker Compose, or standalone Python.

1. Run via Docker (Recommended)

BASH / DOCKER
docker run -d \
  --name openbalancer \
  -p 8080:8080 \
  -v $(pwd)/config.json:/app/config.json \
  openbalancer/core:latest

2. Run with Docker Compose (Full Multi-Backend Test)

BASH
git clone https://github.com/incontrolplus/openbalancer.git
cd openbalancer/core
docker compose up -d

3. Standalone Python (Zero Dependencies)

BASH
# Requires Python 3.11+ (Standard Library only - 0 pip packages required)
python3 openbalancer.py config.json

4. Verify Ingress & Status

BASH
# Test Load Balancer Ingress
curl -i http://localhost:8080/

# Query JSON Cluster Telemetry
curl http://localhost:8080/openbalancer/status

# Scrape Prometheus Metrics
curl http://localhost:8080/metrics

Kernel & Event Loop Architecture #

OpenBalancer utilizes single-threaded non-blocking cooperative multitasking via Python's asyncio socket event loop. By bypassing traditional thread pools and GIL contention, it maintains a lightweight footprint (~18MB RSS) capable of handling tens of thousands of concurrent open TCP streams.

Zero-Copy Bufferless Streaming Pipeline: When proxying streaming responses (e.g. OpenAI/Claude SSE completion streams or gRPC chunks), OpenBalancer bypasses internal aggregation buffers and streams chunks directly between socket descriptors in real time.

Circuit Breaker & Health Probing State Machine

Every configured upstream node is evaluated across a robust state machine:

State Trigger Condition Routing Behavior Recovery Process
HEALTHY Health check returns HTTP 200 OK within timeout limit. Receives full traffic proportional to its configured weight. Active probe continues at health_interval frequency.
DEGRADED 1 or more probe timeouts or 5xx responses. Traffic remains routed, but warning metrics increment. Monitored for consecutive failures.
TRIPPED / DOWN consecutive_failures >= threshold (default: 3). Immediately isolated. Zero ingress traffic routed to this node. Background probes continue until 2 consecutive 200 OK probes restore health.

Routing Algorithms #

OpenBalancer provides 6 production-ready load balancing strategies switchable at runtime or via configuration:

Algorithm Identifier Routing Logic Best For Complexity
round_robin Distributes requests evenly in circular sequence across all healthy backends. Homogeneous backend nodes with uniform request cost. O(1)
weighted / weighted_round_robin Routes traffic proportional to each node's capacity weight integer (e.g. 3:2:1). Heterogeneous servers (e.g., 8-GPU node vs 2-GPU node). O(1)
least_latency / latency Directs incoming requests to the backend with the lowest recent health check latency. Multi-region backends or variable inference workloads. O(N)
least_connections / least_conn Selects the healthy node with the lowest number of active open TCP sockets. Long-lived HTTP/1.1 connections, WebSockets, SSE streams. O(N)
ip_hash / consistent_hash Hashes client source IP (MD5 hash ring) to bind client sessions to a sticky backend. Stateful web sessions, cache locality, sticky user state. O(1)
power_of_two / p2c Picks two random healthy nodes and routes to the one with fewer active connections. Massive clusters avoiding the herd effect with O(1) selection overhead. O(1)

Setting the Algorithm in config.json

JSON
{
  "algorithm": "least_latency"
}

Configuration Schema (`config.json`) #

OpenBalancer reads its initial topology from config.json. All parameters can be hot-reloaded without downtime via SIGHUP.

Property Type Default Description
host String "0.0.0.0" Bind interface IP address for listening to ingress traffic.
port Integer 8080 TCP listening port for client requests.
algorithm String "round_robin" Balancing algorithm: round_robin, weighted, least_latency, least_connections, ip_hash, power_of_two.
health_interval Integer 5 Interval in seconds between active background health checks.
health_timeout_ms Integer 500 Socket timeout in milliseconds for health probe responses.
circuit_breaker_failures Integer 3 Consecutive failed probes before marking a node UNHEALTHY and tripping circuit breaker.
backends Array[Object] [] List of upstream backend target definitions.
backends[].host String Target upstream host IP or hostname (e.g. "127.0.0.1" or "ai-node-1").
backends[].port Integer Target upstream TCP port (e.g. 9001).
backends[].weight Integer 1 Traffic distribution weight multiplier (from 1 to 100).
backends[].health_path String "/health" HTTP endpoint path polled for health evaluation.

Environment Variable Overrides

For Twelve-Factor App compliance and container environments, all primary options can be overridden via environment variables:

Environment Variable Overrides Config Key Example Value
PORT port PORT=9000
HOST host HOST=127.0.0.1
ALGORITHM algorithm ALGORITHM=least_latency
HEALTHCHECK_INTERVAL health_interval HEALTHCHECK_INTERVAL=3

Interactive JSON Configuration Builder #

Configure your cluster parameters visually below. The schema updates in real time with 1-click clipboard copy and direct JSON file download.

Health Probe Interval 3s
Circuit Breaker Failures Threshold 3 failures
config.json (Live Validated)

Custom Error Page Studio #

Design, live-preview, and export branded, lightweight standalone HTML error pages for 429 Rate Limiting, 502 Bad Gateway, and 503 Outage scenarios. Zero external dependencies, automatic countdown retry logic, and pixel-perfect design.

LIVE INTERACTIVE PREVIEW
🛡️
HTTP 429 TOO MANY REQUESTS

Rate Limit Exceeded (429)

Too many concurrent requests were received. Your token bucket will automatically refill shortly.

⏱️ Automatic reconnection in 15 seconds
Zero external assets • Standalone self-contained HTML

Telemetry & Prometheus API #

OpenBalancer features built-in, zero-dependency observability endpoints natively exposing cluster telemetry in both structured JSON and standard Prometheus scrape formats.

1. Status & Topology API (`GET /openbalancer/status`)

Returns real-time cluster uptime, total proxied requests, selected algorithm, and per-node health status, latency, and circuit breaker trip counts.

JSON RESPONSE — 200 OK
{
  "system": "OpenBalancer Core",
  "operator": "INCONTROL PLUS EOOD",
  "license": "MIT",
  "uptime_seconds": 14280,
  "total_proxied_requests": 849200,
  "algorithm": "least_latency",
  "backends": [
    {
      "url": "http://10.0.1.10:8000",
      "healthy": true,
      "weight": 3,
      "total_requests": 424600,
      "last_latency_ms": 1.18,
      "circuit_trips": 0
    },
    {
      "url": "http://10.0.1.11:8000",
      "healthy": true,
      "weight": 2,
      "total_requests": 283100,
      "last_latency_ms": 1.42,
      "circuit_trips": 0
    },
    {
      "url": "http://10.0.1.12:8000",
      "healthy": true,
      "weight": 1,
      "total_requests": 141500,
      "last_latency_ms": 1.85,
      "circuit_trips": 0
    }
  ]
}

2. Prometheus Metrics (`GET /metrics`)

Compatible out of the box with Prometheus, VictoriaMetrics, and Grafana Agent without requiring an external exporter sidecar.

PROMETHEUS TEXT FORMAT
# HELP openbalancer_requests_total Total number of proxied HTTP requests
# TYPE openbalancer_requests_total counter
openbalancer_requests_total 849200

# HELP openbalancer_uptime_seconds OpenBalancer uptime in seconds
# TYPE openbalancer_uptime_seconds gauge
openbalancer_uptime_seconds 14280

# HELP openbalancer_backend_health_status Health status of backend node (1=healthy, 0=down)
# TYPE openbalancer_backend_health_status gauge
openbalancer_backend_health_status{backend="http://10.0.1.10:8000",host="10.0.1.10",port="8000"} 1
openbalancer_backend_health_status{backend="http://10.0.1.11:8000",host="10.0.1.11",port="8000"} 1

# HELP openbalancer_backend_latency_ms Last probed health check latency in milliseconds
# TYPE openbalancer_backend_latency_ms gauge
openbalancer_backend_latency_ms{backend="http://10.0.1.10:8000",host="10.0.1.10",port="8000"} 1.18
openbalancer_backend_latency_ms{backend="http://10.0.1.11:8000",host="10.0.1.11",port="8000"} 1.42

# HELP openbalancer_circuit_breaker_trips_total Total circuit breaker trip events
# TYPE openbalancer_circuit_breaker_trips_total counter
openbalancer_circuit_breaker_trips_total{backend="http://10.0.1.10:8000",host="10.0.1.10",port="8000"} 0

Real-Time Latency Heatmap & Flamegraph #

Observe real-time latency distribution across 4 discrete threshold buckets (<10ms green, 10-50ms cyan, 50-200ms yellow, >200ms red) with live percentile calculations and execution waterfall stages.

Real-Time Latency Heatmap & Flamegraph DYNAMIC 60FPS
p501.1ms
p907.9ms
p9913.8ms
p99.924.5ms
<10ms (Optimal) 84%
10-50ms (Normal) 13%
50-200ms (Spike) 2%
>200ms (Degraded) 1%

Interactive API Tester ("Try it Out") #

Test OpenBalancer management and telemetry endpoints in real time. Choose an endpoint below and click Execute Request. If running locally, you can query your live instance, or use our high-fidelity simulated sandbox engine.

GET
Status: 200 OK Latency: 1.18 ms Type: application/json

Production Deployment & Docker #

Deploying OpenBalancer in mission-critical environments with automatic restart policies, healthchecks, and resource constraints.

1. Complete Production Dockerfile

DOCKERFILE
FROM python:3.11-alpine

WORKDIR /app

COPY openbalancer.py config.json /app/

EXPOSE 8080

HEALTHCHECK --interval=5s --timeout=2s --start-period=3s --retries=3 \
  CMD python3 -c "import urllib.request; urllib.request.urlopen(\"http://127.0.0.1:8080/openbalancer/status\", timeout=2)" || exit 1

ENTRYPOINT ["python3", "openbalancer.py", "config.json"]

2. Production Docker Compose Stack

YAML
services:
  openbalancer:
    image: openbalancer/core:latest
    container_name: openbalancer
    restart: unless-stopped
    ports:
      - "8080:8080"
    volumes:
      - ./config.json:/app/config.json:ro
    environment:
      - PORT=8080
      - ALGORITHM=least_latency
    deploy:
      resources:
        limits:
          cpus: "2.0"
          memory: 128M

3. Systemd Unit File (`/etc/systemd/system/openbalancer.service`)

INI / SYSTEMD
[Unit]
Description=OpenBalancer AI & API Reverse Proxy Core
After=network.target

[Service]
Type=simple
User=openbalancer
Group=openbalancer
WorkingDirectory=/opt/openbalancer
ExecStart=/usr/bin/python3 /opt/openbalancer/openbalancer.py /etc/openbalancer/config.json
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=3
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

Zero-Downtime Hot Reload (`SIGHUP`) #

OpenBalancer listens for POSIX SIGHUP signals. When received, the core re-reads config.json from disk, reconstructs upstream pools, updates routing weights, and adjusts probing intervals without dropping active client TCP connections or interrupting streaming responses.

BASH
# Send SIGHUP to standalone process
kill -HUP $(pgrep -f openbalancer.py)

# Send SIGHUP to Docker container
docker kill -s HUP openbalancer

# OpenBalancer output confirms reload:
# 2026-08-18 10:45:00 [INFO] [OpenBalancer] SIGHUP received: Reloading config.json
# 2026-08-18 10:45:00 [INFO] [OpenBalancer] Loaded 3 backends. Strategy: least_latency. Port: 8080

Performance & Benchmarks #

Measured on bare-metal Linux (AMD EPYC 7763, 64 Cores, 10GbE network link) running wrk -t16 -c1000 -d30s against 3 upstream nodes.

Load Balancer / Proxy Throughput (Req/sec) p99 Latency Overhead Memory Footprint (RSS) Zero-Config SSE Streaming
OpenBalancer v1.4 52,400+ 0.84 ms 18 MB Native (Zero-Copy)
NGINX Community (Default) 58,000 1.12 ms 45 MB Requires proxy_buffering off;
HAProxy 2.8 62,000 0.78 ms 38 MB Requires custom buffer tunables
Traefik v3.0 34,000 2.45 ms 110 MB Built-in
📊
Reproduce Benchmarks Locally: Run bombardier -c 500 -n 100000 http://localhost:8080/ to verify local throughput and sub-millisecond response consistency.

Enterprise SLA & Support #

OpenBalancer is maintained and commercially backed by INCONTROL PLUS ЕООД. For production enterprise deployments requiring guaranteed uptime, sub-15 minute emergency incident escalation, and custom AI dispatcher integrations, we provide contractual B2B Master Services Agreements (MSAs).

🛡️

Contractual 99.9% Uptime Guarantee

Backed by formal contractual service credits for any monthly downtime below 99.9%. Net-14 corporate invoicing and instant Stripe Card checkout supported.

Request Enterprise SLA Contract Company Impressum & Verification