Observability Data Retention

Comprehensive guide to observability data retention for production observability and monitoring systems.

Observability data retention governs how long and how much telemetry data—logs, metrics, traces, and events—is preserved across systems. It matters when diagnosing incidents, analyzing long-term trends, or validating system behavior over weeks or years. Retention is the foundation of historical context: without it, alerting is reactive, dashboards are static, and root cause analysis becomes guesswork.

Defining Retention Policies

Retention policies determine how long data survives and at what fidelity. They are defined by two core parameters: retention duration and compression tiering.

Retention duration sets the lifecycle of data. A policy might keep raw logs for 7 days, compressed metrics for 90 days, and aggregated traces for 365 days. These durations are typically expressed in days, but can be absolute dates or intervals.

Compression tiering applies different storage and access strategies to data based on age. Data is initially stored in high-fidelity, low-latency formats (e.g., uncompressed, in-memory), then progressively archived to lower-cost, slower-access formats.

For example:

retention:
  logs:
    duration: 7d
    compression: gzip
    storage: s3://observability-logs/
    tiering:
      - age: 1d
        retention: 7d
        storage: mem
        compression: none
      - age: 7d
        retention: 30d
        storage: s3
        compression: gzip
      - age: 30d
        retention: 365d
        storage: s3
        compression: zstd

This policy ensures that recent logs are immediately available with low latency, while older logs are compressed and archived.

Configuring Data Retention in Practice

Retention is applied at the source: when data is ingested. Systems like Fluentd, OpenTelemetry Collector, and Prometheus use configuration files to define retention per data stream.

In Fluentd, retention is declared in the match block of the configuration:

<match logs.*>
  @type copy
  <store>
    @type file
    path /var/log/observability/logs
    flush_interval 10s
    retention_duration 7d
    compression gzip
  </store>
  <store>
    @type s3
    bucket observability-logs
    path logs/
    region us-east-1
    retention_duration 30d
    compression zstd
  </store>
</match>

The retention_duration key controls how long data is retained in each output. When a new file is written, the system records its creation time. A background process, often a retention-worker, runs daily to evaluate whether any file should be moved or deleted.

Data Lifecycle and Tiering

Data evolves over time. Fresh data is kept in primary storage (e.g., SSD-backed), while older data is moved to cold storage (e.g., S3, Glacier). The transition is governed by a tiering policy.

A tiering policy consists of rules that define when data is promoted or demoted. Each rule has:

When a data block reaches its threshold age, it is moved to the next tier. The system maintains metadata about each block: created_at, last_accessed, size, compression, storage_location.

A typical tiering pipeline:

  1. Ingest: Data arrives via fluentd or otelcol.
  2. Hot Tier: Data stored in memory or fast SSDs, retention_duration: 1d, compression: none.
  3. Warm Tier: After 1 day, data is compressed (gzip), moved to S3, retention_duration: 30d.
  4. Cold Tier: After 30 days, data is recompressed (zstd), archived to S3 Glacier, retention_duration: 365d.

Migration is asynchronous. A single worker process scans all data blocks daily:


0 2 * * * /usr/local/bin/retention-worker --config /etc/retention.yaml --log-level info

The worker checks each data block against the tiering rules. If age > threshold, it triggers a move operation: copy data to new storage, update metadata, and mark the old block for deletion.

Common Failure Modes and Silent Failures

Retention systems silently fail in subtle but critical ways:

1. Retention Duration Misalignment

The most common failure is mismatched retention_duration values between ingestion and storage. For example, Fluentd writes logs with retention_duration: 7d, but the S3 retention worker expects data to be retained for 30d. This causes data to be prematurely deleted.

A log file created on 2024-04-01 is written to S3 with created_at: 2024-04-01T00:00:00Z. The retention worker, running on 2024-04-08, sees that the file is 7 days old and moves it from hot to warm storage. But it also checks the retention_duration field and finds 30d, so it expects the file to remain in warm storage for 30 days. Yet, the file is now only 7 days old in warm storage, and the retention period is not yet met.

This leads to under-retention: data is migrated too early, but the system doesn’t respect the full retention window.

2. Compression and Format Mismatch

Data is often compressed during tiering, but the system assumes a specific format without validation. A file is written as zstd, but the reader expects gzip. The reader fails silently, producing invalid data.

