In my work we faced some issues when designing some tables' schema in Postgres, so many of my colleagues want to use triggers in some tables in order to facilitate the task of some code that should be written in the application. I'm not with the idea to use triggers a lot, but when should I use them and how they will be managed if there is any problem when designing a micro-service architecture application using Node.js services?
IMHO, there are some very limited scenarios where the use of a database trigger is valid. These include the following:
That's about it. While triggers by themselves aren't evil, most developers don't use them properly which earns them a bad rap. It's like the Git Submodules of the database world. The list of cons is much longer than the pros:
I don't know the specifics of your business use-case, but almost always, using a trigger is not a good idea. 99.9% of the use-cases can generally be covered using a good event management system and executing code based on events that are raised. This ensures that the code is doing exactly what it says it's doing, making it simpler to write, maintain & debug.