# Load balancer on or off

Source: https://openpanel.sh/docs/load-balancing

One replica behind a public service's addresses, or several replicas balanced by OpenPanel's edge.

Every public service is reached through OpenPanel's edge. The **load balancer** setting decides how many replicas stand behind it.

In the console, the setting is the **Load balancer and replicas** card on a service's **Settings** tab, and the same section in **New service**. The [CLI](/docs/cli), the [API](/docs/api) and [MCP](/docs/ai) do the same.

| Load balancer | What runs |
|---|---|
| **Off** (the default) | One replica. Every request and connection goes to it. |
| **On** | 1 to 100 replicas, on one server or several. The edge spreads the traffic over the ones that are ready. |

## How the edge spreads traffic [#how-the-edge-spreads-traffic]

The edge sends each HTTP request to the ready replica with the fewest requests in flight, on whichever server it runs. A [TCP port](/docs/tcp-udp) is balanced the same way per connection, and a UDP port per client address. A replica is ready when its container runs and passes its [health check](/docs/projects/health-checks); one that fails it gets no traffic until it passes again.

Two requests from one visitor can reach two different replicas. Keep sessions and uploads somewhere every replica can read, such as a database, not in a replica's memory or disk.

## Turn it on [#turn-it-on]

<Tabs items={["Console","CLI","API"]}>
<Tab value="Console">
Open the project, click the service on the canvas, and go to its **Settings** tab. In **Load balancer and replicas**, turn **Load balancer** on, set **Replicas**, and click **Save**. Then deploy the service from its **Overview** tab.
</Tab>

<Tab value="CLI">
```sh
openpanel services update web --project shop --balancer --replicas 3
openpanel deploy web --project shop
```
</Tab>

<Tab value="API">
```sh
curl -X PATCH https://openpanel.sh/api/v1/services/$SERVICE_ID \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"balancer": true, "replicas": 3}'
```

Then deploy, as for any setting.
</Tab>
</Tabs>

## Turn it off [#turn-it-off]

A public service without the load balancer runs one replica, so set both at once:

```sh
openpanel services update web --project shop --no-balancer --replicas 1
```

In the API, send `{"balancer": false, "replicas": 1}`.

## Which services can use it [#which-services-can-use-it]

| Service | Load balancer |
|---|---|
| Public | Yes |
| Private | No: a private service runs one replica |
| With no address | No: it can run several replicas without it, reached only by the project's other services on the same server |
| With a volume | No: it always runs one replica; see [The single-instance rule](/docs/volumes/single-instance) |

The messages for each case are listed in [Service settings](/docs/projects/settings#the-rules-with-their-messages).

<Cards>
<Card href="/docs/load-balancing/replicas" title="Replicas" description="Where replicas run and how a deploy replaces them." />

<Card href="/docs/projects/health-checks" title="Health checks" description="What makes a replica ready." />
</Cards>