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

# Load Balancer: One Custom Domain, Multiple Applications

> Serve one custom domain from several Square Cloud applications, with round-robin at the edge, automatic failover and no per-request billing. On Standard and up.

A load balancer on Square Cloud is **the same custom domain on more than one application**. The Square Cloud edge splits the requests for that domain across the applications and stops sending them to one that goes offline. There is no separate balancer to create or maintain: setting the same domain on a second application turns it on.

Visitors open one custom domain. The Square Cloud edge hands each request to the next application in round-robin and skips the application that is down.

Each request goes to the next application. One that is down is skipped.

## Why use it

> [card] Round-robin at the edge
>
> **Each request goes to the next application** in the group, so the load is split evenly, with no proxy or extra layer for you to configure.

> [card] Automatic failover
>
> When an application goes offline, its requests are **answered by the other applications** in the group. Once it responds again, it is back in rotation by itself.

> [card] Updates without an outage
>
> **Restart or deploy one application at a time**: while one comes back, the others keep serving the domain.

> [card] Included in your plan
>
> **No per-request billing** and no add-on to buy. Load balancing comes with custom domains, from the Standard plan.

## How it works

Visitors reach the Square Cloud edge, which splits the requests across the domain's applications and skips the one that is down.

* **Round-robin, no sticky sessions.** Each request can land on a different application. Sessions and caches kept in memory need shared state, such as a [database](https://docs.squarecloud.app/en/services/databases.md) or [Redis](https://docs.squarecloud.app/en/services/databases/redis.md).
* **Failover on refused connections.** When an application is down, the request goes to another one in the group, `POST` included. If the response is the timeout page, only `GET` and `HEAD` are resent; a `POST` returns the error for the client to retry.
* **One hostname, the same site.** Every application in the group answers on the same domain and should serve the same site or service: usually the same application deployed several times.
* **Back in rotation by itself.** Once an application responds again, it starts receiving requests again, with no action on your part.

## Applications per domain

How many applications can serve one domain depends on your [plan](https://docs.squarecloud.app/en/platform/plans.md):

| Plan | Applications per domain |
| :- | :-: |
| Hobby | Custom domains are not included |
| Standard | 2 |
| Pro | 5 |
| Enterprise | 10 |

Adding an application past the limit is refused with `LOAD_BALANCER_LIMIT_REACHED`.

## Create a load balancer

**1. Deploy the site as two or more applications**

Upload the same project once per application, each with its own `SUBDOMAIN` in the [configuration file](https://docs.squarecloud.app/en/getting-started/config-file.md). Only websites join a balancer: an application without a subdomain can't serve a domain.

**2. Set the custom domain on the first application**

Open the application's network settings, set your domain and create the DNS records the dashboard shows at your DNS provider. The TLS certificate is issued and renewed for you. See [how to set up your own domain](https://help.squarecloud.app/en-us/article/how-to-set-up-your-own-domain-cnamedns-1fzbrgh/).

**3. Add the same domain to another application**

Open [Load Balancers](https://squarecloud.app/en/dashboard/loadbalancers) in the dashboard, pick the domain and click **Add application**, or set the same domain in the second application's network settings.

**4. Check the group**

The Load Balancers page shows the domain as **Active balancing**, with each application and its share of the traffic.

> [!NOTE]
>
> An application serves one custom domain at a time. Adding an application that already serves another domain moves it to the new one.

### From the terminal or the API

Set the same domain on each application:

```bash theme={"system"}
squarecloud app network domain www.example.com --app <first application ID>
squarecloud app network domain www.example.com --app <second application ID>
```

Then list the groups of your account:

```bash theme={"system"}
squarecloud app load-balancers
```

* **CLI:** [`app network domain`](https://docs.squarecloud.app/en/cli-reference/domains#squarecloud-app-network-domain) and [`app load-balancers`](https://docs.squarecloud.app/en/cli-reference/domains#squarecloud-app-load-balancers).
* **API:** [Set custom domain](https://docs.squarecloud.app/en/api-reference/endpoint/apps/network/custom.md) and [List load balancers](https://docs.squarecloud.app/en/api-reference/endpoint/apps/network/load-balancers.md).
* **SDKs:** [JavaScript](https://docs.squarecloud.app/en/sdks/js/network.md), [Python](https://docs.squarecloud.app/en/sdks/py/network.md) and [Go](https://docs.squarecloud.app/en/sdks/go/network.md).

## Prepare your application

Requests for the same visitor can land on different applications, so each one must answer the same way:

* **Keep state outside the process.** Store sessions, carts and caches in a [database](https://docs.squarecloud.app/en/services/databases.md) or [Redis](https://docs.squarecloud.app/en/services/databases/redis.md), not in memory.
* **Keep files outside the application.** Each application has its own disk: send uploads to [Blob Storage](https://docs.squarecloud.app/en/services/blob.md), so every application serves the same files.
* **Same code, same configuration.** Deploy the same version to every application and give them the same [environment variables](https://docs.squarecloud.app/en/platform/environment-variables.md).
* **Scheduled jobs run once per application.** A job that must run a single time (a daily e-mail, a cleanup) needs a lock in the database, or belongs in only one application.

## Update without an outage

Restart or deploy **one application at a time**. While it restarts, the edge sends its requests to the others; once it responds again, it is back in rotation. Updating every application at the same moment leaves the domain with nobody to answer.

## Remove an application or the domain

* **Remove one application:** on the Load Balancers page, choose **Remove from balancer**, or remove the domain in that application's network settings. The other applications keep serving the domain.
* **Remove the domain:** removing it from the last application releases the domain completely.

From the terminal, `squarecloud app network domain @ --app <application ID>` removes the custom domain of one application.

## Frequently asked questions

> [accordion] What is load balancing on Square Cloud?
>
> It is one custom domain served by more than one of your applications. The Square Cloud edge sends the requests for that domain to those applications in round-robin and stops sending them to an application that goes offline.

> [accordion] Which plans include load balancing?
>
> Every plan with custom domains: Standard balances up to 2 applications per domain, Pro up to 5 and Enterprise up to 10. The Hobby plan does not include custom domains.

> [accordion] Is there a charge per request?
>
> No. Load balancing is included in your plan, with no per-request billing and no requests-per-second ceiling set by the balancer.

> [accordion] Are sessions sticky?
>
> No. Each request can land on a different application. Applications that keep state in memory (local sessions, a local cache) need shared state, such as a database or Redis.

> [accordion] What happens when an application goes down?
>
> If the application is offline (connection refused), any request, `POST` included, is answered by another application in the group. If the response is the timeout page instead, only requests without a body (`GET`, `HEAD`) are resent; a `POST` receives an error and must be retried by the client.

> [accordion] Does it scale by itself?
>
> No. There is no autoscaling: you decide how many applications serve the domain, and add or remove one at any time.

> [accordion] Can it balance the included squareweb.app subdomain?
>
> No. Each application keeps its own `squareweb.app` subdomain. Balancing applies to a custom domain shared by the applications.

> [accordion] Which applications can share a domain?
>
> Any website applications of the same account. They should serve the same site or service, since every one of them answers on the same hostname.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.