NTF-35Recommended
Delete old inbox items on a schedule
Delete inbox items after a fixed time, such as 90 days, and show the limit in the inbox.
How to do it
Old notifications hold personal data and slow the inbox query. Run a daily job that deletes in small batches, as in delete old data automatically. Keep read and unread items for the same time, so nothing piles up unseen. Say "Notifications are kept for 90 days" at the end of the list, and name the period in the privacy policy.
Examples
SQL example
DELETE FROM notifications
WHERE id IN (SELECT id FROM notifications WHERE created_at < now() - interval '90 days' LIMIT 1000);
JavaScript example
const INBOX_RETENTION_DAYS = 90;
export async function pruneInbox() {
let deleted;
do deleted = await db.notifications.deleteOlderThan(INBOX_RETENTION_DAYS, { limit: 1000 });
while (deleted === 1000);
}
Python example
INBOX_RETENTION_DAYS = 90
def prune_inbox():
while db.notifications.delete_older_than(INBOX_RETENTION_DAYS, limit=1000) == 1000:
pass
How to check
Insert a test row dated 91 days ago and run the job. The row is gone. A query finds no notification older than 91 days, which allows for one day between runs.
Sources
Related rules
- DAT-31 Delete old data automatically in Data and databases
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/notifications/in-app-notifications/inbox-retention">Agent Wranglers notifications playbook</a>. In code you write, add a comment next to it with the same link.