> Index of every page on this site: [llms.txt](https://docs.a-line.cloud/llms.txt)

# Scale an app automatically

> Add and remove replicas of an app as its load changes, down to zero when it is idle.

**Goal**: an app that runs more replicas when it is busy and fewer when it
is quiet, so you pay for what it uses.

## Before you start

- A deployed app that can run as several replicas: it keeps no state in
  memory or on its own disk that other replicas need.
- Enough room on the cluster for the extra replicas, or a pool that grows
  with them (see [Dedicated clusters](/guides/dedicated-clusters)).

## Steps

<Steps>
<Step>

Open the app on the project canvas and go to its **Settings** tab.

</Step>
<Step>

In the **Autoscaling** section, set **Min Replicas** and **Max Replicas**
(at most 100).

</Step>
<Step>

Select **Add** and pick a trigger:
- **CPU Utilization**: scale out above a CPU percentage (70 by default).
- **Memory Utilization**: scale out above a memory percentage (80 by
  default).
- **Cron Schedule**: run more replicas during set hours, such as office
  hours.
- **NATS JetStream Lag**: scale workers by the number of waiting messages.

</Step>
<Step>

Optional: set the **Cooldown (s)**, how long to wait before scaling in
again (300 seconds by default).

</Step>
<Step>

Optional: turn on **Scale to zero when idle**. This sets **Min
Replicas** to 0. The first request after an idle period waits while the
app starts.

</Step>
<Step>

Apply the changes and deploy the app.

</Step>
</Steps>

Without a trigger, the app does not scale: the section shows **No triggers
configured**.

## Verify

Put load on the app. Its number of replicas rises, up to **Max Replicas**,
and falls back to **Min Replicas** after the cooldown once the load is gone.
Follow CPU and memory in the **Metrics** on the **Overview** tab.

## Troubleshooting

- **The app never scales out**: check that a trigger is configured and that
  its threshold is reached.
- **New replicas stay pending**: the cluster has no room. Add servers, or
  let the pool grow with [pool autoscaling](/guides/dedicated-clusters#autoscaling).
- **Replicas go up and down all the time**: raise the **Cooldown (s)**.

## In IaC

The `autoscaling` block takes `min`, `max`, `triggers`, `scale_to_zero` and
`cooldown_seconds`. See the example under [Scaling](/iac/apps#scaling).

## Next steps

- [Read logs and metrics](/guides/logs-and-metrics)
- [Dedicated clusters](/guides/dedicated-clusters): pools that add servers
  when apps need them.
