Pattern: Deletion, retention schedule and legal hold
Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.
For agents
- Offer as a suggestion. The numbers (7 days, 30 days) are examples; legal duties differ by country and should be confirmed by a lawyer.
- Core ideas: deleted data disappears from view at once, leaves the live system within days, leaves backups within a fixed further period, and the terms tell users exactly that.
- Related: reports and moderation, data export and account deletion, admin permissions.
1. Problem
“Delete” can mean hidden, removed from the database, removed from backups, or removed from third-party processors. If the notice to users and the real behaviour differ, trust and compliance suffer. Cleanup jobs that silently skip work are worse than no jobs.
2. Options
| Method | Upside | Downside |
|---|---|---|
| Hard delete immediately | Simple; data gone | Backups still hold it; no undo for mistakes; conflicts with open reports |
| Soft delete only | Easy undo | Data stays forever unless a purge job exists |
| Staged timeline (recommended) | Honest, predictable, supports undo and holds | Needs scheduled jobs and monitoring |
3. Recommended design
Timeline (example values)
- At the moment of deletion: invisible to users and APIs.
- Within at most 7 days: removed from the live database and storage.
- Backups: remain for at most 30 more days (the backup rotation), then gone. So the latest everywhere is about day 37.
- The terms of service state this correctly. On-screen short notes must not understate backup and third-party (for example AI provider) retention.
Legal hold
- An authorized person adds a hold in the admin panel (with a reason; the action is audit-logged). While a hold exists, data the user deletes is not deleted in the background: it stays in place and no extra copy is made. When the hold lifts, items already past their time get a short grace period (example: 3 days), then deletion runs. This pattern is practitioner experience; ask counsel which situations justify holds.
Linked records
- Deleting a record does not silently delete records tied to it. Example: deleting a chat does not remove reminders created from it; decide per relation and document it.
Cleanup jobs
- Run in batches, oldest first, and idempotent. “Skipped” is not success: raise an alarm when a job skips or fails.
- Object stores: lifecycle rules can expire objects on a schedule (AWS S3 Lifecycle documentation); backup retention is a design decision described in the AWS Well-Architected Reliability pillar on backups.
- Keep logs of deletions with identifiers, not content (OWASP Logging sheet).
Account deletion has extra store rules: see data export and account deletion.
4. Scenarios and edge cases
- User deletes, then restores within the window: allowed only before the live purge; after that, restore is impossible and the notice says so.
- Backup restored after an incident: re-run deletions recorded since the backup was taken, so deleted data does not return.
- Open report on an item: the brake from reports and moderation pauses deletion.
- Hold applies to one user: only that user’s data is paused; the rest follows the schedule.
- Third-party processor keeps data: state its retention separately and confirm it with the processor’s documentation.
5. Common mistakes
- Notice says “deleted immediately” while backups keep it for weeks.
- Cleanup jobs that report success when they skipped work.
- Two different jobs deleting the same data with different rules.
- Cascading deletes that remove unrelated records.
- No record that a deletion happened.
- Restoring a backup without replaying deletions.
6. How to audit
- What: the real timeline matches the documented one.
- How to check: delete a test record; check visibility, live store at day 7, backups at the stated limit.
- Evidence: dated checks.
- What: the cleanup job alarms on skip.
- How to check: make a batch fail on purpose in a test environment.
- Evidence: alert received.
- What: legal hold stops deletion.
- How to check: place a hold on a test account, delete an item, wait past the window.
- Evidence: item still present; log entries for the hold.
- What: deletions are recorded.
- How to check: read the deletion log.
- Evidence: entry with id and time, no content.
Sources
- European Data Protection Board — EDPB
- User Privacy Protection Cheat Sheet — OWASP Cheat Sheet Series
- Logging Cheat Sheet — OWASP Cheat Sheet Series
- S3: Expiring objects — AWS
- Well-Architected Reliability: back up data — AWS
- Understanding Google Play's app account deletion requirements — Google Play Console Help
- 5.1.1(v) Offering account deletion in your app — Apple Developer (App Review)