> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ultrabalancer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Algorithms

> Load balancing algorithms explained

## Overview

UltraBalancer supports 7 algorithms. Choose based on your needs.

## Algorithms

### round-robin (default)

Even distribution across all backends.

```bash theme={null}
ultrabalancer -a round-robin -b s1:8080 -b s2:8080
```

**Best for:** Similar backends, stateless apps

### least-connections

Routes to backend with fewest active connections.

```bash theme={null}
ultrabalancer -a least-connections -b s1:8080 -b s2:8080
```

**Best for:** Variable response times, long connections

### ip-hash

Same client IP always goes to same backend.

```bash theme={null}
ultrabalancer -a ip-hash -b s1:8080 -b s2:8080
```

**Best for:** Session affinity needed

### random

Random backend selection.

```bash theme={null}
ultrabalancer -a random -b s1:8080 -b s2:8080
```

**Best for:** Simple distribution, development

### weighted

Higher weight = more requests.

```bash theme={null}
ultrabalancer -a weighted -b s1:8080:200 -b s2:8080:100
```

**Best for:** Backends with different capacities

### power-of-two

Picks 2 random backends, uses the one with fewer connections.

```bash theme={null}
ultrabalancer -a power-of-two -b s1:8080 -b s2:8080 -b s3:8080
```

**Best for:** High performance, distributed choice

### fastest-response

Routes to backend with fastest recent response.

```bash theme={null}
ultrabalancer -a fastest-response -b s1:8080 -b s2:8080
```

**Best for:** Latency-sensitive applications

## Quick Comparison

| Algorithm         | Use Case          |
| ----------------- | ----------------- |
| round-robin       | Default choice    |
| least-connections | Long requests     |
| ip-hash           | Sessions/sticky   |
| weighted          | Unequal backends  |
| power-of-two      | Performance       |
| fastest-response  | Latency-sensitive |
