← all posts
DEEP DIVE30 Jun 2026·1 min read

Drizzle transactions: where silent rollback lives

The bug: inside db.transaction, one query used db instead of tx. It ran outside the transaction — it committed on its own even when the rest rolled back. No error, no log. Just inconsistent data days later.

services/transfer.ts
undefined

The fix is trivial (use tx), but the bigger lesson was about isolation: Postgres defaults to READ COMMITTED, and for a ledger that allows read anomalies between the two legs of the entry. Financial transactions call for SERIALIZABLE — plus retry on conflict.

services/transfer.ts
undefined

A lint rule I adopted: forbid references to db inside transaction callbacks. A no-restricted-syntax rule does the job.

← back to blogBernardo Filipe · 30 Jun 2026