The error is not in the logs but in the metadata. The retention system writes:

{
  "file": "logs/2024-04-01-00-00-00.gz",
  "created_at": "2024-04-01T00:00:00Z",
  "compression": "zstd",
  "storage": "s3://observability-logs/logs/"
}

But the reader assumes compression: "gzip" and tries to decompress the file using gunzip. The output is Error: Invalid zstd header, even though the file is correctly compressed. The reader fails to decode the data, and downstream systems report missing or corrupted logs.

3. Retention Worker Not Running

The retention worker is often a single binary with no monitoring. If it fails to run, data is never tiered. A systemctl status check reveals:

$ systemctl status retention-worker
● retention-worker.service - Observability Retention Worker
   Loaded: loaded (/etc/systemd/system/retention-worker.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2024-04-02 02:00:00 UTC; 12h ago
 Main PID: 1234 (retention-worker)
   CGroup: /system.slice/retention-worker.service
           └─1234 /usr/local/bin/retention-worker --config /etc/retention.yaml

Apr 02 02:00:00 server retention-worker[1234]: Starting retention worker
Apr 02 02:00:00 server retention-worker[1234]: Loaded config from /etc/retention.yaml
Apr 02 02:00:00 server retention-worker[1234]: Running daily retention cycle

But the journalctl log shows no entries after Apr 02 02:00:00. The worker started, processed one cycle, then exited. No error, no logging, no health check.

The cause: the worker binary is not kept alive. It runs once, processes the queue, and exits. The systemd unit is configured with Type=oneshot, but no RemainAfterExit=yes.

Fix:

[Unit]
Description=Observability Retention Worker
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/retention-worker --config /etc/retention.yaml
Restart=on-failure
RestartSec=30s

[Install]
WantedBy=multi-user.target

Without this, data remains in hot storage indefinitely, but the warm and cold tiers are never populated.

Data Access and Querying Across Retention Levels

Queries must be aware of retention tiers. A query to retrieve logs from 2024-03-15 to 2024-03-20 must:

  1. Locate the data in the correct storage (e.g., S3)
  2. Check the compression format
  3. Decompress the data as needed
  4. Apply any filters or aggregations

The query engine must support tier-aware access. For example, a curl request to a log service:

$ curl -X GET \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  "http://logs.example.com/query?from=2024-03-15T00:00:00Z&to=2024-03-20T23:59:59Z"

The service responds:

{
  "data": [
    {
      "timestamp": "2024-03-15T01:23:45Z",
      "level": "error",
      "message": "Failed to connect to database",
      "service": "user-service"
    },
    ...
  ],
  "metadata": {
    "storage": "s3://observability-logs/logs/2024/03/15/",
    "compression": "zstd",
    "retention": "30d",
    "source": "cold-tier"
  }
}

The client uses metadata.source to decide whether to cache the data locally or stream it.

Querying Across Tier Boundaries

When a query spans multiple retention tiers, the system must merge results. For example, a query from 2024-01-01 to 2024-04-01 pulls data from:

The query engine must:

  1. Retrieve data from each tier
  2. Decompress each stream
  3. Merge results by timestamp
  4. Deduplicate if needed

The failure mode: time gap between tiers. A log file from 2024-03-01 is in hot storage, but the warm tier starts at 2024-02-28. The query returns two overlapping streams with different timestamps. The client must detect and resolve this.

Retention and Data Lifecycle Management

Retention is not a one-time setup. It requires ongoing maintenance:

A retention violation occurs when a data block is removed from storage, but the created_at and retention_duration indicate it should have stayed longer.

Example violation:

{
  "block_id": "logs/2024-01-01-00-00-00.gz",
  "created_at": "2024-01-01T00:00:00Z",
  "retention_duration": "30d",
  "deleted_at": "2024-01-31T23:59:59Z",
  "expected_until": "2024-01-31T00:00:00Z",
  "actual_duration": 30.999 days
}

The block was deleted on 2024-01-31, but the expected retention was 30 days, so it should have remained until 2024-01-31T00:00:00Z. The data was deleted 23 hours too early.

This violation triggers an alert: "Retention under-runs detected: 12 files missed retention window."

Best Practices and Key Decisions

Retention is not just storage; it is the architecture of time.

This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.