News for hackers. Stuff that matters.

Ask HN: Business logic in the database – your thoughts

I realise the question of whether you should store business logic in a database will never yield a definitive answer but I'm still keen to hear your opinions.

What has been your experience with putting business logic in a database? How much business logic did you place in the database and do you think it was a good choice? Thanks

( 3 comments | 4 points | on HN )
Re:Ask HN: Business logic in the database – your thoughts by connormcarthur on Monday October 29, 2018 @06:01PM (#18331950)
If you're talking about storing business logic in the database for building an MVP, e.g. using stored procedures and views in your app, then yeah, go for it. Deal with the existential risk (your business might not work) before you deal with the risk of needing to fix tech debt.

If you have the resources to avoid putting business logic in the database, in a production app context, I'd avoid it if possible. It's just another thing tying you to that database, and if you ever decide to migrate, it's another hurdle preventing you from doing that.

Re:Ask HN: Business logic in the database – your thoughts by rigged-system on Monday October 29, 2018 @05:58PM (#18331932)
Are you talking about at the schema design level or more from a stored procedure point of view?

Can you give an example of the business logic you have in mind?

Re:Ask HN: Business logic in the database – your thoughts by vanilla-almond on Monday October 29, 2018 @06:42PM (#18332308)
I was thinking in terms of what level of detail is preferred in a database. Is it merely the database schema? Is it adding constraints and data validation logic to that schema (or placing that outside in your programming language code)? Or is it also adding (stored) procedures using the database language too? I'm guessing that everyone will have a different opinion based on the projects they've worked on.