Business Logic in Database versus Code?

senfo picture senfo · Sep 24, 2009 · Viewed 23.9k times · Source

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?

Answer

Matt Wrock picture Matt Wrock · Sep 24, 2009

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.