# Sleep mode

Source : https://webgune.cloud/en-us/docs/mise-en-veille · Mis à jour le 2026-11-20

# Sleep mode

> **Rolling out.** Today, only **staging** and **development** services can go to sleep. Production services stay on.

A service that no longer receives requests is stopped, then restarted on the next request. During sleep, no instance runs and the service uses no CPU or memory.

## Who can go to sleep

A service goes to sleep when all these conditions are met:

- it is a site or API, in the staging or development environment;
- your plan does not keep it on permanently;
- it answers on at least one domain, otherwise nothing could wake it;
- the web application firewall (WAF) is not enabled on this service;
- its domain does not use a certificate you provided yourself.

The last two conditions protect the service: during sleep, requests go through a relay that carries neither the WAF nor a provided certificate. Webgune then keeps the service on rather than remove a protection from it.

Never go to sleep:

- [bots](/docs/bots-discord) and [workers](/docs/workers), which nobody visits and nothing would wake;
- [databases](/docs/bases-de-donnees);
- production services, as long as sleep is not open to them.

## Checking whether a service goes to sleep

On the service's **General** tab, in the **Availability** block. A box shows the delay in effect, for example "Put to sleep after 30 min without a visit". Without this box, the service stays on.

## Delay before sleep

The delay is counted from the last request received. It depends on your plan's memory:

| Plan memory | Sleeps after |
|-------------|--------------|
| up to 256 MB | 15 minutes without a request |
| up to 512 MB | 30 minutes |
| up to 1 GB | 1 hour |
| up to 2 GB | 2 hours |
| up to 4 GB | 4 hours |
| above | 8 hours |

Without an active subscription, the shortest delay applies: 15 minutes. A plan can set its own delay, between 5 minutes and 24 hours, or keep the service on permanently ([Plans and pricing](/docs/plans-tarifs)). The delay cannot be set service by service.

## What happens on wake-up

1. A request arrives on the sleeping service's domain.
2. Webgune holds the request and starts the service.
3. As soon as the service answers on its port, the request is forwarded to it.
4. Later requests are served normally.

```flow
title: Waking up a service
Request | reaches the domain
Held | Webgune starts the service
*Port open | the request is passed on
Next | later requests are served normally
```

The visitor gets no error: the first page simply takes longer. In our tests, wake-up took about 5 seconds, plus your application's startup time. During this wake-up, the service may be limited in the number of requests.

Staging and development environments are private ([Network and isolation](/docs/reseau-cloisonnement)). A request without the project token is stopped before the service: it does not wake it.

## What is lost during sleep

The service is stopped, not paused. On wake-up, it starts again from its image.

| Item | After a sleep |
|------|---------------|
| Application memory (sessions, caches) | lost |
| Working disk (`/tmp`, files written outside a volume) | wiped |
| [Persistent volume](/docs/volumes-persistants) | kept |
| Database, Redis | kept, they do not sleep |
| Scheduled tasks inside the service | not run during sleep |

## Traffic type

In the same box, **Traffic type** offers three values:

| Value | Meaning |
|-------|---------|
| **Automatic** | the type is detected at each deployment, and shown next to the label |
| **Website** | the service sends pages to browsers |
| **API** | the service answers programs |

This setting is used to recognize real visitors at wake-up. With automatic detection, Webgune queries the service's root `/`: an HTML response or a redirect classifies it as a website, any other response as an API. With no response, the previous value is kept, and failing that the service is treated as an API, which any request wakes.

Correct the value by hand in two cases: an API whose root shows a home page, or an application that serves both a site and an API. For a mixed application, choose **API**: an API client cannot answer a check meant for browsers.

## Sleep and high availability

A service in ultra high availability can go to sleep if your plan allows it. During sleep no instance runs. On wake-up, its instances are spread across different servers again ([Availability and scaling](/docs/autoscaling)). While a service can go to sleep, its number of instances goes from 0 to its base number, with no automatic scale-up beyond that.

## Preparing the application

- Fast startup: each second of initialization adds to the wait for the first request. Move what you can until after the port opens.
- Nothing important in memory or on the working disk. What must last goes in a database, in [Redis](/docs/db-redis) or on a volume.
- No scheduled tasks in a service that can sleep. Put them in a [worker](/docs/workers).
- Clients that tolerate a slow first response: set the timeout of a call to this service to 30 seconds or more.
- A [health check](/docs/controle-de-sante) that answers as soon as the application is ready, without heavy work.

Example of a call that gives the service time to wake up:

```js
const res = await fetch("https://api-demo.preprod.webgune.dev/health", {
  headers: { Cookie: `kx_preview=${process.env.PREVIEW_TOKEN}` },
  signal: AbortSignal.timeout(30_000),
});
```

## Keeping a service from sleeping

- Switch to a plan that keeps the service on.
- Put the service in production: sleep is not open there today.

A monitoring tool that queries the service at an interval shorter than the delay, with the project token, also keeps it from sleeping. This is not a setting: if the probe stops, the service goes to sleep.

## Common mistakes

| Symptom | Cause | Fix |
|---------|-------|-----|
| The first page takes several seconds | the service is waking up | speed up startup, or change plan |
| Users are logged out after a pause | sessions kept in memory | put them in Redis or in a database |
| A scheduled task did not run | the service was asleep | move it to a worker |
| The service never goes to sleep | WAF enabled, provided certificate, monitoring probe, or a plan that keeps it on | check the box in the **Availability** block |
| Files disappeared | they were on the working disk | use a volume |

## Planned changes

| Topic | Today | Planned |
|-------|-------|---------|
| Services concerned | staging and development | public sites, after the anti-bot page goes live |
| Visitor recognition | any allowed request wakes the service | a browser check for sites, so bots do not wake the service |
| Wake-up time | a few seconds | near-instant wake-up |
