# Balancing methods

A balancer that holds several servers with the same content picks one of them for every request. The balancing method is the rule it picks by. The weight and the role of each server change the outcome, and a server you switch off takes no part. With [Load Balancer](/en/documentation/platform/connectors/#load-balancer) enabled, a connector of type `http` makes this choice among its addresses, at the step described in [How Connectors works](/en/documentation/platform/connectors/how-it-works/#load-balancer).

The sections cover the balancing method, the weight, the server role, retries and timeouts, and active addresses, in that order.

---

## Balancing method

The balancing method decides which address of the connector receives each request. Load Balancer chooses among the addresses according to the method and to the weight each address carries. A connector with Load Balancer enabled holds up to 15 addresses. Each one takes the same fields as the single address of a connector without Load Balancer. For that bound, refer to [Connectors limits](/en/documentation/platform/connectors/limits/#load-balancer).

You choose one of three methods: *Round Robin*, *Least Connections*, or *IP Hash* in the **Method** field of Azion Console, and `round_robin`, `least_conn`, or `ip_hash` in the API. The default is `round_robin`. These three are the whole list, and none of them steers a request by the visitor's location or by a measured latency. Rules still decide which requests reach the connector at all, so a rule criterion such as the path decides which requests are balanced.

The Load Balancer configuration carries no health-check setting. It has no probe, no probe protocol, and no interval to set. Its fields are the method, **Max Retries**, **Connection Timeout**, and **Read/Write Timeout**, and each address adds its own **Server Role**, **Weight**, and **Active**.

### Round Robin

*Round Robin* hands requests to the addresses in rotation, so each address receives its turn. It counts requests and ignores how fast each address answers. Each address receives a share of the rotation in proportion to its weight, and with equal weights the shares are equal.

The cost is that a slow address keeps receiving its turn. Its requests take longer to finish, so it can hold more parallel connections than a fast address, while the number of requests stays even. Use *Round Robin* when the addresses have similar capacity and the requests take similar time.

### Least Connections

*Least Connections* tracks the active connections to each address. It sends the next request to the address that holds the fewest. A slow address keeps its connections open longer, so it receives fewer new requests, and a fast address handles more requests in succession.

Use *Least Connections* when the addresses differ in speed, or when some requests keep a connection open far longer than others. For example, when one address of a pair is a smaller server, that address finishes requests more slowly and receives fewer of them.

### IP Hash

*IP Hash* maps each client IP address to one address of the connector. Every request from the same client IP reaches the same address, so a visitor keeps reaching one origin server across requests. Use it when the origin keeps state for each visitor, such as a session held in the memory of one server.

The mapping follows the client IP address, not the visitor. A visitor whose IP address changes, such as a phone that moves from one network to another, can reach a different address. *IP Hash* also refuses backup addresses. A connector with `ip_hash` and an address whose `server_role` is `backup` is refused with `28005`: `Backup addresses are not allowed when using 'ip_hash' as load balance method.` Azion Console shows `Backup role is not available when the load balancing method is IP Hash.`

---

## Weight

The weight sets the share of requests an address receives, relative to the other addresses of the connector. A higher weight allocates more traffic to the address. The weight is a whole number from 1 to 100, and the default is `1`. Addresses left at the default share the traffic equally.

For example, with two primary addresses at weights 3 and 1, the first is meant to take three requests for each one the second takes. Use this when one server can take more load than another, such as a larger server beside a smaller one.

The weight sets a proportion, not an exact split. Each data center balances on its own, so the traffic one address receives across all data centers varies around the share its weight asks for. For how per-data-center balancing shapes the split, refer to [How Connectors works](/en/documentation/platform/connectors/how-it-works/#load-balancer).

---

## Server role

The server role of an address is *Primary* or *Backup* in Azion Console, and `primary` or `backup` in the API. Every address is `primary` unless you set it otherwise.

Load Balancer sends requests to the primary addresses first, and they are always preferred over the backup addresses. A backup address stands by, and it receives requests only when every primary address fails. Use a backup address for a server that must stay out of daily traffic, such as a standby copy of the origin in another location.

The cost is idle capacity: a backup address carries no traffic while the primary addresses answer. The server role works with *Round Robin* and *Least Connections*. Under *IP Hash*, every address must be `primary`, and a `backup` address is refused with `28005`.

---

## Retries and timeouts

Retries and timeouts exist on a connector only while Load Balancer is enabled. **Max Retries** sets the number of retry attempts when a connection to the origin fails, from 0 to 20. **Connection Timeout** limits the wait for a connection to the origin, in seconds. **Read/Write Timeout** limits the wait for data on a connection that is already open, in seconds.

The defaults depend on the interface that sets them. In the API, a key you leave out of the configuration takes the default: `max_retries` `0`, `connection_timeout` `60`, and `read_write_timeout` `120`. When you turn on **Load Balancer** in Azion Console, the form fills in `3`, `30`, and `60` instead. A connector created through the API therefore does not retry a failed connection until you raise `max_retries`.

Retries apply to a connection failure. Each retry gives a failed connection another chance, and the client waits through every attempt before it receives an answer. A short timeout gives up quickly on a slow origin, and a long one waits for an origin that answers slowly by design.

A connector without Load Balancer has no configurable timeout and no retry setting. For the platform defaults that apply then, refer to [How Connectors works](/en/documentation/platform/connectors/how-it-works/#connection-reuse-and-timeouts). For every field and its range, refer to [Connector settings](/en/documentation/platform/connectors/settings/#load-balancer).

---

## Active addresses

Each address carries an **Active** switch, `active` in the API, which is on by default. Turn it off to take an address out of rotation without deleting it, for maintenance or during an outage of that server. The address keeps its ports, role, and weight, so turning it back on restores it as it was.

An address with `active` set to `false` stops receiving requests once the change reaches the data center that handles the request. The change takes several minutes to spread, and data centers apply it at different times. Until every data center holds the change, some requests can still reach the inactive address. Keep the server answering until no request reaches it.

For how a change spreads across Azion's distributed infrastructure, refer to [How Connectors works](/en/documentation/platform/connectors/how-it-works/#propagation). For the address fields, refer to [Connector settings](/en/documentation/platform/connectors/settings/#addresses).

---

## Related resources

- [Connector settings](/en/documentation/platform/connectors/settings.md#load-balancer): Every Load Balancer field, with its values, defaults in each interface, and the address fields it works with.
- [Connectors limits](/en/documentation/platform/connectors/limits.md#load-balancer): The bounds on addresses, weight, retries, and timeouts, with the error each one returns.
- [Load Balancer quickstart](/en/documentation/platform/connectors/load-balancer/quickstart.md): Enable Load Balancer on a connector with two addresses and send requests through it.
- [Balance traffic across multiple origins](/en/documentation/guides/application-performance/availability/multiple-origins.md): The procedure that adds addresses to a connector and sets the method, weight, and server role of each.
