With all this micro-services and micro business components ideology we are way ahead of questioning the right place to put our business logic.
Even though the ideology is well accepted we still have temptation and some instances where we ended up putting some decision making and business logic in database. It’s worth visiting detailed answer to why it should not be done, but at macro level I would advise thinking about one good reason why it should stay in stored-procedure and not in the application layer.
Having that counter thought process would always direct taking the right decision. Ask these questions before deciding:
- What if down the line we change our database from SQL to Mongo?
- What if want to expose API which takes the data (that database is providing) and apply this business logic on top?
- Unit testing this business logic?
- SDLC steps involved if we make change in conditions of this business logic?
- What if we need another user input for the decision making in this business logic?
- What if it requires high computation power (not data processing) and we want to be run off a separate process (or platform) ?
In all cases it would make natural choice to not put any logic (other than just data retrieval) in business logic.