Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Business Logic in Database versus Code? [closed]

As a software engineer, I have a strong bias towards writing business logic in the application layer, while typically relying on the database for little more than CRUD (Create Retrieve Update and Delete) operations. On the other hand, I have run across applications (typically older ones) where a large amount of the business logic was written in stored procedures, so there are people out there that prefer to write business logic in the database layer.

For the people that have and/or enjoy written/writing business logic in a stored procedure, what were/are your reasons for using this method?

like image 986
senfo Avatar asked Sep 24 '09 19:09

senfo


People also ask

What is database business logic?

Business logic is the custom rules or algorithms that handle the exchange of information between a database and user interface. Business logic is essentially the part of a computer program that contains the information (in the form of business rules) that defines or constrains how a business operates.

Is SQL a good place for business logic?

SQL is the language optimized for operating sets of data. It isn't flexible enough and we can't rely on it to express any more or less complex domain model because it lacks the ability to create proper abstractions. And that is the single most important reason why we shouldn't use it as a place for business logic.

What is data logic and business logic?

The presentation logic manages the interaction with the user, the data logic handles data persistence while business logic handles the “stuff” that happens between the two. It can be difficult to precisely define what this “stuff” really means.

Should business logic be in front end or back end?

The very definition of the terms "front end" and "back end" comes from the separation of business logic (back end) from the user interface (front end). So yes, business logic should be in the back-end, whether that is a remote service or simply a different layer in the same application.


1 Answers

I try to seriously limit my business logic in the DB to only procs that have to do alot of querying and updating to perform a single application operation. Some may argue that even that should be in the app, but I like to keep the IO down if I can.

Databases are great for CRUD but if they get bloated with logic:

  1. It becomes confusing where the logic is,
  2. Typically databases are a silo and do not scale horizontally nearly as well as the app servers.
  3. t_sql/PLsql is hard to read and procedural in nature
  4. You forfeit all of the benefits of OOAD.
like image 93
Matt Wrock Avatar answered Oct 02 '22 14:10

Matt Wrock