Table of Contents

Interface IAggregateDataSubjectMapping

Namespace
Excalibur.EventSourcing.Erasure
Assembly
Excalibur.EventSourcing.dll

Maps data subject identifiers to the aggregate instances that contain their personal data.

public interface IAggregateDataSubjectMapping

Examples

// Returns the aggregate holding the subject's PERSONAL DATA -- not their orders.
// Erasing this removes the person; the orders survive, carrying only a customer reference.
public class CustomerAggregateMapping : IAggregateDataSubjectMapping
{
    private readonly ICustomerRepository _repository;

    public async Task<IReadOnlyList<AggregateReference>> GetAggregatesForDataSubjectAsync(
        string dataSubjectIdHash, string? tenantId, CancellationToken cancellationToken)
    {
        var customerId = await _repository.FindIdByHashAsync(dataSubjectIdHash, cancellationToken);

        return customerId is null
            ? []
            : [new AggregateReference(customerId, "Customer")];
    }
}

// DO NOT do this unless the order aggregate genuinely holds nothing you must retain.
// Every event of every returned order is tombstoned: amount, dates, line items, all of it.
//     return orderIds.Select(id => new AggregateReference(id, "Order")).ToList();

Remarks

Consumers MUST implement this interface to support GDPR erasure of event-sourced aggregates. The implementation is application-specific because only the application knows which aggregates belong to which data subjects.

WHAT YOU RETURN HERE IS WHAT GETS DESTROYED, AND THE DESTRUCTION IS TOTAL AND IRREVERSIBLE. Erasure does not remove a subject's fields from the aggregates you name. It tombstones every event of every aggregate you name — the payload is nulled and the event type is replaced with a reserved marker. Nothing is selective: not by field, not by event type.

So if you return a transaction aggregate — an order, a sale, a service visit, a loan — you lose the transaction, not just the personal data in it. The amount, the dates, the line items and the vehicle or account identifier go with the customer's name. Those are frequently records you are separately obliged to keep: tax records, warranty and product-recall traceability, and anti-money-laundering records with multi-year retention minimums. Privacy regimes generally carve such material out of the erasure right — but this framework cannot act on that carve-out, because erasure here operates on whole aggregates and this interface is where you told it the aggregate belonged to the subject. Consult your own counsel on what you must retain; what is stated here is only what OUR mechanism does.

Return the aggregates that hold the PERSONAL DATA, not the aggregates the subject participated in. Model so a Customer aggregate carries the identifying data and transaction aggregates carry a reference to it; return the Customer. Erasing it then removes the person and leaves the transactions standing, which is the outcome both regimes describe.

Known gap, stated rather than left to be discovered: where personal data is unavoidably embedded in a transaction event — the buyer's name on an invoice — there is no supported way to erase the name and keep the invoice. Whole-aggregate tombstoning is the only mechanism, so the choice is to destroy the record or to retain the personal data.

Retaining it is a DECLARED decision, not a gap you work around privately. Return fewer aggregates, and declare the retention through AddErasureRetention: an ErasureRetention names the aggregate type, the tenant partition, the LegalHoldBasis you are relying on, a written justification, and the retention period. The declaration is what makes the choice auditable — the basis and justification are recorded against the erasure rather than living in a process of your own that the erasure record cannot see. Declaring a retention does not erase the embedded field; it states, on the record, that you are keeping it and why.

Common strategies for locating the aggregates that hold personal data:

  • Query a lookup table mapping subject IDs to the aggregate that holds their personal data
  • Use naming conventions (e.g., the personal-data aggregate ID equals the subject ID)
  • Search an index or projection that tracks data subject ownership

Methods

GetAggregatesForDataSubjectAsync(string, string?, CancellationToken)

Resolves all aggregate references associated with a data subject.

Task<IReadOnlyList<AggregateReference>> GetAggregatesForDataSubjectAsync(string dataSubjectIdHash, string? tenantId, CancellationToken cancellationToken)

Parameters

dataSubjectIdHash string

The SHA-256 hash of the data subject identifier.

tenantId string

The tenant ID for multi-tenant scenarios, or null.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IReadOnlyList<AggregateReference>>

A list of aggregate references that contain data for the specified data subject.