transactions

Retry Postgres serialization failures with bounded attempts

For workloads that run at SERIALIZABLE isolation (or that hit serialization conflicts under load), retries are part of the contract. The important part is to retry only the safe errors (typically SQLSTATE 40001) and to keep the loop bounded so you don

Postgres transaction pattern with pgx: defer rollback, commit explicitly

The most common transaction bug I see is forgetting to roll back on early returns. With pgx, I like the “defer rollback” pattern: start the transaction, defer tx.Rollback(ctx), then call tx.Commit(ctx) only on success. Rollback after a successful comm

sqlc transaction wrapper that keeps call sites clean

When using sqlc, the generated query set usually has a WithTx method. I wrap that pattern so business logic can depend on an interface and still run inside a transaction. The key is to keep transaction boundaries explicit while avoiding passing *sql.T

Transactional “Reserve Inventory” with SELECT … FOR UPDATE

Inventory systems are concurrency systems. Lock the row, verify available quantity, then write the reservation in the same transaction. It’s the simplest correct starting point.

Advanced database locking and concurrency control

Database locks ensure data consistency in concurrent access. I understand lock types—row, table, advisory. Shared locks allow concurrent reads. Exclusive locks prevent all access. Understanding lock granularity prevents contention. Deadlocks occur whe

Deadlock-Aware Retry Wrapper

Deadlocks happen under load. When the operation is safe to retry, rescue the deadlock exception and retry with jitter. Keep retries bounded and log when it happens.

Django transaction handling with atomic decorator

Database transactions ensure data integrity when multiple operations must succeed or fail together. I use @transaction.atomic on views or functions to wrap them in a transaction. For partial rollbacks, I use transaction.atomic() as a context manager a

Database transactions and ACID properties

Transactions ensure data consistency through ACID properties. Atomicity guarantees all-or-nothing execution. Consistency maintains database constraints. Isolation prevents concurrent transaction interference. Durability persists committed changes. I u

Django atomic transactions for data integrity

The atomic decorator/context manager ensures all-or-nothing database operations. I wrap related operations in @transaction.atomic or with transaction.atomic() blocks. If any operation fails, the entire transaction rolls back. This prevents partial dat

Database transactions and isolation levels

Spring's @Transactional manages database transactions declaratively. Transaction propagation controls behavior when methods call other transactional methods—REQUIRED, REQUIRESNEW, NESTED. Isolation levels prevent concurrent access issues—READUNCOMMITT

Laravel database transactions for data integrity

Database transactions ensure multiple database operations succeed or fail together, maintaining data consistency. I wrap related operations in DB::transaction() which automatically commits on success and rolls back on exceptions. For manual control, I

Row-level locking with SELECT ... FOR UPDATE in a transaction

Optimistic locking is great for most user edits, but sometimes you need strict serialization—like decrementing inventory or consuming a one-time token. In those cases I use SELECT ... FOR UPDATE inside a transaction. The lock is scoped to the transact