# Scaling

How many copies of your app run, how big each one is, when more start on their own, and when the app sleeps while nobody uses it.

## Instances and sizes

An app runs as one or more instances, each in its own sandbox. More instances share the traffic and keep the app up while one restarts. Every instance has the same size: `small`, `medium`, or `large` ([sizes](limits.md#instance-sizes)). The number you set is the total, not an addition. `0` stops the app without deleting it.

An app with a [disk](disks.md) runs one instance: scaling it above one, or turning on autoscaling, is refused.

## Autoscaling

Set a maximum above the number of instances and Deplane adds and removes instances for you, between the two. `instances` is the minimum and `--max` is the maximum.

- Deplane aims for each instance to use about 70% of its size's CPU. Above that, it adds instances; below it, it removes them.
- It scales up within a minute of the load rising, by at most 2 instances a minute.
- It scales down only after 5 calm minutes, by 1 instance a minute.
- For your plan's limits, an autoscaled app counts at its maximum, whether or not it is using that many.

Turn autoscaling off with `--max 0`. The app then stays at its `instances` number.

## Sleep when idle

A sleeping app costs nothing to run. Choose how long the app waits without requests before it sleeps: 5, 15, or 60 minutes, or never (the default).

- Any request to the app's address counts as use, including requests to your custom domains. An app that serves no requests for the whole time goes to sleep. A minute for which the platform could not read the request count never counts as idle.
- A new deploy, a scale change, or a wake counts as activity, and a deploy wakes a sleeping app.
- The first request to a sleeping app wakes it. It waits a few seconds, then is redirected to the same URL, which now reaches the running app. Later requests are not slowed down.
- Workers and cron jobs keep running while the web app sleeps.
- A sleeping app still counts toward your plan's limits.

If the app is not ready in time, the request gets a `503` with `Retry-After: 5`; try again.

## From the CLI

```sh
$ deplane scale 1 --max 5       # one to five instances, depending on load
$ deplane scale --sleep 15m     # sleep after 15 minutes without requests
$ deplane scale --sleep off     # never sleep
$ deplane scale --max 0         # fixed number of instances again
```

`deplane status` shows the autoscale range and, while the app sleeps, `Sleeping since`. See [`deplane scale`](cli.md#deplane-scale).

## From the dashboard

On an app's **Settings** tab, the **Scale** card has **Autoscale up to** (leave it empty for a fixed number) and **Sleep when idle** (Never, or after 5, 15, or 60 minutes). A sleeping app shows **Sleeping**, and counts as healthy on the overview. Setting instances to 0 stops the app and turns autoscaling and sleep off. The [Assistant](assistant.md) and [AI tools](mcp.md) can set the same things.

## Limits

- Instances: 0 or more, up to your plan's instance limit ([Limits](limits.md)). The autoscale maximum is 1 to 1000, also bound by your plan. The AI tools' `scale` tool (MCP) is stricter for `instances`: it takes 0 to 20. Its `max_instances` (autoscale maximum) goes up to 1000, like the API.
- The maximum must be above `instances`. See [invalid_autoscale](errors.md#invalid_autoscale).
- Sleep time is 5, 15, or 60 minutes. See [invalid_sleep](errors.md#invalid_sleep).
