How do I keep data correct (ACID, constraints, concurrency)?
Make invariants executable in the database, not just in the UI:
- UNIQUE, FOREIGN KEY, CHECK and NOT NULL constraints, clear transaction boundaries and audit fields
- Transactions for steps that must change together; pick isolation levels deliberately and test lost updates, write skew and concurrent approvals
- Optimistic concurrency (version columns) for ordinary edits; locks or serialised commands when correctness demands it
- Idempotency and uniqueness enforced server-side — a disabled button is not protection against double submit
- An authoritative ledger for money or payroll; recompute derived totals deterministically
- Connection pooling, query timeouts, EXPLAIN-based tuning and recorded migration history
ACID example (booking or payroll approval): *Atomicity* — reserve stock and create the booking together; *Consistency* — a unit can't be reserved twice, an overtime segment can't be paid twice; *Isolation* — two requests must not both see the last unit as free; *Durability* — a committed record survives failure.