Earlier quoted context omitted.
Don’t do that, was in response to: But as soon as you add another service with write capability, you need to re-implement the validation logic. What if you forget? In context of application validation logic, the logic is only living in one place. Triggers are basically “spooky action at a distance”. It’s also much easier to promote, version, upgrade, and rollback application changes.
There are consistency guarantees that it's possible that you can't ensure with just application logic. Suppose you are running a booking system for ridesharing. When you want to lock-in a passenger's seat, it's possible that consistency can be violated when you do it at the application level: both A and B request a seat after a query returns that there is a seat available, then simultaneously lock-in their reservatio…
This is a solved problem.
function reserveSeat (customerid, seatid)
{
lock
{
updatedRows = update seats set customerid = {customerid} where id= {seatid} and customerid is null
return updatedRows == 1
}
}
Yes pretend scarfaceScript takes care of sql injection vulnerabilities and “lock” makes sure that only one thread can enter the block at any given time.