Skip to main content

Snapshots & Backups

Snapshotting

Restate workers can be configured to periodically publish snapshots of their partition state to a shared destination. Snapshots act as a form of backup and allow nodes that had not previously served a partition to bootstrap a copy of its state. Without snapshots, rebuilding a partition processor would require the full replay of the partition's log. Replaying the log might take a long time or even be impossible if the log was trimmed.

Architectural overview

To understand the terminology used on this page, it might be helpful to read through the architecture reference.

Configuring Snapshots

Restate clusters should always be configured with a snapshot repository to allow nodes to efficiently share partition state. Restate currently supports using Amazon S3 (or another API-compatible object store) as a shared snapshot repository. To set up a snapshot destination, update your server configuration as follows:

[worker.snapshots]
destination = "s3://snapshots-bucket/cluster-prefix"
snapshot-interval-num-records = 10000

This enables automated periodic snapshots to be written to the specified bucket. You can also trigger snapshot creation manually using the restatectl:

restatectl snapshots create-snapshot --partition-id <PARTITION_ID>

We recommend testing the snapshot configuration by requesting a snapshot and examining the contents of the bucket. You should see a new prefix with each partition's id, and a latest.json file pointing to the most recent snapshot.

No additional configuration is required to enable restoring snapshots. When partition processors first start up, and no local partition state is found, the processor will attempt to restore the latest snapshot from the repository. This allows for efficient bootstrapping of additional partition workers.

Experimenting with snapshots without an object store

For testing purposes, you can also use the file:// protocol to publish snapshots to a local directory. This is mostly useful when experimenting with multi-node configurations on a single machine. The file provider does not support conditional updates, which makes it unsuitable for potentially contended operation.

For S3 bucket destinations, Restate will use the AWS credentials available from the environment, or the configuration profile specified by AWS_PROFILE environment variable, falling back to the default AWS profile.

Log trimming and Snapshots

In a distributed environment, the shared log is the mechanism for replicating partition state among nodes. Therefore it is critical to that all cluster members can get all the relevant events recorded in the log, even newly built nodes that will join the cluster in the future. This requirement is at odds with an immutable log growing unboundedly. Snapshots enable log trimming - the proces of removing older segments of the log.

When partition processors successfully publish a snapshot, they update their "archived" log sequence number (LSN). This reflects the position in the log at which the snapshot was taken and allows the cluster to safely trim its logs.

By default, Restate will attempt to trim logs once an hour which you can override or disable in the server configuration:

[admin]
log-trim-check-interval = "1h"

This interval determines only how frequently the check is performed, and not a guarantee that logs will be trimmed. Restate will automatically determine the appropriate safe trim point for each partition's log.

If replicated logs are in use in a clustered environment, the log safe trim point will be determined based on the archived LSN. If a snapshot repository is not configured, then archived LSNs are not reported. Instead, the safe trim point will be determined by the smallest reported persisted LSN across all known processors for the given partition. Single-node local-only logs are also trimmed based on the partitions' persisted LSNs.

The presence of any dead nodes in a cluster will cause trimming to be suspended for all partitions, unless a snapshot repository is configured. This is because we can not know what partitions may reside on the unreachable nodes, which will become stuck when the node comes back.

When a node starts up with pre-existing partition state and finds that the partition's log has been trimmed to a point beyond the most recent locally-applied LSN, the node will attempt to download the latest snapshot from the configured repository. If a suitable snapshot is available, the processor will re-bootstrap its local state and resume applying the log.

Handling log trim gap errors

If you observe repeated Shutting partition processor down because it encountered a trim gap in the log. errors in the Restate server log, it is an indication that a processor is failing to start up due to missing log records. To recover, you must ensure that a snapshot repository is correctly configured and accessible from the node reporting errors. You can still recover even if no snapshots were taken previously as long as there is at least one healthy node with a copy of the partition data. In that case, you must first configure the existing node(s) to publish snapshots for the affected partition(s) to a shared destination.

Pruning the snapshot repository

Pruning

Restate does not currently support pruning older snapshots from the snapshot repository. We recommend implementing an object lifecycle policy directly in the object store to manage retention.

Data Backups

note

This page covers backing up individual Restate server instances. For sharing snapshots in a Restate cluster environment, see Logs and Snapshots.

The Restate server persists both metadata (such as the details of deployed services, in-flight invocations) and data (e.g., virtual object and workflow state keys) in its data store, which is located in its base directory (by default, the restate-data path relative to the startup working directory). Restate is configured to perform write-ahead logging with fsync enabled to ensure that effects are fully persisted before being acknowledged to participating services.

Backing up the full contents of the Restate base directory will ensure that you can recover this state in the event of a server failure. We recommend placing the data directory on fast block storage that supports atomic snapshots, such as Amazon EBS volume snapshots. Alternatively, you can stop the restate-server process, archive the base directory contents, and then restart the process. This ensures that the backup contains an atomic view of the persisted state.

In addition to the data store, you should also make sure you have a back up of the effective Restate server configuration. Be aware that this may be spread across command line arguments, environment variables, and the server configuration file.

Restoring Backups

Prevent multiple instances of the same node

Restate cannot guarantee that it is the only instance of the given node. You must ensure that only one instance of any given Restate node is running when restoring the data store from a backup. Running multiple instances could lead to a "split-brain" scenario where different servers process invocations for the same set of services, causing state divergence.

To restore from backup, ensure the following:

  • Use a Restate server release that is compatible with the version that produced the data store snapshot. See the Upgrading section.
  • Use an equivalent Restate server configuration. In particular, ensure that the cluster-name and node-name attributes match those of the previous Restate server operating on this data store.
  • Exclusive access to a data store restored from the most recent atomic snapshot of the previous Restate installation.