Think of state as a person's memory. Usually, a service has state, which means it has memory of actions and information it's serving. The idea is that our service will run indefinitely, but sometimes we're forced to restart it or even stop it for some time because of maintenance or an upgrade.
Ideally, a service should resume without losing state, giving its users the perception that it never stopped. This is achieved by doing one of two things:
- Having state stored in a persistent storage
- Saving state in a persistent storage before stopping and loading that state after restarting
The first option will make your service a bit slower (nothing is faster than state in system memory) but should give you a more consistent state across restarts. ...