magic starSummarize by Aili

Why soft deletes are evil and what to do instead – James Halsall

🌈 Abstract

The article discusses the pros and cons of using soft deletes versus hard deletes in database management, and proposes an alternative approach using audit logs.

🙋 Q&A

[01] Soft Deletes vs. Hard Deletes

1. Questions related to the content of the section?

  • The article discusses the tradeoffs between using soft deletes (where records are marked as deleted but not physically removed) versus hard deletes (where records are permanently removed):
    • Soft deletes provide a "safe" and easily reversible way of deleting records, but can create more problems than they solve.
    • Hard deletes remove the records completely, but make it impossible to recover deleted data.
  • The article argues that soft deletes prevent the database from properly managing relationships between data, and shift that responsibility to the application layer, which is not designed for it.

[02] Cascading Deletes

1. Questions related to the content of the section?

  • The article presents a contrived example where a Group object has many User objects associated with it.
  • When deleting a Group object, the article discusses the challenges of ensuring that all associated User objects are also deleted, either through:
    • Hard deletes, which would remove the group and all associated users, but make recovery impossible.
    • Soft deletes, which would leave the associated users intact, requiring additional application logic to handle the cascading delete.

[03] Audit Logs as an Alternative

1. Questions related to the content of the section?

  • The article proposes using audit logs as an alternative to soft deletes, where:
    • The database performs hard deletes, removing records permanently.
    • An audit log is maintained, which stores a serialized copy of the deleted entities, along with metadata like the user who performed the deletion and the timestamp.
  • This approach allows for accountability and the ability to recover deleted data, while keeping the database responsible for the actual deletion process.
Shared by Daniel Chen ·
© 2024 NewMotor Inc.