So, this is a classic SO discussion and debate among passionate programmers. I asked a similar, but more general question about this ...
database-level business logic
To answer the first part, I found one of the best explanations I've seen about business logic in a code database and a database:
http://www.codeproject.com/KB/architecture/DudeWheresMyBusinessLogic.aspx
The following explains why business logic is much better and more scalable. I am also in this question ... therefore, to answer your question, I will not conduct business logic in the database or stored procedures, since the main reason among many others is that SPs are not version controlled, but its pain for version control. Not to mention the fact that IDEs for SP are infinitely more primitive than IDEs for code. Both sql / tsql and similar things are not intended for a complex code structure, but for basic data manipulation and, as you will see in this article, for some very simple code structure, because previously the client-server architecture was limited.
Some exceptions to this page:
There are two levels in the client server system that force you to implement at least two levels. Previously, the server was simply considered as a remote database, and the partition was considered as an application (client) and storage (server). As a rule, all business logic remained in the client, mixed with other layers, such as the user interface.It did not take long to realize that network bandwidth could be reduced and centralized by logic to reduce the constant needs of client relocation by moving most of the business logic from the client. Since there were only two levels, the only place to move the business logic was the server. A server in architecture was a good place in a client server system, but a database as a platform was a poor choice. Databases were designed for storage and retrieval, and their extensibility was designed for such needs. Database stored procedure languages ββwere developed for basic data conversion in addition to what could not be done in SQL. Stored procedure languages ββwere designed to be executed very quickly, and not for complex business logic.
But this was the best of two options, so the business logic was moved to stored procedures. In fact, I would say that business logic was charred (hacked, adapted) to stored procedures as pragmatism. In a two-tier world, this was not perfect, but improved.
The business layer must contain all business rules.This design has the following advantages: - All business logic exists in one place and can be easily checked, debugged and changed. - A true development language can be used to implement business rules. Such a language is more flexible and more suitable for such business rules, rather than SQL and stored procedures. - The database becomes a storage tier and can focus on efficiently retrieving and storing data without any restrictions related to the implementation of business logic or presentation tier.
So now, in terms of architecture, I would have each user icon updated by calling a stored procedure when the related question / answer or something else is updated. You put this in the business logic of a question or answer, as I assume that it will be different for different types of elements (when they change). Since this is an event-based action, the action will only occur when the event occurs. If you have a service or scheduled tasks, it will work all the time and, although it will be minimal, it will ultimately lead to a system crash when you have many users.
If you do not want each userβs events to run checks and updates in the gazillion, you can upload them to the table and complete the scheduled task for updating the icons.
So that the system can update the entire user base based on the new business logic, you can cover all your actions in a Windows task or a one-time task, and this will work better than tsql, IMHO and will be much more important and flexible.
However, sometimes duplication of VERY small business logic may come in handy for some performance improvement. But, as you see in the article, the business layer in the code is much more scalable, so it can be controversial.
Hope this is useful information for you to decide what you need ...