Skip to content

Records streams — mutable vs immutable

What this is

Validation results are stored in CDF Records API streams. A stream's mutability is fixed at creation and cannot be changed later. Operators choose a stream template when the stream is first created; runtime code auto-detects mutability and picks the correct write endpoint.

When to use each template

Template (records.stream_type) Mutability Best for
BasicArchive (default) Immutable Audit history, per-run triage, time-window analytics
BasicLiveData Mutable Current-state KPIs, de-duplicated pass/fail counts
ImmutableTestStream Immutable Non-production / test streams

Set in settings.yaml:

records:
  stream_id: dq_validation_stream
  stream_type: BasicArchive   # or BasicLiveData

records.stream_type only affects stream creation (persisted in DMS as records_stream_type). At runtime the function calls GET /streams/{id} and dispatches to ingest or upsert.

Creating the stream

deploy_validation_infrastructure() ensures the Records container and state containers — it does not create the Records API stream. Operators must create the stream separately with the intended template before validation runs:

  • Production: create the stream in CDF (Console / API) with template BasicArchive or BasicLiveData, or call ensure_records_infrastructure() from a one-off script using the same stream_id and records.stream_type from settings.yaml.
  • Local validation: run_validation(..., post_to_records=True) calls ensure_records_infrastructure(), which creates the stream if missing using records.stream_type.

Mutability is fixed at creation. Changing records.stream_type in settings after the stream exists does not alter an existing stream.

Write behavior

Stream type Endpoint Behavior
Immutable POST /streams/{id}/records (ingest) Every validation run creates a record; full history; DMS hard deletes leave historical records untouched
Mutable POST /streams/{id}/records/upsert and POST /streams/{id}/records/delete One record per stable externalId key — latest state wins, and DMS hard deletes remove stale validation records (key shape varies by validation type; see Records output)

Records use a stable externalId (no jobRunId in the key), for example:

dq_{ruleSetId}_{instanceSpace}_{instanceExternalId}

jobRunId remains a queryable property on the record.

Immutable streams — multi-run semantics

After the stable-key migration, a single externalId can match multiple records on an immutable stream (one per run). Consumers must filter or sort by:

  • jobRunId property
  • lastUpdatedTime / createdTime

Do not assume externalId uniqueness per run on immutable streams. Deleting a DMS node or edge does not remove or append records on an immutable stream — historical audit rows remain as written.

Mutable streams — current state

Re-validating the same focus upserts its record for that stable-key dimension (instance+ruleset, edge relation, etc.) — not strictly “one row per instance + ruleset” for every validation type.

When a DMS node or edge is hard-deleted (instances.delete), instance_sync_cursor (and node edge_existence_event workflows) deletes the corresponding validation record keys from the mutable stream via POST /streams/{id}/records/delete (covering the instance SHACL key plus any per-instance uniqueness and edge-existence keys declared in the RuleSet). Missing keys succeed idempotently.

Required runtime permissions on mutable streams:

  • streamsAcl:READ so runtime can detect stream type (on the DMS delete path, lookup errors preserve the sync cursor for retry rather than falling back to immutable).
  • streamRecordsAcl:WRITE to upsert and delete stream records.
  • dataModelInstancesAcl:WRITE scoped to the target record space (records.space, record_space, or the instance space when use_instance_space is enabled) — required by CDF /records/delete.

Choosing a stream for your estate

Need Recommendation
Compliance / audit trail BasicArchive
Operations dashboard (latest state) BasicLiveData after consumers support upsert semantics
High ruleset churn Mutable reduces record volume (per stable-key dimension)
Streamlit validation dashboard Stay on immutable (BasicArchive) — the dashboard queries by lastUpdatedTime windows, not mutable upsert keys

Migration notes

  • Mixed externalId schemes: older run-scoped ids (dq_{ruleSetId}_{externalId}_{jobRunId}) may coexist with stable ids until retention removes them.
  • Legacy mutable / immutable strings in settings are mapped to CDF template names when creating a new stream via ensure_records_infrastructure() (not when loading DMS settings at runtime).
  • RAW on mutable streams: stable keys qualify each row with database, table, and a 16-hex tuple digest (dq_{ruleSetId}_{dbName}_{tableName}_{rowKey}_{hash16}), so multiple RAW tables sharing row keys or underscore-containing names can safely share a mutable stream. Older space-less dq_{ruleSetId}_{rowKey} entries may coexist during transition.

Full schema and query examples: Records output.