Lifecycle Policies
Lifecycle policies are background tasks that automatically clean up old records from your buckets. They help you manage storage efficiently by removing outdated data based on rules you define.
How It Worksβ
A lifecycle policy runs at a configurable interval and scans the target bucket for records older than max_age. It removes these records and logs the operation in the $audit system bucket. 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 as a lifecycle_run event in the $audit bucket for transparency and debugging.
Supported Actionsβ
Currently, ReductStore supports one action type for lifecycle policies:
| Type | Description |
|---|---|
delete | Removes records older than max_age from the bucket |
More action types may be added in future releases.
Policy Settingsβ
You can configure lifecycle policies using the following settings:
| Setting | Description | Required | Default |
|---|---|---|---|
type | Action type (e.g., delete) | No | delete |
bucket | Target bucket name | Yes | - |
entries | List of entries to scope the policy (wildcard * supported) | No | - |
max_age | Maximum age of records before action is applied (e.g., 30d, 1h, 5m) | Yes | - |
interval | Policy execution interval (e.g., 3600s, 10m) | No | 3600s |
when | JSON condition to filter records (see Conditional Query Reference) | No | - |
mode | Policy mode: enabled (default) or disabled | No | enabled |
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-2orsensor-*)when: Apply the policy only to records matching a condition (e.g.,{"&sensor_type": {"$eq": "temperature"}})
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_MAX_AGE: 30d
RS_LIFECYCLE_1_INTERVAL: 10m
RS_LIFECYCLE_1_ENTRIES: "sensor-1,sensor-2"
RS_LIFECYCLE_1_WHEN: |
{
"&sensor_type": { "$eq": "temperature" }
}
Managing Policiesβ
Currently, lifecycle policies can only be provisioned using environment variables. They cannot be updated or removed via the API.
Provisioned policies cannot be modified or deleted through the API. To make changes, update the environment variables and restart the ReductStore instance.
Audit Logsβ
Every lifecycle run generates a lifecycle_run event in the $audit bucket. The event includes:
- Policy name and action type
- Target bucket and duration of the run
- Number of records processed
- Error details (if any)