News for hackers. Stuff that matters.
Re:Common data model mistakes made by startups by rm999 on Saturday May 22, 2021 @03:43PM (#27249685)
>Soft deletes

This section is totally wrong IMO. What is the alternative? "Hard" deleting records from a table is usually a bad idea (unless it is for legal reasons), especially if that table's primary key is a foreign key in another table - imagine deleting a user and then having no idea who made an order. Setting a deleted/inactive flag is by far the least of two evils.

>when multiplied across all the analytics queries that you’ll run, this exclusion quickly starts to become a serious drag

I disagree, modern analytics databases filter cheaply and easily. I have scaled data orgs 10-50x and never seen this become an issue. And if this is really an issue, you can remove these records in a transform layer before it hits your analytics team, e.g. in your data warehouse.

>soft deletes introduce yet another place where different users can make different assumptions

Again, you can transform these records out.

Re:Common data model mistakes made by startups by inopinatus on Saturday May 22, 2021 @07:28PM (#27251168)
Most order forms are snapshots of data at the instant of their lodgement, since they are sales contracts. It is a rookie blunder to link them relationally to master data for products and PII &c.

The record of an order is not intrinsically PII and thereby subject to rights of erasure. It may well be equally unlawful in some jurisdictions to irrevocably destroy it entire, it being necessary for accounting or tax audit, or even simply for mundane followup process, such as returns, that arise from actionable consumer rights. Ergo, such documents must fundamentally survive the erasure/redaction of any PII it does include.

Re:Common data model mistakes made by startups by jhgb on Saturday May 22, 2021 @10:06PM (#27251881)
> It is a rookie blunder to link them relationally to master data for products and PII &c.

Is it always? If that data is immutable, for example?

Re:Common data model mistakes made by startups by snowwrestler on Sunday May 23, 2021 @12:21AM (#27252433)
How are you going to satisfy data compliance, which may require the deletion of PII upon request or expiration, if your PII data is immutable?
Re:Common data model mistakes made by startups by atatatat on Sunday May 23, 2021 @02:12AM (#27252793)
Was just considering this when I came across your comment.

I'm hoping someone here can suggest a one-way audit-log audit-trail sort of solution, because I need this for the medical industry.

Re:Common data model mistakes made by startups by ranguna on Monday May 24, 2021 @02:55AM (#27261677)
I would say the structure of the records themselves can stay, but not the data itself.

If you have a user table, maybe you can just randomly hash the sensitive user data but keep the record.

Not 100% sure about this though, since you could probably derive the user with statistics like: if it's known that 1 person gets a specific disease every 10 years and you have an obfuscated record of a person connected with that disease, it's fairly straightforward to derive who that person is just through that connection.

Re:Common data model mistakes made by startups by jokull on Sunday May 23, 2021 @05:29AM (#27253620)
The way to do it is to have foreign keys, but instead of hard delete you scrub data in the columns.
Re:Common data model mistakes made by startups by snowwrestler on Sunday May 23, 2021 @10:40PM (#27260624)
Seems like if you can scrub data, it is mutable? Maybe I misunderstand what “immutable” means.
Re:Common data model mistakes made by startups by mvc on Sunday May 23, 2021 @03:32AM (#27253094)
How are you going to respond to a warranty claim if you've wrongly deleted the order data when a subject requests that you delete all PII you have about them?

https://www.adyen.com/blog/gdpr-what-it-means-for-customer-p...

Re:Common data model mistakes made by startups by snowwrestler on Sunday May 23, 2021 @10:55PM (#27260712)
You store the sales contract separately, which is what this whole subthread is about.

https://news.ycombinator.com/item?id=27251168

Re:Common data model mistakes made by startups by jhgb on Sunday May 23, 2021 @08:48AM (#27254649)
I'm not sure how this changes anything. Is your PII in the order forms/sales contracts mentioned above? If yes, you'll have to delete those as well anyway, right? If it's not, the order forms/sales contracts themselves don't have to be linked to something that may potentially get deleted.

Please note that by "immutable" I don't mean that data won't get deleted eventually, just that it won't be deleted until nothing needs it anymore (and until then won't be mutated either), so basically the same thing that languages like Haskell mean by "immutable". Then, once you don't need it (= it's not observable anymore), it could perhaps get archived or erased, whatever you prefer.

Re:Common data model mistakes made by startups by inopinatus on Sunday May 23, 2021 @09:48AM (#27254982)
Then it isn’t master data anymore; it’s just one field of a record of a commercial document. This is taking a long way around to the same point.

(Presumably no-one is trying to reference-count GC their RDBMS. If so, I wish them all the luck in the world.)

Re:Common data model mistakes made by startups by jhgb on Sunday May 23, 2021 @09:55AM (#27255030)
I'm not quite sure what "master data" means in English (a non-native language to me) but Wikipedia tells me that it's "data about the business entities that provide context for business transactions" (and lists examples that sound relevant for this situation to me). Based on that I'm inclined to think that this would qualify.
Re:Common data model mistakes made by startups by tgbugs on Saturday May 22, 2021 @03:52PM (#27249738)
Hard deletes are also awful from the perspective of data preservation. For example, when youtube removes a video they also delete all the metadata or any indication that it ever existed. Countless people have lost what they thought was a secure record of at least the title of songs or videos they saved to a playlist.

There is also a more sinister side, which is that the ability to hard delete something forever means that bad actors can fabricate old "deleted" documents and accuse someone of having created and then deleted them.

Re:Common data model mistakes made by startups by alexpetralia on Saturday May 22, 2021 @04:09PM (#27249871)
I do think that hard deletes may sometimes be required to comply with legal requirements (e.g. complete expungement of personal information relating to a user). If it is not required by statutory law, sometimes it is written into commercial contracts.
Re:Common data model mistakes made by startups by bulhi on Saturday May 22, 2021 @04:07PM (#27249864)
Exactly. I get OP's point (i.e. you can accidentally include softdeleted records in your results), but for some types of data hard deletes are an absolute no-go anyways, so you just have to live with it.
Re:Common data model mistakes made by startups by irrational on Saturday May 22, 2021 @04:16PM (#27249919)
> if that table's primary key is a foreign key in another table - imagine deleting a user and then having no idea who made an order

Assuming you have constraints set up correctly (on delete no action or on delete restrict) then how could this ever happen? If you don’t have constraints set up correctly…

Re:Common data model mistakes made by startups by vericiab on Saturday May 22, 2021 @06:49PM (#27250942)
Assuming you're deleting the row because it shouldn't be used by read queries, constraints like you described prevent the problem of having orphaned records in the child table but also prevent you from achieving your goal. On delete cascade would allow you to achieve your goal and prevent the orphaned records but could lead to deleting more than intended (especially if the child table is also a parent table referenced by further foreign key constraints, its children could in turn have children, etc). Of course, with no action/restrict you could also manually cascade the delete, but if you actually don't want to delete a child row and there's not an appropriate alternative value for its foreign key then you're in a bit of a pickle.

So if you want to delete a user but keep the records of their orders and still know who made those orders, then some form of soft delete is probably your best option. I believe that's the point rm999 was making (in response to the article asserting that soft deletes are a "data model mistake"). Properly configured constraints can prevent an "oops" but don't really do anything to solve the problem of this sort of delete from some contexts but not others.

Re:Common data model mistakes made by startups by andrewprock on Saturday May 22, 2021 @06:35PM (#27250863)
The chance that you don't have constraints set up correctly is indistinguishable from 100%.
Re:Common data model mistakes made by startups by dalyons on Sunday May 23, 2021 @04:11AM (#27253250)
Foreign key constraints are a waste of effort for most at-scale web apps. They guard against a subset of problems that aren’t actually problems (orphaned rows) at a putative cost (for the db)
Re:Common data model mistakes made by startups by irrational on Saturday May 22, 2021 @09:49PM (#27251807)
I disagree. Any fairly competent DBA will know how to setup the constraints correctly. It's not rocket science. If you can think logically enough to program, you can think logically enough to set up constraints correctly.
Re:Common data model mistakes made by startups by ako on Sunday May 23, 2021 @03:09AM (#27252998)
This should be the responsibility of the application developer creating the database schema and queries. A constraint is part of your application logic, not of the administration of the database.
Re:Common data model mistakes made by startups by yxhuvud on Sunday May 23, 2021 @03:57AM (#27253187)
I've yet to see anything I'd consider calling a startup having a DBA. I'm positively impressed if they even default to use foreign keys.
Re:Common data model mistakes made by startups by cerved on Sunday May 23, 2021 @02:11AM (#27252790)
Not everybody has a DBA :(
Re:Common data model mistakes made by startups by irrational on Sunday May 23, 2021 @01:42PM (#27256918)
Well, my team has never had an official DBA either. But we do all the tasks of a DBA. I've installed/upgraded, configured, tested backups, and hardened Oracle and Postgres more times than I can remember. We do all our own DML and DDL work. It really isn't hard to do it right.
Re:Common data model mistakes made by startups by quietbritishjim on Saturday May 22, 2021 @06:44PM (#27250919)
That would just make the data loss problem worse still. I realise OP just chose an arbitrary example, but if you really are talking about users and orders, and if you delete a user, then really deleting the records for their associated orders is even worse than losing track of who made them.
Re:Common data model mistakes made by startups by irrational on Saturday May 22, 2021 @09:46PM (#27251791)
I realize you might not be familiar with how database constraints work, but an on delete no action would totally prevent the user from being deleted. You literally cannot delete the user and their associated orders will definitely not be deleted.
Re:Common data model mistakes made by startups by stouset on Saturday May 22, 2021 @08:29PM (#27251460)
GP did not suggest ON DELETE CASCADE.
Re:Common data model mistakes made by startups by watermelon0 on Saturday May 22, 2021 @04:22PM (#27249952)
Hard deletes most likely need to be supported, due to legal or contractual obligations. Designing with this in mind, makes everything a lot easier in the long run.
Re:Common data model mistakes made by startups by rm999 on Saturday May 22, 2021 @04:29PM (#27249997)
I’ve always NULL’d values, not deleted rows. E.g. GDPR request? NULL out all identifying information, but keep the record.

As long as your primary key has no business meaning you should never have to delete the row of a table.

Re:Common data model mistakes made by startups by FigmentEngine on Saturday May 22, 2021 @05:53PM (#27250603)
INAL, but... you might want to revisit that code. article 17, right to erasure is about erasure of personal data, not about making non-indentifiable. of course they dont define erase or delete :-)

(edit: typo)

Re:Common data model mistakes made by startups by Tarq0n on Saturday May 22, 2021 @06:28PM (#27250827)
If you erase all identifying parts it stops meeting the definition of personal data. That should be sufficient.
Re:Common data model mistakes made by startups by Aperocky on Saturday May 22, 2021 @06:01PM (#27250664)
well to me the transaction is the same as deleting a record and populating a NULL record.

I don't see why the law should care in any way about a company populating NULL records.

Re:Common data model mistakes made by startups by izacus on Sunday May 23, 2021 @03:27AM (#27253069)
> I don't see why the law should care in any way about a company populating NULL records.

It cares if the existence of this record still leaks private data. This is why talking about generic "records" here is pretty wrong - actual data is not interchangeable "records" where you can just slap on a generic cargo cult policy and think you're done.

Different use-cases require different data handling. Although, I do agree, for most CRUD cases it's enough to NULL out rows.

Re:Common data model mistakes made by startups by FigmentEngine on Saturday May 22, 2021 @06:07PM (#27250703)
"NULL out all identifying information" is anonymization, not deleting the information.
Re:Common data model mistakes made by startups by duncans on Sunday May 23, 2021 @03:29AM (#27253082)
I wrote zeroes to my hard drive. Would you consider the data on my hard drive merely anonymized, or is it deleted?
Re:Common data model mistakes made by startups by ranguna on Monday May 24, 2021 @03:04AM (#27261719)
It's deleted because all connections (and meta data) has been erased.

In a database, if you null all fields but keep the entries and their inter table relationship intact, you still have identifiable data up to a certain point.

Imagine you have data of specific people and you only have one person per country, having a user and country relationship, if you null a single data of a specific user, you'll still be able to find the user just by analysing to which country that user was connected + some external information.

This is the classical problem of deriving personal data from statistical reports and why data anonymisatiom is so complex.