# Minimize downtime for an application

Downtime comes from two places: the switch that brings traffic to Azion, and an origin that stops answering later. You avoid the first by finishing the setup before the DNS change. You limit the second with a backup origin, an expired copy from cache, and your own error page.

---

## Prerequisites

- A workload, an application, and a connector on Azion. To set them up, refer to [Migrate an application to Azion](/en/documentation/fundamentals/migrate-to-azion/).
- Access to the DNS records of the domain at your DNS provider.

---

## Go live without a gap

Users notice only the DNS change, so everything else comes first:

1. **Bind a certificate to the workload**

   In the workload's **Digital Certificate** field, select a certificate that covers the custom domain. Without it, HTTPS fails as soon as the domain resolves to Azion.

2. **Enter the custom domain on the workload**

   In **Subdomain** and **Domain**, enter the host name users type.

3. **Test through the hosts file**

   Load the application from your own computer before any user does. For the steps, refer to [Test an application through the hosts file](/en/documentation/guides/application-development/getting-started/stage-applications-through-hosts-file/).

4. **Point the domain last**

   At your DNS provider, point the CNAME record at the workload domain. For the steps, refer to [Point a domain to a workload](/en/documentation/guides/platform/migration/point-domain-to-azion/).

Users reach the application on Azion as their resolvers pick up the change. Until then, the previous provider keeps answering them, so keep it running through the propagation.

---

## Keep answering when an origin fails

[Load Balancer](/en/documentation/platform/connectors/#load-balancer), a feature of the connector, spreads requests across several origin addresses. It skips an address that returns a 4xx or 5xx error or exceeds the connector's timeouts. To add a backup origin:

1. **Open the connector**

   Access [Azion Console](https://console.azion.com/) > **Connectors** > **your connector**.

2. **Add the backup address**

   In **Addresses**, add the address of the backup origin.

3. **Set its role**

   Set its **Server Role** to *Backup*, so it receives requests only when every *Primary* address fails.

4. **Choose the balancing method**

   In **Balancing Method**, select *Round-Robin* or *Least Connections*. **Server Role** applies to these two methods.

5. **Select Save**

When the primary origin fails, requests go to the backup origin instead of returning an error. A connector holds up to 10 addresses with Load Balancer active.

> **Note**
>
> To take an origin out for maintenance, turn off the **Active** switch of its address. At least one address must stay active.

---

## Answer from cache while the origin recovers

A cache setting with **Stale cache** on lets Azion serve an expired copy when the origin fails, instead of an error. The Console turns it on when you create a setting; the API and the CLI leave it off. To check it:

1. **Open the cache settings**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application** > **Cache Settings** tab.

2. **Open the cache setting the application uses, or select + Cache to create one**

3. **Turn on Stale cache**

4. **Select Save**

While the origin is down, requests for content Azion has already cached are answered with the last copy.

---

## Show your own page instead of an error

When the origin fails for content that is not in cache, a custom page set replaces the 5xx response with a page you host. Serve that page from a connector that stays up when the origin fails, such as an [Object Storage](/en/documentation/platform/object-storage/) bucket. To create the set:

1. **Open Custom Pages**

   Access [Azion Console](https://console.azion.com/) > **Custom Pages**.

2. **Select + Custom Page**

3. **Add the page code**

   Select **+ Custom Page Code** and, in **Page Code**, select *503*.

4. **Point it at your page**

   Select the **Connector** that serves the page and, in **Page Path**, enter its path. For example: `/errors/503.html`.

5. **Set how long Azion keeps it**

   In **Response TTL**, enter the seconds the page stays in cache.

6. **Select Save**

7. **Bind the set to the workload**

   Access **Workloads** > **your workload**. In **Deployment Settings**, select the custom page set, then select **Save**.

A 503 from the origin now returns your page. The status code stays 503 unless you set **Response Custom Status Code**.

---

## Next steps

- [Cache](/en/documentation/platform/applications.md#cache): Follow the TTL, stale cache, and the second layer through a request.
- [Load Balancer](/en/documentation/platform/connectors.md#load-balancer): Balancing methods, weights, and the limits of a connector's addresses.
- [Custom Pages](/en/documentation/platform/workloads.md#custom-pages): Every page code, the response TTL, and the custom status code.
- [Maintenance mode](/en/documentation/fundamentals/maintenance-mode.md): Show a maintenance page on purpose while you change the application.
