Skip to main content

Overview

UltraBalancer supports multiple configuration methods to fit different deployment scenarios. Choose the approach that works best for your infrastructure.

CLI Arguments

Quick setup with command-line flags

YAML Config

Human-readable configuration files

TOML Config

Type-safe structured configuration

Environment Variables

12-factor app compliance

Configuration Methods

1. Command-Line Arguments

Perfect for quick testing and simple deployments:
ultrabalancer \
  --port 8080 \
  --algorithm round-robin \
  --backend server1:8080 \
  --backend server2:8080 \
  --health-check-interval 5000
CLI arguments take precedence over config files. Use them to override specific settings in production.

2. YAML Configuration File

Recommended for production deployments:
config.yaml
listen_address: "0.0.0.0"
listen_port: 8080
algorithm: "round-robin"

backends:
  - host: "192.168.1.10"
    port: 8080
    weight: 100

  - host: "192.168.1.11"
    port: 8080
    weight: 100

health_check:
  enabled: true
  interval_ms: 5000
  max_failures: 3

timeout:
  connect_ms: 5000
  request_ms: 30000
ultrabalancer -c config.yaml

3. TOML Configuration File

Alternative structured format:
config.toml
listen_address = "0.0.0.0"
listen_port = 8080
algorithm = "round-robin"

[[backends]]
host = "192.168.1.10"
port = 8080
weight = 100

[[backends]]
host = "192.168.1.11"
port = 8080
weight = 100

[health_check]
enabled = true
interval_ms = 5000
max_failures = 3

[timeout]
connect_ms = 5000
request_ms = 30000
ultrabalancer -c config.toml

4. Environment Variables

12-factor app compliant configuration:
# Basic settings
export ULTRA_LISTEN_ADDRESS="0.0.0.0"
export ULTRA_LISTEN_PORT="8080"
export ULTRA_ALGORITHM="round-robin"

# Backends (comma-separated)
export ULTRA_BACKENDS="server1:8080,server2:8080,server3:8080"

# Health checks
export ULTRA_HEALTH_CHECK_ENABLED="true"
export ULTRA_HEALTH_CHECK_INTERVAL_MS="5000"
export ULTRA_HEALTH_CHECK_MAX_FAILURES="3"

# Timeouts
export ULTRA_TIMEOUT_CONNECT_MS="5000"
export ULTRA_TIMEOUT_REQUEST_MS="30000"

ultrabalancer

Configuration Hierarchy

Configuration values are resolved in the following order (highest to lowest priority):
1

Command-Line Arguments

Highest priority - always override other sources
ultrabalancer -c config.yaml --port 9090  # Port 9090 wins
2

Environment Variables

Second priority - useful for containerized deployments
export ULTRA_PORT=9090
ultrabalancer -c config.yaml  # Env var wins over file
3

Configuration File

Third priority - main configuration source
listen_port: 8080
4

Default Values

Lowest priority - sensible defaults
const DEFAULT_PORT: u16 = 8080;

Configuration Structure

Top-Level Options

listen_address
string
default:"0.0.0.0"
IP address to bind to. Use 0.0.0.0 for all interfaces, 127.0.0.1 for localhost only.
listen_port
integer
default:"8080"
Port number to listen on (1-65535).
algorithm
string
default:"round-robin"
Load balancing algorithm: round-robin, least-connections, ip-hash, random, weighted.
workers
integer
default:"auto"
Number of worker threads. Set to auto to match CPU cores.
max_connections
integer
default:"10000"
Maximum concurrent connections.

Backend Configuration

backends
array
required
Array of backend servers.
backends[].host
string
required
Backend hostname or IP address.
backends[].port
integer
required
Backend port number.
backends[].weight
integer
default:"100"
Backend weight for weighted algorithms (1-1000).
backends[].max_connections
integer
default:"1000"
Maximum connections per backend.

Health Check Configuration

health_check.enabled
boolean
default:"true"
Enable/disable health checking.
health_check.interval_ms
integer
default:"5000"
Health check interval in milliseconds.
health_check.timeout_ms
integer
default:"2000"
Health check timeout in milliseconds.
health_check.max_failures
integer
default:"3"
Number of failures before marking backend unhealthy.
health_check.path
string
default:"/"
HTTP path for health checks.

Timeout Configuration

timeout.connect_ms
integer
default:"5000"
Connection timeout in milliseconds.
timeout.request_ms
integer
default:"30000"
Request timeout in milliseconds.
timeout.idle_ms
integer
default:"60000"
Idle connection timeout in milliseconds.

Response Caching

cache.enabled
boolean
default:"false"
Enable response caching for GET/HEAD requests.
cache.max_size
integer
default:"10000"
Maximum number of cached responses.
cache.default_ttl_seconds
integer
default:"300"
Default TTL when no Cache-Control header present.

Compression

compression.enabled
boolean
default:"false"
Enable response compression.
compression.algorithm
string
default:"gzip"
Compression algorithm: gzip, brotli, zstd.
compression.min_size
integer
default:"1024"
Minimum response size to compress (bytes).

Rate Limiting

rate_limit.enabled
boolean
default:"false"
Enable rate limiting.
rate_limit.requests_per_second
integer
default:"1000"
Global rate limit (requests per second).
rate_limit.per_ip_rps
integer
default:"100"
Per-IP rate limit (requests per second).
rate_limit.burst
integer
default:"50"
Burst allowance above rate limit.

IP Filtering

ip_filter.whitelist
array
Array of allowed IP addresses/CIDR ranges. If set, only these IPs are allowed.
ip_filter.blacklist
array
Array of blocked IP addresses/CIDR ranges.

Sticky Sessions

