Back to docs
Recipe

Load Balancer Patterns

Production-tested strategies for distributing traffic across Nimbus backend nodes with zero-downtime failover.

Round‑Robin

Each request cycles to the next healthy backend in sequence. Simplest to implement, works well when all nodes have identical capacity and request cost is uniform.

upstream nimbus_backend {
  server backend1:9000;
  server backend2:9000;
  server backend3:9000;
}

Least Connections

Routes to the node with the fewest active connections. Ideal when request durations vary significantly or when backend capacity is heterogeneous.

upstream nimbus_backend {
  least_conn;
  server backend1:9000 weight=3;
  server backend2:9000 weight=1;
}

IP Hash

Hashes the client IP to pin sessions to a specific backend. Useful for stateful workloads where sticky sessions avoid cache invalidation storms.

upstream nimbus_backend {
  ip_hash;
  server backend1:9000;
  server backend2:9000;
}

Health Checks

Active probes detect dead backends before they receive traffic. Combine with passive checks (observing 5xx responses) for defense in depth.

health_check interval=5s fails=3 passes=2 uri=/health;

Circuit Breaker

When a backend exceeds a failure threshold, the circuit opens and traffic is diverted. After a cooldown, a trickle of requests probes for recovery before fully closing the circuit.

server backend1:9000 max_fails=3 fail_timeout=30s;

Pro tip: Layer IP hash with least connections for hybrid sticky‑aware balancing. Always deploy health checks before going to production.