If an after_commit is called inside of a transaction and that transaction has calls to model methods that can trigger model callbacks, the block passed to after_commit will be called multiple times. For example,
ActiveRecord::Base.transaction do
User.create!(email:)
ev = Event.create!(name: 'created user', source: 'admin')
after_commit do
send_welcome_email!
end
track_event!(ev)
end
When this transaction runs, the welcome e-mail will be sent multiple times because the block is run repeatedly.