sticky_sessions.enabled
boolean
default:"false"
Enable cookie-based sticky sessions.
Name of the session cookie.
sticky_sessions.ttl_seconds
integer
default:"3600"
Session TTL in seconds.

Retry Configuration

retry.enabled
boolean
default:"true"
Enable retry on backend failures.
retry.max_attempts
integer
default:"3"
Maximum retry attempts.
retry.backoff_ms
integer
default:"100"
Initial backoff delay in milliseconds.
retry.max_backoff_ms
integer
default:"5000"
Maximum backoff delay in milliseconds.

Access Logging

access_log.enabled
boolean
default:"false"
Enable access logging.
access_log.path
string
Path to access log file.
access_log.format
string
default:"combined"
Log format: combined, json.

TLS Configuration

tls.enabled
boolean
default:"false"
Enable TLS termination.
tls.cert_path
string
Path to TLS certificate file (PEM format).
tls.key_path
string
Path to TLS private key file (PEM format).

Complete Configuration Example

# UltraBalancer v3.0 Production Configuration

# Listener configuration
listen_address: "0.0.0.0"
listen_port: 443
workers: auto
max_connections: 50000

# Load balancing
algorithm: "least-connections"

# Backend servers
backends:
  - host: "backend1.prod.internal"
    port: 8080
    weight: 100
  - host: "backend2.prod.internal"
    port: 8080
    weight: 100
  - host: "backend3.prod.internal"
    port: 8080
    weight: 100

# Health checks
health_check:
  enabled: true
  interval_ms: 3000
  timeout_ms: 1500
  max_failures: 3
  path: "/health"

# Response caching
cache:
  enabled: true
  max_size: 10000
  default_ttl_seconds: 300

# Compression
compression:
  enabled: true
  algorithm: "gzip"      # gzip, brotli, zstd
  min_size: 1024

# Rate limiting
rate_limit:
  enabled: true
  requests_per_second: 10000
  per_ip_rps: 100
  burst: 50

# IP filtering
ip_filter:
  blacklist:
    - "10.0.0.0/8"       # Block internal probes

# Sticky sessions
sticky_sessions:
  enabled: true
  cookie_name: "ULTRABALANCER_SESSION"
  ttl_seconds: 3600

# Retry with backoff
retry:
  enabled: true
  max_attempts: 3
  backoff_ms: 100
  max_backoff_ms: 5000

# Access logging
access_log:
  enabled: true
  path: "/var/log/ultrabalancer/access.log"
  format: "json"

# TLS termination
tls:
  enabled: true
  cert_path: "/etc/ultrabalancer/cert.pem"
  key_path: "/etc/ultrabalancer/key.pem"

# Graceful shutdown
shutdown:
  timeout_seconds: 30
  drain_connections: true

Validation

Validate your configuration before deployment:
ultrabalancer validate -c config.yaml

Configuration Templates

Development Template

config-dev.yaml
listen_address: "127.0.0.1"
listen_port: 8080
algorithm: "round-robin"

backends:
  - host: "localhost"
    port: 3001
  - host: "localhost"
    port: 3002

health_check:
  enabled: true
  interval_ms: 10000        # Less aggressive
  max_failures: 5

logging:
  level: "debug"
  format: "text"

Staging Template

config-staging.yaml
listen_address: "0.0.0.0"
listen_port: 8080
algorithm: "least-connections"

backends:
  - host: "backend1.staging.internal"
    port: 8080
  - host: "backend2.staging.internal"
    port: 8080

health_check:
  enabled: true
  interval_ms: 5000
  max_failures: 3

logging:
  level: "info"
  format: "json"

Production Template

config-prod.yaml
listen_address: "0.0.0.0"
listen_port: 443
algorithm: "least-connections"
workers: auto
max_connections: 50000

backends:
  - host: "backend1.prod.internal"
    port: 8080
    weight: 100
  - host: "backend2.prod.internal"
    port: 8080
    weight: 100

health_check:
  enabled: true
  interval_ms: 3000
  max_failures: 3

cache:
  enabled: true
  max_size: 10000

compression:
  enabled: true
  algorithm: "gzip"

rate_limit:
  enabled: true
  requests_per_second: 10000
  per_ip_rps: 100

retry:
  enabled: true
  max_attempts: 3

access_log:
  enabled: true
  path: "/var/log/ultrabalancer/access.log"
  format: "json"

tls:
  enabled: true
  cert_path: "/etc/ultrabalancer/cert.pem"
  key_path: "/etc/ultrabalancer/key.pem"

shutdown:
  timeout_seconds: 30
  drain_connections: true

Dynamic Configuration Reload

UltraBalancer supports hot-reloading configuration without downtime:
# Send SIGHUP signal to reload config
kill -HUP $(pidof ultrabalancer)

# Or use systemd
systemctl reload ultrabalancer
Configuration reload will:
  • Update backend list (add/remove/modify backends)
  • Change algorithm settings
  • Adjust health check parameters
NOT reloaded:
  • Listen address/port (requires restart)
  • Worker count (requires restart)
  • TLS certificates (requires restart)

Best Practices

Configuration Tips
  1. Use config files in production - More maintainable than CLI args
  2. Version control your configs - Track changes over time
  3. Validate before deployment - Use validate command
  4. Use environment variables for secrets - Don’t commit credentials
  5. Start with templates - Modify for your needs
  6. Document custom settings - Add comments explaining why

Security Considerations

config.yaml
# DON'T: Hard-code secrets
tls:
  key_password: "mysecretpassword"  # Bad!

# DO: Use environment variables
tls:
  key_password: "${TLS_KEY_PASSWORD}"  # Good!
# Set secrets via environment
export TLS_KEY_PASSWORD="mysecretpassword"
ultrabalancer -c config.yaml