Soft Delete
Marking a record as deleted instead of removing it, which makes deletion reversible and auditable but leaks complexity into every query.
A soft delete marks a record as deleted, usually with a deleted_at timestamp or an is_deleted flag, instead of removing it from the database. Queries then filter out the marked rows, so the record disappears from the application while staying in storage. A hard delete removes the row for good.
The appeal is easy to see:
- Undo. Accidentally deleted data can be restored by clearing the flag. A trash folder with a 30-day recovery window is soft deletion with a scheduled hard delete at the end.
- History and audit. Records of what existed, and when it was deleted, stay available for support, reporting, and disputes.
- Referential safety. Orders that reference a deleted product still have something to point to.
The costs arrive later and spread everywhere:
- Every query must remember the filter. One forgotten
WHERE deleted_at IS NULLin a report, a join, or a background job, and deleted records reappear. ORMs offer default scopes to apply the filter automatically, which then surprise anyone who needs to see deleted rows. - Unique constraints break. A user deletes their account and tries to sign up again with the same email, and the soft-deleted row still holds it. Workarounds include partial indexes that cover only live rows.
- Tables and indexes grow with rows nobody reads, slowing queries that must skip them, as every database index carries the dead entries too.
- Deletion stops meaning deletion. Privacy laws give people the right to have their data erased. A soft delete that keeps personal data indefinitely does not satisfy that, so real systems need a hard delete path regardless.
Alternatives often fit better. Moving deleted rows to a separate archive table keeps live tables clean. Event Sourcing records deletion as an event, keeping history without a flag on current state. Some systems simply hard delete and rely on backups, or on Change Data Capture streams, for recovery.
Distributed systems use a related idea under the name tombstone: a marker that records a deletion so replicas learn about it, since simply removing data would look like data that was never received. Conflict-Free Replicated Data Type designs and Database Replication depend on tombstones, which in turn need garbage collection.
See also2
Audit Log
An append-only record of who did what, to what, and when, kept to answer questions of accountability long after the fact, and built so that even its administrators can't quietly rewrite it.
Data & Content9 connections
Null
The special marker for a missing or unknown value, whose three-valued logic in SQL and whose null references in programming languages cause a long tail of surprising bugs.
Data & Content8 connections
Linked from9
- Audit LogData & Content
An append-only record of who did what, to what, and when, kept to answer questions of accountability long after the fact, and built so that even its administrators can't quietly rewrite it.
- Conflict-Free Replicated Data TypeNetworks & Distribution
A data structure whose replicas can be edited independently and always converge without coordination.
- Draft and PublishedData & Content
Keeping an in-progress version of content separate from the live one, with all the state that implies.
- Event SourcingData & Content
Storing every change that ever happened, instead of only the current state, so the current state becomes a derived view.
- Foreign KeyData & Content
A column that points at a row in another table, with the database refusing any change that would leave the pointer dangling.
- ImmutabilityComputation & Algorithms
A value that cannot change after construction, so sharing it never risks a caller seeing another caller's edit.
- NullData & Content
The special marker for a missing or unknown value, whose three-valued logic in SQL and whose null references in programming languages cause a long tail of surprising bugs.
- Personal DataData & Content
Any information that relates to an identifiable person, why it is broader than names and emails, and the engineering habits that privacy law now expects.
- UndoDesign & Interface
Letting people reverse what they just did, which makes interfaces safe to explore and usually beats asking "are you sure?" before every action.