Skip to main content
Version: 1.20.x

Lifecycle Policies

Lifecycle policies are background tasks that automatically delete or compress old records from your buckets. You can configure policies to run at specific intervals and target records based on age, entry names, or custom conditions. This helps use your storage efficiently while keeping relevant data accessible.

How It Works​

A lifecycle policy runs at a configurable interval and scans the target bucket for records older than older_than. It applies the configured action to matching records and logs run diagnostics in the $system/lifecycle system entry. Delete policies remove matching records, while compress policies compress old persisted blocks with zstd. Compressed blocks remain transparently readable and are decompressed first if new writes target them. You can optionally scope policies to specific entries or filter records using conditions.

Policies are stored on disk and remain active after restarts. However, read-only (replica) instances cannot execute lifecycle policies. Every policy run is recorded in the $system/lifecycle system entry for transparency and debugging.

Supported Actions​

ReductStore supports these action types for lifecycle policies:

TypeDescription
deleteRemoves records older than older_than from the bucket
compressCompresses persisted blocks containing records older than older_than with zstd

Compress policies do not delete records. A common retention pattern is to compress old data first, then delete very old data later with a separate delete policy.

info

Compression is applied per storage block for efficiency, not per individual record. Because of this block-level behavior, the when condition is not supported for compress policies.

Policy Settings​

You can configure lifecycle policies using the following settings:

SettingDescriptionRequiredDefault
typeAction type (e.g., delete or compress)Yes-
bucketTarget bucket nameYes-
entriesList of entries to scope the policy (wildcard * supported)No-
older_thanMaximum age of records before action is applied (e.g., 30d, 1h, 5m)Yes-
intervalPolicy execution interval (e.g., 3600s, 10m)No3600s
whenJSON condition to filter records (see Conditional Query Reference)No-
modePolicy mode: enabled (default), dry_run, or disabledNoenabled

Conditional Policies​

You can refine lifecycle policies using the entries and when parameters:

  • entries: Limit the policy to specific entries (e.g., sensor-1,sensor-2 or sensor-*)
  • when: Apply a delete policy only to records matching a condition (e.g., {"&sensor_type": {"$eq": "temperature"}}). This condition is not supported for compress policies.

For more details, see the Conditional Query Reference.

Example​

Imagine you store telemetry data from temperature sensors in a bucket called telemetry. You want to automatically delete records older than 30 days, but only for specific sensors (sensor-1 and sensor-2) and only if the sensor_type label equals temperature. Here’s how you’d configure the policy:

version: "3"
services:
reductstore:
image: reduct/store:latest
ports:
- "8383:8383"
volumes:
- ./data:/data
environment:
RS_API_TOKEN: my-api-token
RS_BUCKET_1_NAME: telemetry
RS_LIFECYCLE_1_NAME: purge-sensors-30d
RS_LIFECYCLE_1_BUCKET: telemetry
RS_LIFECYCLE_1_TYPE: delete
RS_LIFECYCLE_1_OLDER_THAN: 30d
RS_LIFECYCLE_1_INTERVAL: 10m
RS_LIFECYCLE_1_ENTRIES: "sensor-1,sensor-2"

RS_LIFECYCLE_1_WHEN: |
{
"&sensor_type": { "$eq": "temperature" }
}

Managing Lifecycle Policies​

Here you will find examples of how to create, list, retrieve, update modes, and delete lifecycle policies using the ReductStore SDKs, REST API, CLI and Web Console.

All examples are written for a local ReductStore instance available at http://127.0.0.1:8383 with API token my-token.

For more information on setting up a local ReductStore instance, see the Getting Started guide.

Creating a Lifecycle Policy​

To create a lifecycle policy, you must provide at least the action type, target bucket, and older_than. The examples below also include optional filters (entries and when) and a custom interval.

reduct-cli alias add local -L http://localhost:8383 -t "my-token"
reduct-cli bucket create local/my-bucket
reduct-cli lifecycle create local/my-lifecycle my-bucket --type delete --older-than 30d --interval 1h --entries cli-example --when '{"&anomaly":{"$eq":1}}'

Browsing Lifecycle Policies​

You can list all lifecycle policies and inspect full settings/details of a specific policy. Lifecycle list responses include the action type and the last run timestamp when available.

reduct-cli alias add local -L http://localhost:8383 -t "my-token"
reduct-cli lifecycle ls local --full
reduct-cli lifecycle show local/my-lifecycle

Lifecycle Modes​

Lifecycle policies can be switched between modes without recreating the policy.

reduct-cli alias add local -L http://localhost:8383 -t "my-token"
reduct-cli lifecycle dry-run local/my-lifecycle
reduct-cli lifecycle disable local/my-lifecycle
reduct-cli lifecycle enable local/my-lifecycle

Removing a Lifecycle Policy​

You can remove a lifecycle policy when it is no longer needed.

info

Provisioned lifecycle policies cannot be modified or deleted through the API. To change or remove them, update environment variables and restart ReductStore.

reduct-cli alias add local -L http://localhost:8383 -t "my-token"
reduct-cli lifecycle rm local/lifecycle-to-remove --yes

Run Diagnostics​

Every lifecycle run writes a diagnostic record to the $system bucket under the lifecycle/<instance>/<policy-name> entry. For example, diagnostics for a policy named purge-sensors-30d on instance node-1 are stored in $system/lifecycle/node-1/purge-sensors-30d.

Lifecycle diagnostics are written as lifecycle_run system events. The stored JSON record contains these fields:

FieldDescription
timestampEvent timestamp in Unix microseconds.
instanceReductStore instance name that emitted the diagnostic record.
statusHTTP-style status code for the lifecycle run result.
messageError message for the lifecycle run, or an empty string on success.
policy_nameLifecycle policy name.
action_typeLifecycle action type, such as delete or compress.
bucketTarget bucket name.
durationLifecycle run duration in seconds.
processed_recordsNumber of records processed by the lifecycle action, or null on failure.
error_codeError status code. Present only when the lifecycle run fails.
error_messageError details. Present only when the lifecycle run fails.

The record also has a status label with the same value as the status field, so you can filter diagnostics by result code.