# Snapshots

Unikraft Cloud supports the ability to deploy **stateful** apps.
These apps can keep state across different [scale-to-zero](/features/scale-to-zero) incarnations.
This mechanism also reduces app init time.
Heavy-weight apps take a while to get started when cold started (for example, Spring Boot, Ruby on Rails, etc.).
You can reduce this initialization time by taking a snapshot of the app memory and restoring it when the app starts again.

## Setting it up

The quickest way to set this up is via the legacy CLI `--scale-to-zero-stateful` flag:

<CodeTabs>

```bash title="kraft"
kraft cloud deploy --metro fra --scale-to-zero-stateful .
```

</CodeTabs>

As an alternative, you can add a `label` to your example's `Kraftfile` as follows:

```yaml title=""
labels:
  cloud.unikraft.v1.instances/scale_to_zero.stateful: "true"
```

You can see an example of such a `Kraftfile` and label in the [Spring Boot example](/guides/springboot).

Once deployed, you can check whether this mechanism works for your app via the CLI:

<CodeTabs syncKey="cli-tool">

```bash title="unikraft"
unikraft instances get <instance-name>
```

```bash title="kraft"
kraft cloud instance get <instance-name>
```

</CodeTabs>

```ansi
stateful: [92menabled[0m
```


## How it works

When you enable stateful mode and first deploy your app, Unikraft Cloud brings it up normally and lets it fully initialize.
This may be fast or take seconds or minutes, depending on your app's init time.
Unikraft Cloud waits until the app's exposed port becomes available, and then starts the scale-to-zero process.
This assumes no traffic is coming to that port.
At this point, Unikraft Cloud saves the state of your app and sets the app to standby (consuming no resources).

Next, when traffic arrives, Unikraft Cloud brings up the app including its saved state.
This ensures statefulness across scale-to-zero and scale-to-one cycles.
It also eliminates long initialization times from heavyweight apps.


## Learn more

* The [CLI reference](/docs/cli/unikraft) and the [legacy CLI reference](/docs/cli/kraft/overview).
* Unikraft Cloud's [REST API reference](/api/platform/v1), and in particular the [scale-to-zero schema](/api/platform/v1/~schemas#instance-scale-to-zero).
