Hacker News new | ask | show | jobs
by Supermancho 2102 days ago
> Nothing controversial

ahem

> Foreign Key constraint is the king of the relational database design

Amazon does not use FK constraints and I have rarely run into systems that do (since 1996ish). Most people with big enough datasets learn not to use them. The overhead for orphaned data is far less than the consequences of using them.

2 comments

Ah. Fair enough, yes, I agree. That statement goes a little too far, and is a bit at odds with the otherwise overall light tone of the article and the YMMV-ish disclaimer at the end.
Can you clarify about the overhead you're speaking of?

I assume it only comes into play at super massive scale like Amazon-level datasets.

Not even super massive like amazon, even an app for a few million users you’ll run into the performance problems of FKs. They are really overrated in their usefulness - as parent says, orphan records are really not a big deal. As soon as you get to any moderate scale, dealing with a small level of data inconsistencies is inevitable. Especially as you grow into a multiple services, multiple databases type architecture where you fundamentally have to handle breaking fks btw systems
When not using FK constraints, data may be modified or lost (deleted) without proper cleanup of related records leading to "orphaned" records without relationships (or related ids that do not correspond to existing records). The disk space for these orphaned records and the time to run a relational integrity checks across tables (removing orphans), is of minor concern and effort, comparative to a troublesome database entry with FK constraints.