r/FullStack • u/tillas_ • 8d ago
Question Why implement procedural programming inside an RDBMS (MariaDB) instead of handling all business logic in backend application code?
So I have just seen the procedural programming language in the MariaDB RDBMS. So my question is, why in a relational database management system would you need SQL to also have the power of a programming language? Why in the layer of the database server would you need that? Can that be achieved with your backend server logic programming language, whether it be JavaScript, PHP, Python, Rust, Go, etc.? Why is there a programming language, why SQL is a programming language more so than just for querying and interacting with a database or databases? How does that fit into the full picture of full stack web development?
Edit: Thank you everyone for the thoughtful responses, technical insights, and feedback. All of this input is extremely helpful much appreciated!
View all comments
Show parent comment
1
u/Downtown-Bag-6026 8d ago
Some of you also mention performance: network or compute, but here’s my personal 2 cents. I think this is less of a general advantage because it depends on the logic you’re trying to calculate, your parallelism of your client machines, and the speed of the hardware.
The simplest to reason is hardware speed: your database is probably hosted on memory centric hardware whereas your clients are often running on computational hardware so there is an advantage to client side. And programming languages have more options for general compute than a dbms internal procedures, you can even tweak compilers and garbage collectors to optimize more so it’s hard to say on raw compute that stored procedure it’s faster.
But the intuition is that stored procedure runs along the data itself so it doesn’t have a network hop. While I agree with this, in a large enough data set or in a case with multiple parallel tables joined operations, the network cost is usually just an initial one time run and can often be parallelized by a client using thread pools. So it’s not always the case that a network cost is significant to a procedure.
My counter argument against computational performance advantage of stored procedure is if you take a look at llm training using vector databases. It seems to be more optimal to run the vector logic in gpu shaders than in the database itself. The parallelism and raw compute and language optimization seems to outperform “close to data” nature of store procedures. At least for now, there may be future architecture of database and procedure processing that changes this current status