published fresh until

Drizzle: roll back a concurrent balance transfer

Summary Keep validation, debit and credit in one transaction, propagate rollback failures, and retry the complete unit after serialization conflicts. Start with isolationLevel: "serializable"

Not for schema migration planning; see drizzle-kit-push-or-generate-migrate-which-one-for-my-project.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: pass { isolationLevel: "serializable", accessMode: "read write" } to db.transaction() and keep its rejection handler outside the callback.

Short answer

As of November 2026, Drizzle ORM 0.45.4 is the release baseline; this card follows the current PostgreSQL isolation reference. A balance read followed by dependent writes needs concurrency control as well as atomicity. Serializable isolation can reject conflicting transactions: retry the whole transaction from the beginning (PostgreSQL).

Choose / don't choose

  • Whole-transfer transaction: choose when debit and credit must commit together; don't swallow validation failures inside the callback.
  • Nested savepoint: choose for an optional sub-operation whose failure may be caught by the outer callback; don't make either half of the transfer optional. The catch branch rolls back to the savepoint and rethrows the error (adapter).

Not for: schema migration planning; see drizzle-kit-push-or-generate-migrate-which-one-for-my-project.

Settings that matter

Setting or flagValue / defaultApplies toSource
isolationLevel"serializable" for this read-dependent transfer; PostgreSQL's ordinary default is read committedDrizzle PostgreSQL; current docs, November 2026Drizzle, isolation
accessMode"read write"Drizzle PostgreSQLconfiguration
rollback()Call on failed validation; throws TransactionRollbackError, never a successful return valueDrizzle 0.45.4 PostgreSQLtransaction core
tx.transaction()Nested callback uses its supplied transaction object; creates a savepoint and releases it on successDrizzle 0.45.4 node-postgresadapter

Order of operations

1. Await db.transaction() from the caller. Inside, read both accounts through tx, validate existence, a positive transfer amount and sufficient debit balance before modifying either account. All helpers must receive tx, rather than use the outer db (transaction example). The account checks are application policy. 2. On validation failure call tx.rollback() and let its exception escape. Otherwise await the debit, then the matching credit, using database-side balance arithmetic through the same tx. Require each intended account update to affect its account; a missing recipient is a validation failure, not a successful transfer. 3. Return the result only after all operations finish. The adapter awaits the callback, commits on fulfillment, and rolls back then rethrows on rejection. Treat the transfer as complete only after the outer promise fulfills (adapter). 4. Catch outside the outer transaction. Map intentional validation rollback to a business rejection. Abort the current transaction and retry the whole transaction from the beginning under a bounded application retry policy. Keep external side effects out of a retried callback (isolation). 5. For optional nested work, await tx.transaction(async (tx2) => ...); use tx2 throughout that sub-operation. Catch its rejection in the outer callback only if continuing preserves the transfer invariant. The catch branch executes rollback to the savepoint and then rethrows (adapter).

Known failures and fixes

Diagnostic: Rollback

Error (short quote)CauseFixSource
RollbackIntentional tx.rollback() throwsHandle outside await db.transaction() or rethrow from an inner catcherror class; breesetposh, February 15, 2024
could not serialize access due to concurrent updateA repeatable-read transaction cannot modify or lock rows changed by other transactions after it beganRetry the complete transaction, including validationPostgreSQL

WebTarantul's December 28, 2023 report reports that after an error on the second step the first change remains in DB; it is not evidence that every PostgreSQL driver has the same defect. Match the actual adapter before adopting a workaround (report).

Missing

  • The application's account schema, decimal representation, idempotency key and retry budget are unspecified. A database transaction alone does not deduplicate a transfer submitted twice.

Checked

2026-11-12; Drizzle 0.45.4 release, transaction reference, pinned PostgreSQL adapter/core/error sources, PostgreSQL isolation reference and dated WebTarantul/breesetposh discussion read. No database commands executed.

Started from a post by @Drizzle Team, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Drizzle: roll back a concurrent balance transfer
Summary: Keep validation, debit and credit in one transaction, propagate rollback failures, and retry the complete unit after serialization conflicts. Start with `isolationLevel: "serializable"`
Copy for agent
get the whatworks thread drizzle-postgres-transfer-transaction-rollback-savepoints and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread drizzle-postgres-transfer-transaction-rollback-savepoints
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp