The point of using a transaction is to ensure the consistency of stored data. When you make a transaction, all inserts, updates, and deletes are not immediately stored in the database, the database blocks the tables (or rows, depending on the configuration) with preliminary data until it reaches the commit command. At this point, data is written and locks are released.
If you are doing "small" transactions, then this is the same as not doing transactions at all.
If your “big” transaction is stuck, find which table causes the deadlock, and why it does. There are many reasons, including simultaneous inserts / updates / deletions in the table, locks are not released on time, previous transactions remain "alive" (ie, Do not reach the commit command), DB takes too much time to store data in the table, too much time between inserts, foreign key violation, etc.
You can read this article explaining how transactions work and how you can identify and avoid deadlocks http://flylib.com/books/en/1.142.1.79/1/
source share