The Very Hungry Transaction
summary
A small order save grows into recurring deadlocks, lock timeouts and exhausted DB connections after inventory updates, background jobs enqueued before commit flood queues with retries, and an external fulfillment HTTP call inside the transaction stalls all database activity. Fixes shown include adding a missing index to avoid slow updates, moving external work out of transactions, swapping after_create for after_create_commit, using transaction instrumentation (Rails 7.1) and upcoming Rails 7.2 enqueue-after-commit behavior, and splitting or sequencing cross‑database work.
AI-written summary · about
chapters (12)
- 0:00Introduction to Cat’s story
- 1:04The growing transaction problem
- 3:16Adding inventory checks
- 5:01Lock contention in transactions
- 10:00Slow transactions and background jobs
- 14:13External API calls in transactions
- 18:43Database connection exhaustion
- 20:08Splitting databases for scale
- 24:23Lessons learned from the week
- 27:11Fixing the transaction incrementally
- 29:00Preventing transaction creep
- 31:33Summary and Q&A
related talks
34mThe Very Hungry Transaction
34mThe Very Hungry Transaction
33mThe Very Hungry Transaction
42mA Race To The Bottom: Database Transactions Undermining Your AppSec
41mConcurrency, Scalability and Transactions -- Myths and Surprises
29mPutting Rails in a corner: Understanding database isolation
41mTransactions: myths, surprises and opportunities
40mrails db:migrate:safely
