---
name: azion-balance-traffic-across-multiple-origins
description: >-
  Spread the requests of an Application across several origin addresses with an origin of the Load Balancer type.
---

# Balance traffic across multiple origins

> Platform versions: this page applies to API v3.x only, not to API v6.x and API v4.x.
> Equivalent page for API v4.x: [Balance traffic across multiple origins](/en/documentation/guides/application-performance/availability/multiple-origins.md)
> Release stage: Deprecated.

You can spread the requests of an [Application](/en/documentation/platform/applications/v3/) across several origin servers with [Load Balancer](/en/documentation/platform/connectors/load-balancer/), from Azion Console or the API. Load balancing belongs to an origin of the Application, of the *Load Balancer* type, and Load Balancer distributes the requests among the addresses of that origin with a balancing method. A rule with the *Set Origin* behavior sets the origin of the requests it matches. For every field of an origin, refer to [Origins](/en/documentation/platform/connectors/origins/).

> **Caution**
>
> With Load Balancer enabled, data transfer can generate usage-related costs. For more information, refer to [Pricing](/en/documentation/fundamentals/pricing/).

---

## Prerequisites

### Console

- An Application, and a hostname that reaches it.
- Two or more origin servers that hold the same content and are set up the same way for the Application.
- `curl`, to request the hostname.
- Access to Azion Console. To sign in, refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).

### API

- An Application, and a hostname that reaches it.
- Two or more origin servers that hold the same content and are set up the same way for the Application.
- A personal token, sent in the `Authorization` header as `Token [TOKEN VALUE]`. To create one, refer to [Manage a personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/).
- `curl`, or another HTTP client.
- The ID of the Application.

---

## Plan the addresses

The example on this page balances three origin servers. Each one is hosted with a different storage provider or cloud service, because server outages rarely occur at the same time. All three hold the same content and are set up the same way for the Application. Two of them share the traffic, and the third stands by for the case where both fail.

| Address       | Server    | Load capacity                              | Weight                                         | Server role | Active |
| ------------- | --------- | ------------------------------------------ | ---------------------------------------------- | ----------- | ------ |
| `example.com` | Primary   | High                                       | `3`                                            | `primary`   | Always |
| `example.net` | Secondary | Medium, enough for large surges of traffic | `2`                                            | `primary`   | Always |
| `example.org` | Backup    | Low                                        | `1`, the default when the weight is left blank | `backup`    | Always |

The weight follows the load capacity of each server. Both `example.com` and `example.net` are primary, so `example.com` receives about three requests for every two that `example.net` receives. `example.org` receives requests only when both primary addresses fail. It stays active, because an address that is not active receives no request, even as a backup. For how the weight, the server role, and the active state distribute requests, refer to [Balancing methods](/en/documentation/platform/connectors/load-balancer/balancing-methods/#weight).

---

## Balance the addresses on an origin

### Console

Load Balancer is a setting on the Application, and the addresses sit on one origin. To set both in Azion Console:

1. **Open the Application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your Application**.

2. **Turn on Load Balancer**

   In the **Main Settings** tab, under **Modules**, turn on **Load Balancer**.

3. **Save the Application**

4. **Open the origin**

   In the **Origins** tab, select **Default Origin** to balance the addresses the Application already uses, or **+ Origin** to add a separate one. Editing the default origin replaces the address the Application was created with.

5. **Name the origin and choose its type**

   Enter a name and set **Type** to *Load Balancer*.

6. **Choose the balancing method**

   In **Method**, select a method, such as *Round-Robin*.

7. **Add the first address**

   In the first **Address** field, enter the primary server. In **Weight**, enter its share of the requests, such as `3` for a server with more capacity. In **Server Role**, keep *Primary*, and keep the address **Active**.

8. **Add the other addresses**

   Select **+ Add Origin** for each further address. A **Weight** left blank takes `1`. An address with **Server Role** set to *Backup* receives requests only when the primary addresses fail, and an address with **Active** off receives none.

9. **Save the origin**

   Select **Save**.

### API

To balance the addresses with the API, first read the `origin_key` of the origin you want to change. The request carries the header `Accept: application/json; version=3`:

```bash
curl --request GET \
  --url https://api.azionapi.net/edge_applications/<application-id>/origins \
  --header 'Accept: application/json; version=3' \
  --header 'Authorization: Token [TOKEN VALUE]'
```

The response lists the origins of the application. Each one carries `origin_key`, a UUID, beside `origin_type` and its name:

```json
{
  "results": [
    {
      "origin_id": 123456,
      "origin_key": "bdcd7003-ba53-4ed8-8ca0-05b1357cdafd",
      "name": "Default Origin",
      "origin_type": "single_origin"
    }
  ]
}
```

Then send a `PATCH` to that origin with the full list of addresses:

```bash
curl --request PATCH \
  --url https://api.azionapi.net/edge_applications/<application-id>/origins/<origin-key> \
  --header 'Accept: application/json; version=3' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Token [TOKEN VALUE]' \
  --data '{
  "name": "Default Origin (RR3)",
  "origin_type": "load_balancer",
  "method": "round_robin",
  "host_header": "${host}",
  "addresses": [
    { "address": "example.com", "weight": 3, "server_role": "primary", "is_active": true },
    { "address": "example.net", "weight": 2, "server_role": "primary", "is_active": true },
    { "address": "example.org", "weight": 1, "server_role": "backup", "is_active": true }
  ]
}'
```

| Key                       | What it carries                                                                    |
| ------------------------- | ---------------------------------------------------------------------------------- |
| `origin_type`             | `load_balancer` turns the origin into a balanced one. Load Balancer has to be on   |
| `method`                  | The balancing method, such as `round_robin`                                        |
| `addresses[].weight`      | The share of requests the address takes. Omitted, it is `1`                        |
| `addresses[].server_role` | `primary`, or `backup` for an address that answers only when the primary ones fail |
| `addresses[].is_active`   | `false` keeps the address in the list and out of rotation                          |

The response returns the origin as Azion stored it, with the addresses in the order you sent them:

```json
{
  "results": {
    "origin_id": 123456,
    "origin_key": "bdcd7003-ba53-4ed8-8ca0-05b1357cdafd",
    "name": "Default Origin (RR3)",
    "origin_type": "load_balancer",
    "method": "round_robin",
    "addresses": [
      { "address": "example.com", "weight": 3, "server_role": "primary", "is_active": true },
      { "address": "example.net", "weight": 2, "server_role": "primary", "is_active": true },
      { "address": "example.org", "weight": 1, "server_role": "backup", "is_active": true }
    ]
  }
}
```

For every field of the origin, refer to [Origins](/en/documentation/platform/connectors/origins/).

---

## Confirm that the Application answers

The change takes a few minutes to propagate. Until then, the Application answers as it did before.

To confirm it, send a request to a hostname that reaches the Application, with that hostname in place of `<your-domain>`:

```bash
curl -i https://<your-domain>/
```

The response starts with the status line that one of the primary addresses returns, such as `HTTP/2 200`, followed by the response headers of that origin server. A header that each origin server sets to its own value, such as `server`, shows which address answered. If the response does not come from your origin servers yet, send the request again until it does.

---

## Next steps

- [Load Balancer](/en/documentation/platform/connectors/load-balancer.md): The balancing methods, and how weight, server role, and the active state distribute requests.
- [Origins](/en/documentation/platform/connectors/origins.md#load-balancer): Every field of an origin, and the settings of the Load Balancer type.
