U
U
user_of_toster2021-05-05 06:25:02
Software design
user_of_toster, 2021-05-05 06:25:02

Is database integrity due to concurrency issues the responsibility of business logic?

There is a tree of objects. In the business logic, deletion occurs as follows:
1) Find the child elements of the object
2) Delete each child object
3) Delete the object itself

The problem is that during the deletion of child objects, a new child object may appear that is not included in the array obtained in the first step . The question is, who should solve this problem? Are we smearing business logic in the database, or vice versa, database logic in business logic? There are two options:

1) After all the steps, the business logic goes through the table and looks for leaves without parents
2) The database itself resolves everything using foreign key, delete cascade, table locks

Is it a business logic concurrency issue or a database integrity issue? At what level should it be destroyed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-05-05
@user_of_toster

Business logic should not know anything at all about the database, integrity mechanisms, or concurrency. The infrastructure code must work with the base, which must exploit its mechanisms most fully and efficiently. That is, in the case of deleting a tree, as in your example, the second option is definitely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question