﻿# Primary-key changes in CDC: keep feature and label identity linked through migration

Primary-key changes in CDC: keep feature and label identity linked through migration. A practical data-quality guide with failure mechanisms, validation steps, acceptance evidence and primary references.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/dq-primary-key-change-cdc-label-link/
Language: en

A business record receives a new primary key. The feature consumer processes the new row, while the annotation consumer retains the old key, leaving apparently valid but disconnected training data.

## The mechanism that changes the example

Key mutation is more than an ordinary feature update. The source may represent it through multiple events, and downstream identity mappings must define whether the entity persists across the change.



## Define the comparison boundary

Read the connector's documented representation of a primary-key update. For the chosen Debezium PostgreSQL contract, key changes involve old-key and new-key events rather than one ordinary update that every consumer can treat independently.

Preserve both transport key and stable business identity where the application has a reviewed continuity rule. An annotation may legitimately belong to the old historical version; reassociation must follow that rule rather than an unconditional text replacement across all records.

Stop the consumer between the old-key removal and new-key creation, then restart and repeat delivery. The intermediate state must not be published as a complete training release. Verify that old references are either migrated, retained as explicitly historical, or rejected, and that a later reuse of the old business key cannot inherit unrelated annotations.

## A constructed test case

Change an entity key while labels still reference the earlier key. Pause the consumer between source events. Inspect whether recovery preserves authorized continuity without leaving both old and new active examples or attaching a reused key to the wrong entity.

## A reproducible validation procedure

Capture the exact source event sequence for a controlled key change. Verify removal of the old materialization, creation of the new one and annotation reassociation under an explicit identity rule. Test interrupted delivery between events.

Include an unchanged control and a deliberately invalid case. Verify that the checker distinguishes them before testing the complete release.

Exercise the actual preparation path, including later serialization and reload. Limit retained diagnostic content to the evidence required for this comparison.

## Evidence needed for acceptance

Retain the old-to-new identity mapping and evidence that no duplicate active entity survives.

## Containment and recovery

A business key can be reused by a different entity, so matching key text does not establish continuity.

Quarantine an invalid release candidate or use an explicit partial-release rule. Preserve the last approved artifact and record corrections without silently rewriting historical inputs.

## Interpretation and references

Implementation references: [Debezium PostgreSQL change events](https://debezium.io/documentation/reference/stable/connectors/postgresql.html); [pandas merge validation](https://pandas.pydata.org/docs/reference/api/pandas.merge.html).

This is a proposed engineering validation, not an executed Retrivium benchmark. Documentation specifies interfaces; dataset acceptance needs its own evidence and must be repeated after relevant dependency changes.

## Related reading

Continue with [Argilla record updates: retain the server identity and protect the meaning of old feedback](/journal/fg2-argilla-record-update-source-identity/); [COCO: preserve image and annotation identities](/journal/data-guide-coco-instance-caption-identities/). These guides supply adjacent context; the decision in this article remains the specific example-preservation check above.
