0

I was executing many queries against a MySQL database with the same transaction using Promise.all(), so all queries are executing in parallel, the if anything bad happens I rollback the transaction. But a friend said that running queries in parallel is a bad practice because if a query failed and the transaction rolled back there will be other queries still running in MySQL that using the same transaction and if they didn't find the transaction they will fir errors in MySQL itself.

He sugged executing the queries in series so if something bad happens the transaction will rollback and the next query will not execute. I tried to find some proves about this issue but I couldn't find any or I missed some if exist.

Hopefully, someone can provide me with a clear answer or reference and thank in advanced.

Abdul Razzaq
  • 85
  • 2
  • 6

1 Answers1

0

Promise.all() method as described here waits for all promises to resolve and if only one of them gets rejected it will reject too. So the problems are 1. Are all of your methods passed to promise.all() returning promise or they are using callback functions? 2. Is it important that which one of those methods runs at first? because promise.all() doesn't care in what order they resolve 3. Is it important that how many methods are returning reject because promise.all() will reject at first rejection. Moreover if you are using this method for MySQL and so on, sometimes your ORM may handle that somehow but rejecting. So I personally agree with your friends as this method is hard to control but maybe find a use for it :)

PS: Hopfully other contributers will help me with other points I missed.

Shahin Shemshian
  • 356
  • 1
  • 11