# Sleep and wake

> Let an idle Ownkube web app, database or cache scale to zero and bill nothing, then wake on the next request. Idle windows, wake chains, and what still bills.

A web app on Ownkube Compute can **sleep** when nobody is using it and wake on the next request. A sleeping app bills no CPU or memory. Databases and caches can sleep too, and an app that wakes brings its linked database and cache up with it.

<img src="/docs/screenshots/settings-scale-to-zero.webp" alt="Screenshot of the Sleep when idle setting with the idle-before-sleep minutes field" />

## Turn it on

1. **Open Settings**

   On the web app's page, open **Settings** and find **Sleep when idle**.

2. **Set the idle window**

   Choose **Idle before sleep** in minutes, 1 to 60. The default is 5. After that long with no requests, the app scales to zero.

3. **Save**

   The change rolls out like any other. The **Overview** tab shows **Asleep** once the app has gone idle.

## Requirements

- The app needs a [public hostname](/docs/networking/public-hostnames). An incoming request is what wakes it.
- A single replica with [autoscaling](/docs/deployments/autoscaling) off. Set the replica count back to one to enable sleep.
- Ownkube Compute only. Own-cloud clusters do not sleep.

## What a wake looks like

The first request after sleep is held while the container starts, then served. Every request after that is served normally until the app goes idle again. This pause is a [cold start](/docs/glossary/cold-start); how long it takes depends on how fast your app boots, so keep startup lean and use a [startup probe](/docs/deployments/health-checks) that reflects it.

Leave sleep off for anything that must answer instantly or receives webhooks that cannot retry.

## Databases and caches

A [Postgres](/docs/data/postgres) database or [Valkey](/docs/data/valkey) cache can sleep on its own idle window from its **Settings** tab. Sleep on a database or cache requires **Public access** on, because the public endpoint is what receives the waking connection. While a database sleeps only its storage bills; a sleeping cache bills nothing.

Linked services wake together. When a sleeping web app receives a request, Ownkube wakes the app and, by name, the database and cache it is linked to, so the app finds them ready. Linking is described on [Variables](/docs/deployments/variables#variables-ownkube-sets-for-you).

## Sleep and the bill

| State | Compute bill | Other charges |
|---|---|---|
| Web app asleep | Nothing | Nothing |
| Database asleep | Nothing | Storage, per GB per month |
| Cache asleep | Nothing | Nothing |

Sleep is the sharpest tool in [cost control](/docs/billing/cost-control) for personal software and staging stacks that sit idle between visits. It is different from pausing: a paused deployment (0 replicas, or a [spend limit](/docs/billing/cost-control#spend-limits) reached) does not wake on its own.

- [Autoscaling](/docs/deployments/autoscaling)
- [Cost control](/docs/billing/cost-control)
- [Cold start](/docs/glossary/cold-start)

---

**Don't see a feature you need?** Email [support@ownkube.io](mailto:support@ownkube.io?subject=Feature%20request). Ownkube is shaped by the teams using it and we ship what our users ask for.

## Search

This site has a search endpoint: https://context7.com/api/v2/ask?siteKey=ask_c64dfe8ffaa8d3ad19576838&query=<URL-encoded question>. It returns documentation that answers the question, with a source link for each part. No API key is needed. If nothing matches, it says so.
