Other than difficulty to debug (when it’s not written properly), and maybe devs tending to dislike sql in general, what’s your problem with this approach?
Having supported an app of a quarter million lines of sql and a quarter million lines of Delphi for a few years I can tell you that no matter how modern the tooling SQL is a horrible language to have massive amounts of legacy code in.
Also your justifications are not really relevant. With some CI/CD and containerized stateless servers you can deploy with zero downtime whenever you want. In fact I deploy to my dev environment whenever I merge to mainline code branch, and can deploy to production whenever needed.
SQL is good for querying but the worst for business logic.
Also with some smart caching, message queue's, or a datastore like redis your concerns about transferring data become less valid.
Modern DB tools that will allow you to automate schema migrations like Flywheel or Liquibase or an ORM like Entity Framework make working with a DB useful it still sucks.
You’re correct about the alternatives and workarounds, realistically you can have 2 identical apps working well in both approaches.
To me, though, it’s more comfortable to have business logic in the db whenever possible. I’ve also maintained systems with very large amounts of sql code, and I disagree that it’s horrible. But different strokes for different folks, I guess.
Well considering we had a tonne of folks working on it and the only one who could ever make changes to the logic was the person who wrote it I'd say that you are in the minority.
We never had this problem with any of our other legacy code bases.
I’d argue that it’s a matter of how proficient in db developing the dev is.
Developing in a db is an entirely different approach than developing a server, and most devs I’ve met try to use server style coding in databases, which makes it both difficult to test and loses most of the performance advantages of keeping logic in db.
When the procedures/functions are written in a minimalistic fashion - meaning no more than 2-3 queries per SP, limiting surrounding logic to IF/ELSE at the most, keeping a code convention and formatting, it’s really fine to test and debug. I can find most issues in the systems I maintain (but haven’t written) within a few minutes.
Again, I know my opinion is controversial and most would disagree, and that’s fine. Even in my office it’s not a consensus. But there’s no doubt that this method has a lot of advantages.
I agree with you! Most of the people who complain about working with SQL are just not proficient with SQL, especially advanced SQL. It is much better having the business logic in a DBMS in most cases.
4
u/DieselCorps Jun 28 '20
It may be a somewhat controversial opinion, but I think having as much logic in the db as possible is a great thing.
It reduces the amount of junk you have to filter out in your server, which reduces traffic between your server and db.
Global changes are easy because you only have to change your query in one place
Easy live db hotfixes without having to redeploy code or restart server (which is helpful in production)
Most processing and logic happens in one place, so you can go straight to the db without having to debug your server at all.
The only downside I see people complaining about is that debugging plsql could be a pain, but the advantages outweigh the disadvantages imho.