Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Privacy & data protectionMixed 24 series

Retention that deletes itself

Retention schedules fail in a predictable way: the policy says five years, the database says 2014, and nobody can explain the gap.

Quick reference

A rule, a job and a receipt, in that order.

  1. Rule as data — Class, trigger, clock and action in a table a job can read.
  2. Bulk by default — Partitions, prefixes and TTLs, not row-by-row loops.
  3. Bound the backups — Rotation or key destruction, stated in plain words.
  4. Keep the receipt — Counts before and after, stored with the run.

In one line: Retention ends in a delete. If nothing runs at the deadline, the policy is a wish with a version number.

Start this week:

  • Pick one dataset with an obvious clock and one owner.
  • Write the rule as a row, then write the job that reads it.
  • Store the first receipt before you extend the schedule.

Explained

A schedule needs three parts, and most teams write only the first. The rule says which data, from when, and for how long. The job actually deletes it. The receipt proves the job ran and the rows are gone. Without the job, the rule is a sentence in a wiki. Without the receipt, you cannot tell an auditor what happened.

Prefer bulk deletion to row-by-row. Drop a partition, expire an object prefix, let a TTL index do the work. Bulk operations are cheaper, easier to verify and less likely to leave orphans behind.

Backups are the real exception. An immutable archive cannot be edited per person, so bound the window instead: rotate on a known schedule, document the maximum age, and for encrypted archives destroy the key when the clock runs out. Say so plainly rather than promising surgical deletion you cannot perform.

Checklist

Run it against one dataset end to end before you write the policy for the rest.

Write

  • The rule names the class, the trigger, the clock and the action.
  • The dataset has a named owner who answers when the job fails.
  • Ambiguous cases cite the advice, not just the opinion.

Run

  • A scheduled job performs the deletion without a human step.
  • The job runs with a role scoped to the datasets in scope.
  • A failed run alerts the owner, and an empty run is investigated.

Prove

  • Counts before and after are stored with the run id.
  • A sample is checked for rows that should have gone.
  • The receipt outlives the retention window it describes.

Review

  • Backup and archive windows are stated, not implied.
  • Legal holds are recorded with a review date and an owner.
  • The next review is booked before the current one closes.

The field guide

The full guide of the PDF (P1156), page by page.

A promise with a clock (the promise)

Every retention statement is a promise about the future. It is only kept if something runs when the clock expires.

Most policies describe the rule and stop: customer records for seven years, logs for ninety days, backups for thirty-five. The rule is the easy half. The hard half is the job that finds the records, deletes them and leaves evidence that it did.

The policy saysWhat has to exist
Keep for 90 daysA job that runs on day 91
Delete on requestA path that reaches every copy
Do not keep foreverA maximum age you can measure

The gap shows up in the same place every time: a rule was agreed, a wiki page was written, and no queue, cron entry or lifecycle policy was ever created. The data is still there, now older than the promise.

Three parts, not one The rule says what and how long. The job does the deletion. The receipt proves it ran. A schedule missing any of the three is a draft, however approved it looks.

A retention rule without a job is a sentence with a date in it.

Write the rule as data (the rule)

A rule in prose cannot be executed or tested. Write it as a row an engineer can read and a job can run.

Two fields are usually missing: the trigger that starts the clock and the owner who answers when the job fails. Without the trigger, keep for a year means a year from whenever someone remembers. Without the owner, a failed run is nobody's problem.

RuleWhat runs
Session logs, 30 daysTTL index on write
Tickets, close + 24 monthsNightly delete job
Invoices, year end + 7 yearsArchive, then delete

The rule as a table

create table retention_rule (
  dataset    text primary key,
  clock      text not null,  -- event that starts the timer
  keep_days  int  not null,
  action     text not null   -- delete, archive, anonymise
);

Anonymise is not delete Overwriting identifiers can satisfy a retention rule while keeping the row for analytics. Decide which one the rule means, then test that the job does that and not the other.

A rule an engineer cannot read is a rule a job cannot run.

Delete in bulk, not by hand (the job)

Row-by-row deletion is slow, expensive and easy to leave half done. Delete by partition or prefix where the store allows it.

Partitioned tables, object prefixes and TTL indexes each give you a bulk delete that is cheap to run and easy to verify. The single-row delete still has a place for one subject's request, but it should not be the mechanism behind a schedule.

Four bulk deletes

alter table events detach partition events_2023_01;
drop table events_2023_01;
aws s3 rm s3://exports/2023/01/ --recursive
find /exports -type f -mtime +90 -delete
  • Detach the partition before you drop it, so a mistake is reversible for one step.
  • Log the row count before and after every bulk delete.
  • Run the job with a role that can delete only the datasets in scope.
  • Alert when a job deletes zero rows for two cycles in a row.

The orphan problem Deleting the parent row leaves children, attachments and search documents behind. Delete from the leaves inward, or use a cascade you have tested against a copy.

Bulk deletion is a schedule you can test, not a script you hope about.

Backups and the deletion gap (the gap)

Backups rotate on their own clock, and an immutable archive cannot be edited per person.

This is the exception most retention promises ignore. If a copy is immutable for thirty-five days, a deletion request cannot reach it; the copy disappears when the rotation does. Say that plainly, bound the window, and make sure the window is shorter than the promise.

CopyHow deletion works
Live tableDelete or anonymise in place
Object storeLifecycle expiry on the prefix
Immutable backupDestroy the key, then rotate
Offline archiveDestroy the media at end of life

Crypto-shredding, honestly Destroying the key makes an encrypted archive unreadable, but only if the key is not stored with the archive and no copy of it survives elsewhere. Test the restore path before you rely on it.

Engineering practice, not legal advice Retention clocks and legal holds are set by law and by the matter at hand. This is an engineering guide, not legal advice; confirm the clocks and the exceptions with counsel before you automate them.

Bound the window, document it, and stop promising surgery you cannot perform.

Prove that it deleted (the receipt)

The receipt is the difference between a deletion and a claim. Capture it at the moment the job runs.

  1. Record the rule, the dataset, the cutoff and the row count before the run.
  2. Run the job with a unique run id, and log the start and end times.
  3. Count again after the run, and sample for rows that should be gone.
  4. Store the receipt with the job output, not in a chat thread.
  5. Escalate a failed or empty run to the dataset owner by name.

Count, delete, count again

select count(*) from events where created_at < '2023-02-01';
delete from events where created_at < '2023-02-01';
select count(*) from events where created_at < '2023-02-01';

What an auditor asks Show the rule, the run, the count and the owner. Four artefacts answer more than a policy PDF, and they take minutes to assemble if the job wrote them down.

Keep the receipt for longer than the retention window it describes, or you will be unable to prove the deletion by the time anyone asks. A receipt that expires before the promise is a receipt you cannot use.

A deletion without a receipt is a rumour with a cron entry.

The honest caveat: retention is shaped by law and by litigation holds, and this is engineering practice, not legal advice. Confirm the clocks and the exceptions with counsel before you automate them.

Your turn: What is the oldest personal record you still hold, and why?

More notes: Privacy & data protection

Open in the notes app: search, filters, copy This note on GitHub