PRACTICAL PROGRAMMING ADVICE
Three Issues With Using Database Generated IDs
Stop letting the database be in charge of your application
You’ve probably let databases generate IDs for your entities at least once.
But, what if I told you there’s an alternative when developing applications?
I’m sure this stands in sharp contrast to what you learned in the Relational Databases 101 college course and the countless youtube tutorials you’ve watched when learning how toCREATE TABLE UsingTerribleIds ()
.
Generate your IDs at the application level. Not at the persistence level.
That’s it. You’re free to go on your merry way.
(please note that entity ID is not necessarily a database primary key)
Or, stay put if you want to know more about why database generated entity IDs may be troublesome and want to learn how I approach ID generation at client projects.
So, what’s the issue with having the database generate your entities’ IDs?
1 What’s most problematic is you’re delegating an important aspect of your domain to third party software.