# Scale an app

Change how many machines run an app, where they run, and their size.

Every machine runs the same container. One machine in one location is reached directly: the app's
names point at the machine, which gets its own certificates. More machines, or more than one
location, put the app behind a load balancer of its own: the app's names point at the balancer,
which ends TLS with a certificate the platform issues and renews, and spreads requests over the
machines. Replace app-id with the app's id.

**Important:**
Every machine is a compute instance, billed as one. Adding machines adds to what you pay.

## Prerequisites

- Permission for `deploy:UpdateApp` on the app.
- In the console, also `deploy:DescribeApp` to open the app's page (without it the page is not
  found).

## Change the scale

**Console**
1. Open the app's **Runtime** tab.
2. Under **Scaling**, for **Machines**, enter a number from 1 to 10.
3. Under **Locations**, select the locations the machines are spread over, in the order you want
   them used. None selected means the region's default location.
4. Choose **Save**. The panel says **Saved. Deploy to apply**, and whether the app is **Behind a
   load balancer** or **Reached directly**.
5. Choose **Deploy** at the top of the page.

The machine size is changed with the CLI, the API or Terraform.

**CLI**
```sh
dcloud deploy apps update app-id --replicas 3 \
  --locations fsn1 --locations nbg1 --instance-type performance-4
```

**API**
```http
PATCH /deploy/api/apps/3f1c2b4a-5d6e-4f70-8a91-b2c3d4e5f601
{ "replicas": 3, "locations": ["fsn1", "nbg1"], "instanceType": "performance-4" }
```

**Terraform**
```hcl
resource "dcloud_app" "web" {
  name          = "my-app"
  builder       = "image"
  image_ref     = "org-example1234.ecr.example.com/orders:1.4.2"
  replicas      = 3
  locations     = ["fsn1", "nbg1"]
  instance_type = "performance-4"
}
```

Locations are `fsn1` (Falkenstein) and `nbg1` (Nuremberg), at most three, each listed once; or
`hel1` (Helsinki, Finland) alone, only when the organization allows EU locations outside Germany
(**Settings → Data location**). Locations of different regions are never mixed; anything else is
refused with `400`, for example "All locations of an app must be in one region: Germany (fsn1,
nbg1) or Finland (hel1), not both". More than 10 machines is refused with `400` too. An app that is
being deleted answers `409` "The app is being deleted".

## Result

From the next deployment the app runs on the given number of machines, spread over the locations in
the order given. Scaling down removes the newest machines once the rest serve the new version. The
machines appear under **Compute** as well. A wildcard domain behind a load
balancer is covered only when its zone is in Deutsche Cloud DNS.

## Related

- [Apps and sources](apps-and-sources.md)
- [Inspect an app](inspect-an-app.md)
- `deploy.apps.update` · `dcloud deploy apps update` · `dcloud_app`
