Data Retention Policies

Define data retention periods and automated expiry actions (Delete or Anonymize) for GDPR Article 5(1)(e) compliance.

Data Retention Policies define how long specific categories of data must be kept and what happens when the retention period expires. SCRIPE enforces these policies automatically via background jobs, removing the manual overhead of managing data lifecycles.

Retention Policy Evaluation Flow

The automated retention engine scans database tables periodically, evaluating record age against configured retention thresholds.

Cron Trigger — Recurring background job triggers retention policy evaluation.
Trigger to Policy Fetch
Policy Fetch — Queries active retention policies and jurisdiction profiles for tenant.
Policies to Batch Iterator
Batch Iterator — Iterates through candidate expired entities in manageable transactional batches.
Batch to Execution
Retention Execution — Audit trail of the destruction action
Execution to Anonymization
Anonymization Engine — Applies cryptographic masking or pseudorandom hashing to sensitive PII.
Anonymization to Destruction
Destruction Worker — Executes cascading hard deletion of records past maximum retention.
Destruction to Cycle Finalization
Cycle Completion — Finalizes execution state, updates metrics, and releases locks.
Finalization to Audit Trail
Immutable Audit Log — Appends tamper-evident execution receipt to compliance audit trail.

Expiry Actions

When a retention period expires, SCRIPE applies one of two actions:

Action TypeDescriptionPrimary Use Cases
Hard DeletePermanently purges matching records and dependencies from physical storage.Statutory mandatory deletion, temporary cache files, transient sessions.
Soft DeleteMarks records as inactive and excluded from operational queries while preserving history.Standard business entities requiring legal hold or graceful user deactivation.
AnonymizeReplaces PII with pseudonymized tokens while retaining aggregated reporting metrics.Financial transactions, analytics events, order histories, billing ledgers.

Retention Policy Service Registration

Registering custom retention evaluators and scheduling Hangfire recurring execution jobs.

RetentionEnforcementJob.csC#
public class RetentionEnforcementJob : IAutoRegisteredJob
{
    public string JobId => "compliance-retention-enforcement";
    public string CronExpression => "0 2 * * *"; // Run daily at 2 AM

    public async Task ExecuteAsync(CancellationToken ct)
    {
        var policies = await _dbContext.RetentionPolicies
            .Where(p => p.IsActive)
            .ToListAsync(ct);
            
        foreach (var policy in policies)
        {
            var execution = new RetentionExecution { PolicyId = policy.Id };
            try
            {
                var affectedCount = await _retentionExecutor.ExecutePolicyAsync(policy, ct);
                execution.Status = ExecutionStatus.Completed;
                execution.RecordsAffected = affectedCount;
            }
            catch (Exception ex)
            {
                execution.Status = ExecutionStatus.Failed;
                execution.ErrorMessage = ex.Message;
            }
            await _dbContext.RetentionExecutions.AddAsync(execution, ct);
        }
        await _dbContext.SaveChangesAsync(ct);
    }
}

Retention Data Model

Configurable retention rules specifying target entities, retention periods in days, and disposal actions (Anonymize or Purge).

Field NameData TypeDefine data retention periods and automated expiry actions (Delete or Anonymize) for GDPR Article 5(1)(e) compliance.
TenantIdGuidTenant workspace owning this retention policy rule.
RegulationProfileIdGuidJurisdiction regulation profile governing this retention policy.
NameStringDescriptive name of the retention policy.
DescriptionString?Detailed business justification and scope of the retention policy.
CategoryEnumTarget data category governed by this retention schedule.
RetentionDaysInt32Default retention period duration in days before action is executed.
MinRetentionDaysInt32Minimum statutory holding period before deletion is legally permissible.
MaxRetentionDaysInt32Maximum allowable storage duration under GDPR storage limitation principle.
ExpiryActionStringAutomated action executed upon expiry (Delete, SoftDelete, or Anonymize).
NextEvaluationAtDateTimeTimestamp scheduled for the next automated policy evaluation run.
IsActiveBooleanWhether the retention policy is active and enforced by background workers.

API Endpoints

MethodEndpointDescriptionAuth
GET/api/v1/compliance/retentionList all configured retention policies and schedules for the tenant.🔒 Required
PUT/api/v1/compliance/retention/{id}Update retention threshold days, expiry actions, or active status.🔒 Required
GET/api/v1/compliance/retention/executionsRetrieve historical retention execution logs and purged record counts.🔒 Required