Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/platform/how-to/state-management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# State management

When deploying a service, enabling state management enables the service to maintain its state between restarts by creating a storage area for data and files, ensuring persistence across service restarts.

## Enabling state management

Enable state management during service deployment if your code relies on state or expects files to persist across restarts:

![state management](../images/how-to/state/state-management.png){width=80%}

Enabling state creates a `state` folder that can be accessed by your code.

!!! important

Note that data stored in this area is retained between service restarts and is shared between all replicas of the service, but it is not available globally to other services.

## Storing files in the state folder

You can use this `state` folder as a place to download and store model and other files.

!!! note

While the `state` folder is not visible in the UI, it is still available for use.

For example, the following code downloads a model file to the `state` folder. It subsequently loads the model file from the `state` folder when needed:

``` python
import requests

model = requests.get('https://acme.com/models/model1.dat')
f = open('./state/model1.dat', 'wb')
f.write(model)
f.close()
...
f = open('./state/model1.dat', 'rb')
...
```

The model can be modified at run time, and its state is preserved between service restarts.

!!! note

There is a 100GB storage limit for the state management storage area.

## Using state from Quix Streams

If you have enabled state management for a service, then you can also use the [state management features](https://quix.io/docs/client-library/state-management.html) of Quix Streams in that service. This enables you to store and retrieve data in various formats, and retain that state between service restarts. See the [documentation](https://quix.io/docs/client-library/state-management.html) for further details.

## Running Quix Streams locally

If you are running Quix Streams locally, rather than using it as part of a deployed service in the cloud, then the `state` folder is created automatically for you when you use state management features of the library. For example, if you ran the following code locally:

``` python
from quixstreams import LocalFileStorage

storage = LocalFileStorage()
storage.clear()

storage.set("KEY1", 12.51)
storage.set("KEY2", "str")
storage.set("KEY3", True)
storage.set("KEY4", False)
```

Then you would see the `state` folder and its contents:

```
$ ls state
key1 key2 key3 key4
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ nav:
- 'Add environment variables': 'platform/how-to/environment-variables.md'
- 'Testing using Quix data store': 'platform/how-to/testing-data-store.md'
- 'Configure deployments': 'platform/how-to/yaml-variables.md'
- 'State management': 'platform/how-to/state-management.md'
- 'Tutorials':
- 'platform/tutorials/index.md'
- 'Computer vision':
Expand Down