Skip to content

Commit

Permalink
Respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ploeh committed Jun 6, 2024
1 parent d88a1f2 commit de3f5dd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _posts/2024-06-03-youll-regret-using-natural-keys.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,26 @@ <h2 id="comments-header">
</div>
<div class="comment-date">2024-06-05 12:42 UTC</div>
</div>

<div class="comment" id="2960b65bbaec4db8ade70f551e3f5062">
<div class="comment-author"><a href="/">Mark Seemann</a> <a href="#2960b65bbaec4db8ade70f551e3f5062">#</a></div>
<div class="comment-content">
<p>
James, Nicholas, thank you for writing. I realize that there are some unstated assumptions and implied concerns that I should have made more explicit. I certainly have no problem with adding constraints and other rules to model data. For the Danish CPR number, for example, while I wouldn't make it a primary key (for the reasons outlined in the article), I'd definitely put a <code>UNIQUE</code> constraint on it.
</p>
<p>
Another unspoken context that I had in mind is that systems often exist in a wider context where ACID guarantees fall apart. I suppose it's true that if you look at a database in isolation, you may be able to update a foreign key with the help of some cascading changes rippling through the database, but if you've ever shared the old key outside of the database, you now have orphaned data.
</p>
<p>
A simple example could be sending out an email with a link that embeds the old key. If you change the key after sending out the email, but before the user clicks, the link no longer works.
</p>
<p>
That's just a simple and easy-to-explain example. The more integration (particularly system-to-system integration) you have, the worse this kind of problem becomes. I briefly discussed the CPR number example with my doctor wife, and she immediately confirmed that this is a real problem in the Danish health sector, where many independent software systems need to exchange patient data.
</p>
<p>
You can probably work around such problems in various ways, but if you had avoided using natural keys, you wouldn't have had to change the key in the first place.
</p>
</div>
<div class="comment-date">2024-06-06 6:56 UTC</div>
</div>
</div>

0 comments on commit de3f5dd

Please sign in to comment.