r/FullStack • • 16d 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!

17 Upvotes

41 comments sorted by

View all comments

1

u/AQuietMan 16d ago

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.?

Imagine your backend consists of one JavaScript program, two PHP programs, three Python programs, four Rust programs, five Go programs, etc.

One alternative is to implement business logic once in dbms stored procedures.

Another alternative is to implement the business logic at least 5 times--once in each application language--with identical behavior. *And" maintain identical behavior in the face of version rollouts, application bugs, application language bugs, bug fixes, etc.

Which alternative carries the bigger risk?

I once worked on a db2 database at a Fortune 500 company. I saw programs in two dozen languages hit that database. I'm sure there were others that I didn't have access to. The first version of some of them went to production in the 1970s.

The notion that only one program can access the database is naive. You always have at least two: the application program, and the dbms command-line interface.

1

u/tim128 15d ago

You always have at least two: the application program, and the dbms command-line interface.

Okay? Your CLI isn't tied to the schema. Do you even understand why is a bad idea to have multiple applications accessing the same db? Putting business logic in stored procedures is a horrible decision to fix the outcome of another horrible decision.

1

u/AdministrativeHost15 15d ago

Its a legacy of when servers and disk space was very expensive so the database needed to be shared as much as possible. Database developers were the senior protectors of the company's property. Application developers were just kids playing with HTML and JavaScript who couldn't be trusted to touch the data without going through a stored proc.

1

u/reyarama 15d ago

Why would you have services in multiple languages all executing the exact same business logic operation? Doesn't that break the idea of a single-writer/service-owned DB?

Would a better approach not be a single owning service implementing the logic, and other services calling the main service as a proxy?

1

u/Perkutor_Jakuard 12d ago

You can solve this scenary in one microservice exposing the API, who access a database.
And build X clients in any language.