Should Business Logic be on The Database?

Arnish Gupta
2 min readMay 3, 2020

When we plan for the project we always make it better. We choose the programming language, framework, and keep the things of easy debugging, no network latency, and faster execution. So, we plan the design pattern accordingly but the question is that should we have to write the business logic on the programming side or database side?

I would like to suggest to write your principals on the database level.

Photo by Jed Owen on Unsplash

Hello Everyone, I am working in a startup company. So I have to maintain many projects regularly. Some old projects are written their logics on the programming side whereas new projects are written their logics on the database level. So I found the miracle benefits when I select the database for maintain the logic. Here I am sharing my experience. Let’s learn together:

Easy For Debugging: Debugging is always be a challenge for us. We can make it easier when we write the principals on the database side. We have to use the store-procedures to write the logics.

Reduce Network Latency: Suppose we have to match the username and password then we have to update the date in the last_login column. Let’s do it with the programming side: First, we get the result with username and password condition if the result found we go for update the column. Here two times the database connection established. Wheres if we make a store procedure for this on the programming side we have to call the procedure only. We can write the update logic in the store procedure.

This was a very basic example but sometimes we have to get the data from the database and process complex logic then again save it database.

Processing Speed: Yes, it is also a point that we have to think about it. When we do data-related operations on the database level then the processing speed is much faster than the programming level logics.

Flexibility: We have the option that we can modify the logic in real-time. This flexibility is very much requires when we use Such kinds of applications like Java, Angular, etc. Because in these languages we have to change logic first on code level then compile it and upload it to the server.

Secure Your Logics: In Database, We have an option to make a new user and give permission to read and write. So we can secure it by using the user management system feature. we can permit the particular user to read it or write it.

That’s it. All the features are useful and important for the project. I hope this information is helpful to you. If you like it then clap for me.

Thank you for reading.

--

--

Arnish Gupta

Learn Blockchain with me every Monday at 9AM (GMT+5:30).