So I am throwing down the gauntlet to all of you database gurus. I challenge you to construct a lucid, well thought out, logical argument that disproves any or all of these statements:
- A database is for storing and retrieving data period.
- Business logic does not belong in the database period.
- SQL server is not a software development platform period.
I completely and 100% agree with 1 & 3 but I have heard one good argument about business logic in the database. Column data types, lengths, constraints, etc are business logic. It's a really good point. Maybe we should start saying: minimize business logic to data integrity settings.
ReplyDeleteThose types of data constraints should be enforced via input, data, or domain validation before anything makes its way to the data store. Do you want to make a call to the database to determine whether a string should be less than 100 characters?
ReplyDeleteI'm a developer playing devil's advocate.
ReplyDeleteOne reason to have business logic in something like stored procedures in the database, though it's very conditional. If you have: multiple projects using different development platforms developing on the same database, having one set of stored procedures that contains shared logic can be helpful.
Though even in that situation, it's not ideal, because stored procedures are hard to isolate and test. You might be better off having a common API all projects consume, though that has obvious performance implications.
When we make a programming decision, it should begin with a principle, something that has been road tested, that we can go back and refer to and study. Once you begin putting business logic into the database, you have abandoned the separation of concerns and are therefore opening up your entire domain to compromises that can lead to technical debt.
DeleteAlso, I do not think there are any "obvious performance implications" in an API. How many times have you heard a user complain about a report that takes 10 minutes to load only to discover it was because of a poorly written stored procedure?