--- title: Sleep and wake description: Apps nobody is using go to sleep and wake up when a visitor arrives. --- # Sleep and wake An app that gets no visitors for a while goes to sleep. It stops using a machine, and that is what makes free hosting possible. When the next visitor arrives, Kaviris wakes it up and hands over the request. ## What visitors notice Usually only a short wait on the first request: about **4 seconds** while the app starts. The request is held, not dropped, so the visitor simply gets the page a bit later. If a wake takes longer than 12 seconds (a big app with a slow start), the visitor sees a short "starting your app" page that reloads by itself. Every request after that is served at normal speed until the app is idle again. ## When does an app sleep? After 15 minutes without requests. The final number for the free beta is still to be announced (see [beta limits](../beta-limits.md)). An app falls asleep within about a minute and a half after that. Keeping an app always on is planned for some plans; it is not available yet. ## What keeps running - **Your database.** Postgres keeps running while the app sleeps, so nothing is lost. On the free tier, a database whose app has slept for 24 hours is paused too; the first visitor after that waits about 12 seconds and may see the "starting your app" page once. Paid plans keep the database running. - **Backups** run while the app sleeps. A paused database gets one first if its last is over 23 hours old. - **Your address** keeps answering: requests wake the app. What does not run while the app sleeps: anything inside the app itself, such as timers or in-memory queues. If your app needs to do work on a schedule, keep that in mind; background workers are coming later. ## Write apps that wake well - Start fast: don't do heavy work before you start listening on the port. - Migrations don't slow a wake: with a database, Kaviris runs your release step (a `release:` line in your `Procfile`, a `db:migrate` script, or Django's migrate) once per deploy, before the new version starts, never when the app wakes or restarts. If it fails, the deploy stops with [`release_failed`](../refusals/release_failed.md) and the version before keeps serving. - Keep state in the database, not in memory. A sleeping app forgets what was in memory. - Listen on the port in the `PORT` environment variable (`process.env.PORT`, `os.environ["PORT"]`); Kaviris sets it for you.