Keep source record merges separate from historical fact identity
In brief
Keep each fact's original source ID after a record merge. Use a versioned mapping to group historical facts under the current company.
- Follow merge chains using the result IDs returned by the source.
- If a merge is corrected, rebuild the affected groups from the original IDs.
A CRM merges company A into company B. Yesterday’s invoices still carry A, while today’s company export contains only B.
If the analytical model drops facts whose original company no longer exists, it loses valid invoices. If it replaces every stored A with B, a later correction gets harder to undo.
Keep the original source identity on the fact.
Build a separate, versioned mapping from accepted source merge evidence to the canonical identity each consumer needs. A current consolidated customer view follows the complete merge chain, while a view that must preserve the original billing identity keeps that identity as it was.
The source has to provide a reliable relationship: matching names or disappearing records aren’t enough to infer one.
A suspected duplicate goes through a reviewed identity-resolution process first. Only an established relation enters this mapping.
Record what the source says happened
Capture the retired identifiers, the result identifier the source returned, source account and object type, merge evidence, and the source’s ordering or revision information. Keep the original payload or another durable reference to it. A record ID is only unique within the scope the producer promises. The namespace belongs in the key.
The selected primary record may not keep its ID. The connector has to read the ID the merge returns.
If A merges into an existing B, keep the edge from A to B. If A and B become a new C, keep edges from both A and B to C. Storing only the secondary ID would lose the former primary’s path.
An ordinary source delete says less. It may mean removal, archival, privacy erasure, or a merge whose relation is recorded elsewhere. Keep the deletion state according to its own contract, and look for the missing relation in the producer’s supported evidence. A guessed merge can attach one customer’s activity to another.
Resolve the resulting object’s attributes separately. The source can pick particular fields or associations independently of the IDs. Fetch or capture its authoritative state through the normal extraction path instead of rebuilding its name, status, or owner from whichever old row arrived last.
Resolve a chain without losing its evidence
A later merge can change B into C, and original A must then resolve through B to C. Updating only records currently labeled B can miss A if a previous run kept the wrong intermediate representation or discarded the original relation. Store the accepted edges and build a flattened mapping for consumption, in which one source identity resolves to exactly one terminal identity per mapping version. The original edges explain the result. The flattened mapping saves every dashboard from traversing a graph.
Before resolving, reject conflicting active successors for the same source identity. Two accepted edges from A to different results need source precedence or a correction before anything resolves. Collapse exact duplicate evidence only after confirming that the claimed identity and revision really describe the same relation.
This small TypeScript resolver represents identities as tuples of source account, object type, and source ID. Its inputs have already passed shape and active-edge validation. Key edges and knownIds with identityKey(id) so separately constructed tuples have the same lookup key:
type Identity = readonly [sourceAccount: string, objectType: string, sourceId: string];
function identityKey(id: Identity): string {
return JSON.stringify(id);
}
function resolveId(
start: Identity,
edges: ReadonlyMap<string, Identity>,
knownIds: ReadonlySet<string>,
maxHops = 32,
): Identity {
if (!knownIds.has(identityKey(start))) {
throw new Error('Unknown source identity');
}
let current = start;
const visited = new Set<string>();
let hops = 0;
while (true) {
const key = identityKey(current);
const target = edges.get(key);
if (target === undefined) return current;
if (visited.has(key)) throw new Error('Merge cycle');
visited.add(key);
if (current[0] !== target[0] || current[1] !== target[1]) {
throw new Error('Merge crosses source scope or object type');
}
if (!knownIds.has(identityKey(target))) {
throw new Error('Unverified merge destination');
}
if (hops >= maxHops) {
throw new Error('Merge path exceeds configured limit');
}
current = target;
hops += 1;
}
}The hop limit is an operational bound for this example. Exceeding it fails resolution. Returning the last visited ID would present an intermediate record as the final identity. A longer valid chain needs a higher configured limit or another resolver.
Known identities can come from verified records or accepted merge evidence, and a new result’s attributes may arrive after its identity is known. Track that missing attribute state separately to keep a verified destination that isn’t enriched yet distinct from an unverified one.
The resolver rejects edges across source accounts or object types.
Cross-system identity resolution needs its own mapping authority and evidence. Two unrelated CRMs can both use ID 42 for different companies.
Preserve the fact and choose its identity projection
Keep invoice identity independent from company identity. Keep deduplicating facts by the source event or document contract. A merge only changes which company grouping an invoice may contribute to.
Take four invoices, originally assigned to A, B, C, and D, with amounts 100, 200, 300, and 400. Their source identities and their total of 1,000 stay fixed while different accepted mapping versions produce these current groupings:
| Mapping version | Accepted relations | Grouped amounts |
|---|---|---|
| 1 | A to B | B: 300; C: 300; D: 400 |
| 2 | A to B; B to C | C: 600; D: 400 |
| 3 | A to D; B to C, after an authoritative correction | C: 500; D: 500 |
Version 3 corrects the mapping evidence. Because invoice A still carries A, the corrected projection can move its 100 from C to D. Nobody has to guess which part of an overwritten customer total originally belonged to it.
A mapping version must appear in the join condition or be fixed by the served view. Joining invoices to every historical mapping row multiplies each fact. Joining all three versions turns four invoices totaling 1,000 into twelve joined rows totaling 3,000. Each mapping version is individually unique, so a uniqueness check that includes the version wouldn’t catch that consumer error.
For a single source and a narrow consolidated view, a validated mapping like this may be enough. You don’t need a separate identity service just to follow a handful of merges.
Some historical questions need the original identity. Keep original contractual counterparties where the output requires them.
The pipeline should expose the declared projection, while the owner of the report decides whether previously issued results are restated. Avoid changing both identity policy and the source adapter in one unexplained repair.
Treat a corrected relation as a rebuildable input
Keep each accepted mapping version, the evidence used to build it, and the original source keys. The mapping is derived state. If an adapter reversed the direction or missed a newly created result ID, rebuild from that evidence and compare the old and new resolutions.
Test a reversed edge against the source evidence. B-to-A is a valid acyclic graph even when the source clearly said A-to-B. Neither cycle detection nor total reconciliation will reject it.
To catch that mistake, compare the directed mapping with the source’s own statement of the result. Write at least one expected mapping fixture by hand from the payload roles, independently of the adapter under test.
For a changed edge, the affected set includes every original identity whose path used it: a correction involving B can change A through the chain. Compare the flattened old and candidate maps, then select facts by their preserved original IDs. Repair materialized customer totals and other dependent outputs from that set. Keep unaffected identities as controls.
Publish one accepted mapping version together with the outputs built from it.
A dashboard joining a new identity map to an aggregate grouped under the old one can produce missing or misleading results, even when both tables pass their own assertions. Keep the previous version until the replacement and its dependent outputs meet the release contract.
If the original evidence has been lost, a current source fetch may only return the surviving record, without the old association or attributes. HubSpot’s merged records can’t simply be unmerged either. Keep an analytical mapping correction separate from any attempt to reverse source operations. Record which historical distinctions can still be recovered.
Replay merge histories through the resolver
Start with a merge that keeps the primary’s ID and one that creates a new result ID, then chain a second merge through the first. Replay duplicate evidence and add conflicting successors, a cycle, an unknown destination, and an overlong path. Each rejection should keep enough evidence to explain why the mapping is unavailable. After a valid correction, check both the new grouping and the preserved results of the previous mapping version.
A connector acceptance test needs the real interface’s merge payload, replay and ordering behavior, returned IDs, and an ordinary late fact carrying a retired ID. Resolve that late fact through the same accepted map. Dropping it when the source no longer lists the retired record would reintroduce the original data loss.
More in this domain: Data
Browse allWhen cold history should stay in BigQuery
Keep cold history in BigQuery when retrieval costs would outweigh the storage savings.
BigQuery global queries or a local serving copy?
A global BigQuery query can suit occasional selective reads. An approved local copy can save transfers when reports repeatedly read the same remote data.
Use BigQuery clones for bounded development work
Use a writable BigQuery clone when a test needs the source data's distribution or history. Use a small fixture when it reproduces the problem.
When external Parquet deserves a native BigQuery copy
Keep Parquet external for occasional reads. A native BigQuery copy can pay off when reports repeatedly scan the same files.
Publish a BigQuery dataset without sponsoring every reader's queries
Publish a BigQuery dataset when readers need SQL and have their own execution project. Offer versioned downloads for readers who just need the data.
Related patterns
Repair a Type 2 dimension when a correction changes the past
Repair a Type 2 dimension from the correction's effective date and revisit facts whose historical match changes.
Dataform assertions: make failures block downstream models
Make Dataform publication depend on the candidate's assertions and include those assertions in the selected run.
Partitioning defaults for event tables that don't lie
Partition BigQuery event tables by the date consumers filter on.
How we prevent stale rows in incremental fact models
Rebuild each affected fact row from its inputs and remove rows that no longer qualify.