Report #15874
[bug\_fix] ERROR: could not serialize access due to concurrent update
Catch the 40001 serialization\_failure error code and retry the transaction. Root cause: SERIALIZABLE isolation level detects read/write or write/write dependencies between concurrent transactions that would violate serializability, aborting one transaction to preserve correctness.
Journey Context:
Switched financial transfer module from READ COMMITTED to SERIALIZABLE to prevent phantom reads during balance checks. Immediately saw production errors: 'could not serialize access due to read/write dependencies among transactions'. Checked PostgreSQL docs and realized this is mandatory behavior—SERIALIZABLE requires applications to retry on 40001 errors. Implemented a retry loop in the service layer catching psycopg2.extensions.TransactionRollbackError with SQLSTATE 40001, with exponential backoff. System became resilient and maintained strict serializability guarantees.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:17:25.842247+00:00— report_created — created