Retention

Retention

Retention trims a stream's oldest records automatically, once they pass an age or the stream passes a size.

Retention removes a stream's oldest records for you. You give the stream a maximum age, a maximum size, or both, and Nova trims the records that fall outside them. This stream keeps seven days of records and at most 10 GiB:

POST /v1/streams/demo/logs
{
  "stream_id": "01a20485-60b4-76f9-81a2-6af8507b7704",
  "bucket": "demo",
  "key": "logs",
  "kind": "plain",
  "class": "standard",
  "producer_policy": "any",
  "retention_max_age_ms": 604800000,
  "retention_max_bytes": 10737418240,
  "timestamping_mode": "client-prefer"
}

Without retention, a stream keeps every record until you trim it or delete the stream. That suits a stream that is your system's source of truth. Retention suits a stream that is a buffer on the way somewhere else, such as logs, telemetry, or session events.

Retention by age

With retention_max_age_ms, Nova removes records whose timestamp is older than that age. It compares record timestamps with the current time, so it works on a stream that nobody writes to.

Nova removes records in the groups it stored them in. A group goes once its newest record passes the age, so a record can stay readable for a short time after it passes the age.

Age retention reads timestamps as clock time. A stream with uncapped timestamps can hold values that are not times, so Nova refuses a stream or bucket that sets both.

Retention by size

With retention_max_bytes, Nova keeps the stream's size under that many bytes, counting record bodies and headers. When the stream grows past it, Nova removes the oldest records until the stream fits again. It removes whole groups of records, as Nova stored them, so it can remove a little more than the excess.

Nova checks the size each time the stream grows by an eighth of the limit, or by 1 MiB if that is more. Between checks, and while a trim runs, a stream can hold a little more than its limit.

How retention applies

A record that retention removes behaves like a trimmed one. Reads below the new watermark fail with 410 Gone, and sequence numbers do not change. A background process deletes the records' storage later, usually minutes after they pass the limit; background work explains the delay.

When a stream sets both an age and a size, a record goes as soon as either one says so. On a scalable stream, the age applies to every range and the size counts the whole stream across its ranges.

You set retention when you create a stream, or it comes from the bucket's defaults. You can change it at any time, on a scalable stream too. Most changes apply at once: Nova runs a retention pass right away. The exception is a shorter age on a stream that already has an age and no size limit. It applies only once the oldest records still kept pass the old age. To apply the shorter age sooner, trim the stream to the new cutoff time. Setting a bound to 0 in a change removes it. In a create request, 0 means "use the bucket's default"; Settings explains why.

How it works: Background work.

See also

On this page