# Scale an app

> Fixed replicas, autoscaling on CPU, memory, requests or latency, and scale-to-zero

URL: https://pier.run/docs/guides/scale-an-app

**Goal.** `api` runs two instances, then autoscales between one and three instances on CPU.

### Fixed replicas

```bash
pier set app api --replicas 2
```

```text title="output"

  Changes:
    ~ update app "api" in prod
      replicas: 1 → 2  (scaling — applied immediately)

→  Updated pier.yaml
→  Waiting for infrastructure provisioning...
OK  Infrastructure ready
OK  Updated app "api" in prod

```

A replica change is applied immediately. The existing container image is reused, so no
build is required and the running instance is not rolled.

```bash
pier ls apps
```

```text title="output"
                                                                                       
 NAME STATUS  REPLICAS AUTOSCALE IMAGE                                    PORT UPDATED 
                                                                                       
 api  running 2/2      -         zot.pier-registry.svc.cluster.local:5... 8080 2m ago  
                                                                                       

```

### Autoscale

```bash
pier set app api --autoscale 1-3 --trigger cpu:70
```

```text title="output"

  Changes:
    ~ update app "api" in prod
      replicas: 2 → 0  (scaling — applied immediately)
      autoscale: off → 1-3 on cpu>70   (policy — applied immediately)

→  Updated pier.yaml
→  Waiting for infrastructure provisioning...
OK  Infrastructure ready
OK  Updated app "api" in prod

```

`--autoscale min-max` replaces the fixed count (the two are exclusive). Triggers, repeatable:
`cpu:70`, `memory:80` (percent of the plan), `rps:50` (requests per second per
instance), `latency:250ms`.

### Back to fixed

```bash
pier set app api --autoscale off --replicas 1
```

```text title="output"

  Changes:
    ~ update app "api" in prod
      replicas: 0 → 1  (scaling — applied immediately)
      autoscale: 1-3 on cpu>70 → off   (policy — applied immediately)

→  Updated pier.yaml
→  Waiting for infrastructure provisioning...
OK  Infrastructure ready
OK  Updated app "api" in prod

```

## What changed

```yaml title="pier.yaml"
        targets:
          - name: primary
            plan: app-s
            autoscale:
              min: 1
              max: 3
              triggers:
                - type: cpu
                  target: 70
```

`pier set app --stage` writes this without applying; `pier apply` applies it later.

## Variations

* **Scale to zero**: `--autoscale 0-3 --idle-after 10m` stops the last instance after ten
  minutes without traffic; the next request starts one.
* **A larger instance** instead of more instances: `--plan app-m` ([Plans](/docs/plans)).
  A plan change rolls the target.
* **Per target**: `pier set app api/canary --replicas 1` scales one target.

## See also

[Apps](/docs/resources/apps) · [`pier set`](/docs/cli/reference/set) ·
[`pier monitor`](/docs/cli/reference/monitor)
