MariaDB Why implement procedural programming inside an RDBMS (MariaDB) instead of handling all business logic in backend application code?
/r/FullStack/comments/1xrsx3f/why_implement_procedural_programming_inside_an/
10
Upvotes
View all comments
22
u/Alternative_Pin9598 17d ago •
Rule of thumb: put logic in the database when it's about data integrity or data locality. Keep it in the app when it's about workflow, integrations, or anything you change and deploy often.
Good reasons to do it in the DB (constraints, triggers, stored procedures):
orders, a constraint or trigger is the only place a rule holds for all of them. App-side checks only protect the code path that has them.SELECT ... FOR UPDATE) avoids race conditions and several network round trips.INSERT ... SELECTorUPDATE ... JOINon the server.EXECUTEon a procedure and no direct table writes, and the app account can only do the allowed operations.Reasons people move away from it:
The usual middle ground:
NOT NULL,CHECK, foreign keys, unique keys) for every rule they can express.If you do use procedures, keep them in the app's repo, deploy them through migrations, and write tests that call them.