Engineering Decisions · Junior · Question 8 of 12
Moderators delete comments, and sometimes must restore one within 30 days. Regular queries should stay simple. How do you implement deletion?
- 1Move each deleted row to a separate archive table
- 2Set
deleted_at, and purge old rows on a schedule - 3Remove the row and restore it from a nightly backup
Show the answer
Correct answer: Set deleted_at, and purge old rows on a schedule
Explanation
A deleted_at column makes restoring a one-line update, and a scheduled job can purge rows after 30 days, as long as queries filter out deleted rows. Restoring from a backup fits disaster recovery, but it's slow and clumsy for one comment. An archive table fits data that is rarely restored and keeps the main table clean, at the cost of extra code for each restore.