Soft Deletion Probably Isn't Worth It (2022)
brandur.org
brandur.org
For postgres you could consider using a view instead. See https://evilmartians.com/chronicles/soft-deletion-with-postg...
But if it's not surfaced in UI then I agree it doesn't make much sense.
The way it was overlooked by me is because a ‘bin’ is something you clear regularly, but deleted records will likely persist forever.
That being said; I once helped out a friend who’s computer became slow to a crawl, only to find out they’d never emptied their bin so storage had only a few GB of free space left.
If space is an issue, you can have a scheduled task to really delete all "deleted" items that were last updated e.g. more than 3 months ago.
Clear regularly, but usually also has the option to undo. The article sort of suggests something similar to clearing regularly.
> So you may eventually find yourself writing a hard deletion process which looks at soft deleted records beyond a certain horizon and permanently deletes them from the database.
Another other reason to do soft-deletes up front, then hard delete later is because in some DBs (eg: OLAP), deletes can be extremely expensive. It's sometimes better to soft-delete (or invalidate references), and handle the hard-deletes in a batch-oriented manner on a regular basis.
Surprised you never got a request to undelete something. It’s such a common customer request in b2b saas.
If you don’t have high value clients I can see how it’s unnecessary I suppose.
- Last round hour
- Last round day
- Last round week
These periods can be adjusted to your/client needs. If you need something that was deleted, you restore the snapshot into a new live db and copy whatever you need. You could charge for solving "I just shot myself in the foot" support requests based on the cost of restoring those snapshots.
From my experience, this is much cleaner than having a spread of soft delete columns all over the codebase.
It seems in the vast majority of organizations I talk to, this is not how things work at all. To get a db restore on a different box you have to have at least 2 different teams involved. One to provide a machine/vm/aws instance to restore to, and another to provide the snapshot/backup.
With a soft delete all you need is the application administrator that has SQL access, which is typically far closer to the person that needs the data restored than the operations team is, hence it gets 'fixed' in a more timely fashion.
Let's compare both in either best-scenario or worst-scenario:
Snapshots on good team with no bureaucracy: Everything is automated. Even retrieval is automated via individual, commited, retrieval commands. Setup is done once and requires little maintenance, retrievals can be reused if fallen in same category (restore account, restore conversation, etc).
Snapshots on shitty team with lots of bureaucracy: Everything is manual, AWS-panel operated and only a few people have access, you have to escalate to initiate the proccess.
Soft deletes on good team with no bureaucracy: Everyones respect the soft deletion, no one queries it or do funny stuff unless for recovery purposes. The soft delete related columns, structures and tools are standardized.
Soft deletes on shitty team with lots of bureaucracy: There might be multiple, competing standards for soft delete column naming and structure. Other teams ignore the soft delete and query hidden data either knowingly (tricky hacks) or unknowingly (data team unaware of soft delete model), you can't do shit about it. When it breaks your soft deleted data, you're the one who has to fix it.
If we put external stuff in the mix (teams, people, org structures) we can spin it the way we want, but that doesn't reveal much information about the technical issue itself (having some kind of reasonable data recovery).
Soft delete is a necessity in SaaS. And then combine it with hard delete either triggered manually (empty recycle bin) or time based (after a month, etc.)
It's one of those "If you have it you will never need it but if you don't you will wish you had it"-types of things. I'm sure it's silly/stupid but it makes me feel better/safer.
I’m not versed in databases but I’d expect you can even set additional access rules to individual tables making cross referencing very hard.
You would have to have a separate database copy running for deleted entries so that it can be consistent within itself.
Again, not versed in db at all so this is likely total rubbish.
Someone breaks community rules and bullies someone or something similar, they delete their comments. What do you do now?
Business customers expect that everything they delete is possible to restore, even if the delete button clearly says, "this action is irreversible".
Law Enforcement Agencies would expect you to be able to pull data from them as well.
Some of them are:
- "Establishment, exercise or defence of legal claims"
- "Compliance with a legal obligation, the performance of a task carried out in the public interest or in the exercise of official authority."
In my B2B product, I do soft-deletes, but there is a task that cleans up deleted records older than N days at a specified interval.
A previous lifetime of mine was ensuring that when we legally were able to delete things we _really deleted them_ from _all the places they ended up including backups_ to ensure our response to subpoenas, LEOs, regulatory bodies and other busybodies was 'Unfortunately information about that customer was deleted on <date> under <legal authority>. We have no data to provide you'.
I think unless you're operating a very privacy focused business where such privacy is the selling point - there is no harm in complying.
Disagree completely - giving access to data to LEOs (or others) that you have no ongoing business use for only has downsides and has zero upsides.
I have made several submissions to judges stating the date and for what reason we destroyed records and every time the answer has been ‘well, you were legally entitled to’ and the cases were dismissed early on.
It is especially difficult in modern times to enact, but my personal view is shred fast and shred often with everything.
If there is no soft deletion or audit table available, the alternative is to either 1) Select all the source primary keys to find out which no longer exist in the source but do exist in the data warehouse 2) If there is no primary key available, select the whole dateset for full row comparison
Since in corporate settings data warehouses load at least once a day, you can imagine the amounts of data being moved around needlessly.
Most business applications contain only the actual state of data, so by loading the data warehouse these changes can be saved and analyzed.
The simplest implementation is that each record gets a start_datetime and end_datetime so you can see the changes over time or figure out when something was deleted. Other techniques like data vault enable businesses to get a complete historic view of any given point in time.
Like, some way to create a special column that makes it so every query to that table automatically has a certain filter unless you use some other keyword to override it?
Here is the syntax for Snowflake. CREATE MATERIALIZED VIEW mymv COMMENT='filtered view' AS SELECT * FROM mytable WHERE isdeleted=0;
not = NULL!!!
deleted IS NULL OR LOWER(deleted) = 'null'
I'm not sure the ideal solution in either case, but I think software should use the database primitives as they are intended, rather than building their own primitive operations on top.
In the case of delete, one idea might be for databases to natively support a recycle bin - shadow tables that contain deleted records, but I'm not a db engineer.
Instead, just nuke that row and have a copy in a separate time-based table.
https://learn.microsoft.com/en-us/sql/relational-databases/t...
Also, if you’re not careful, hard deletes can lead to primary keys getting reused, which can cause all kinds of problems if the delete doesn’t cascade into every other system. I had this happen in practice once and it was a huge pain.
Consider, if you are creating resources in something like a cloud provider, you can setup permissions to things if they are based on names or tags. If that name or tag is a UUID like thing, that means you cannot setup the permissions before the thing is created. And if it is ever accidentally deleted, you cannot restore things easily.
Sometimes a really destructive delete isn't something you want to do by default.
I have seen them abused and a lot of times queries forget to take the flag into account. Every decision is a trade-off.
What that means is if you blank out or anonymize the record you can argue you are satisfying generally accepted record keeping rules. Eg you sold a widget to a person. To satisfy GDPR you just don’t know who they are after so many years.