You almost understood everything. However, there is one significant difference between after_commit and after_create or after_save i.e.
In the case of after_create this will always be before calling the save (or create) return.
Rails wraps each saved transaction, and before / after callbacks are triggered in this transaction (this is due to the fact that if an exception is raised in post_create, the saving will be canceled). With after_commit your code does not run until the most external transaction has been completed. These can be created transaction rails or created by you (for example, if you want to make several changes within one transaction). Originally posted here
It also means that if after_commit throws an exception, the transaction will not be after_commit .
Dusht
source share