~/talk

The Very Hungry Transaction

Talkat RailsConf 2024 · 2024-05-07..05-09· [ruby-on-rails, databases]
slides:none on file

A small ActiveRecord save grows into a multi-hundred-query transaction as inventory updates, HTTP calls to a fulfillment API, and background-job enqueueing get wrapped together, causing deadlocks, lock timeouts, and eventually exhausts DB connections so the whole site stalls. Fixes are concrete: add indexes, limit items per order, move slow HTTP calls and job enqueueing out of transactions or use after_create_commit (Rails 7.2 adds defaults), prefer sequential cross-database operations to avoid non-atomic nested commits, and use tools like the isolator gem and DB performance tables to find slow transactions.

AI-written summary · about

  1. 0:00Introduction
  2. 1:06Cat and the hungry transaction
  3. 3:59Simple database transaction
  4. 6:06Inventory updates in transaction
  5. 8:15Lock contention in transactions
  6. 10:00Slow transactions cause contention
  7. 12:50Move slow work out of transactions
  8. 16:27Fix delayed job execution
  9. 17:10External calls in transactions
  10. 19:16Idle transactions exhaust connections
  11. 21:44Nested transactions across databases
  12. 24:11Nested transactions break atomicity
  13. 26:39Key lessons from Cat
  14. 29:28Fixing problematic transactions
  15. 31:58Best practices for transactions
  16. 33:24Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.