Databases · Flashcard
Why enforce a business invariant in the database rather than only in application code?
Why this is the answer
An invariant declared once in the schema holds for the API, the batch job, and the psql session at 2 a.m., with no coordination between teams — that reach is the argument, not raw speed. Constraint checks are not turned into index scans, changing a constraint is itself DDL, and constraints assume transactions rather than replacing them.
Read more in the docs