Design a retention schedule generator: legal minima/maxima and overrides.
- User
Design a retention schedule generator: legal minima/maxima and overrides.
Assistant
Design a retention schedule generator: legal minima/maxima and overrides.
The user wants to "Design a retention schedule generator: legal minima/maxima and overrides."
This is a request for a system design or architecture for a software component that generates data retention schedules based on legal requirements and specific overrides.
Deconstruct the Request:
Target Audience/Context: Likely a software engineer, system architect, or product manager looking for a conceptual design or a high-level implementation strategy. The tone should be professional, structured, and technical.
Key Components of the Design:
Data Model (The "Knowledge Base"):
Logic Engine (The "Brain"):
The "Generator" (The Output):
Overrides (The "Exceptions"):
Step-by-Step Design Plan:
Drafting the Content - Specific Ideas:
(Region, DataClass) -> {Min, Max}.Calculated_Min > Calculated_Max, the system is in an illegal state. Alert compliance immediately. Do not delete, do not keep? usually, default to keeping until reviewed by human.Refining the "Overrides":
Structure of the response:
Self-Correction/Review during drafting:
Final Polish: Ensure the distinction between "Minimum" (don't delete too early) and "Maximum" (don't keep too long) is clear, as this is central to GDPR compliance.
Let's build the response.
getRetentionPolicy(dataObject).Let's write it out. Designing a retention schedule generator requires balancing rigid legal compliance with flexible business logic. The system must prevent users from illegally deleting data too soon (undershooting) while ensuring they do not keep it too long (overshooting), violating privacy principles like "Data Minimization" (GDPR Art. 5).
Below is a comprehensive design specification for a Policy-Driven Retention Engine.
The engine operates on a "Funnel of Constraints" approach.
[Data Asset] + [Jurisdiction] + [Industry]
↓
[Legal Rule Registry] → Calculate {Legal Min, Legal Max}
↓
[Business Policy Layer] → Adjust {Business Min, Business Max}
↓
[Active Overrides (Holds/Consent)] → Adjust {Effective Min, Effective Max}
↓
[Conflict Engine] → Finalize {Deletion Date}
↓
[Scheduler] → Enforce Action
We need three distinct schemas to handle the variables.
This database stores the regulatory requirements. It must be version-controlled.
| Field | Description | Example |
|---|---|---|
| Regulation | Source law | GDPR, CCPA, SOX, HIPAA |
| Jurisdiction | Geo-applicability | EU, California, US-Federal |
| Data Category | Type of data | PII, Financial Records, Medical |
| Min Duration | Must keep at least this long | 0 years (immediate) |
| Max Duration | Must delete by this time | 3 years |
| Trigger Event | When the clock starts | contract_end, last_interaction, creation |
| Penalty Weight | Risk factor for conflicts | Critical (Criminal), High (Fine), Low |
Overrides interrupt the standard flow.
Min Duration = Indefinite.Max Duration.To generate a schedule, the engine needs context about the specific data record.
CreationDateLastModifiedDateDataClassification (e.g., "Employee Record")ApplicableJurisdiction (e.g., "EU")The core generator calculates the Retention Window.
function generateSchedule(asset, legalRules, businessPolicies, activeOverrides):
# 1. Identify Base Trigger
# When does the clock start? (e.g., Employment Termination Date)
base_trigger_date = resolveTriggerDate(asset, legalRules.trigger_event)
# 2. Calculate Legal Boundaries
# Aggregate all applicable laws
applicable_rules = filter(regulations, asset.jurisdiction, asset.type)
# The "Safety Floor": The longest minimum retention among all laws
# (We must comply with the strictest "keep" law)
global_min_duration = MAX(rule.min_duration for rule in applicable_rules)
# The "Compliance Ceiling": The shortest maximum retention among all laws
# (We must comply with the strictest "delete" law)
global_max_duration = MIN(rule.max_duration for rule in applicable_rules)
# 3. Check for Conflicts (Impossible State)
if (base_trigger_date + global_min_duration) > (base_trigger_date + global_max_duration):
raise ConflictError("Legal requirements contradict: Cannot keep data short enough to satisfy Min retention.")
# 4. Apply Business Logic
# Companies often keep data longer than legally required for analytics,
# but this cannot exceed the Legal Max.
effective_duration = MIN(businessPolicies.desired_retention, global_max_duration)
# 5. Apply Overrides
# If a Legal Hold exists, we push the Max to Infinity
if activeOverrides.hasLegalHold():
final_deletion_date = Infinity
status = "FROZEN"
else:
final_deletion_date = base_trigger_date + effective_duration
status = "SCHEDULED"
return {
"status": status,
"earliest_deletion": base_trigger_date + global_min_duration,
"target_deletion": final_deletion_date,
"hard_deadline": base_trigger_date + global_max_duration
}
The most critical part of this design is how the system handles conflicting requirements.
Design Solution: The system must flag this as a "Compliance Deadlock".
Design Solution: The system creates a "pin" on the record.
SUSPENDED.SUSPENDED, it skips.When an admin sets up a policy, the UI should visualize the "Safe Zone."
Visual Representation: A timeline slider.
Override Panel: A simple modal to inject a hold:
Reason: [Dropdown: Litigation / Audit / Investigation] Duration: [Indefinite] or [Specific Date] Impact: "This will suspend deletion for 450 records."
UserDeleted), emit an event. The Retention Engine listens, calculates the target_deletion_date, and writes it to a "Tombstone Table" (a list of IDs and deletion dates).NOW() and performs the physical deletion.