Application-Aware Load Balancing

Application-Aware Load Balancing

High-traffic websites require intelligent traffic distribution that considers application state and server capacity:

# Nginx configuration for application-aware load balancing
upstream backend_servers {
    # Enable least connections with weights
    least_conn;
    
    # Define servers with health checks
    server backend1.example.com:8080 weight=3 max_fails=2 fail_timeout=30s;
    server backend2.example.com:8080 weight=3 max_fails=2 fail_timeout=30s;
    server backend3.example.com:8080 weight=2 max_fails=2 fail_timeout=30s;
    server backend4.example.com:8080 weight=2 max_fails=2 fail_timeout=30s;
    
    # Backup servers
    server backup1.example.com:8080 backup;
    server backup2.example.com:8080 backup;
    
    # Session persistence
    ip_hash;
    
    # Connection pooling
    keepalive 32;
    keepalive_requests 100;
    keepalive_timeout 60s;
}

# Health check configuration
match server_ok {
    status 200-399;
    header Content-Type ~ application/json;
    body ~ '"status":"healthy"';
}

upstream backend_servers_health {
    zone backend_health 64k;
    
    server backend1.example.com:8080;
    server backend2.example.com:8080;
    server backend3.example.com:8080;
    server backend4.example.com:8080;
    
    # Active health checks
    health_check interval=5s fails=2 passes=3 uri=/health match=server_ok;
}