Hey A’chille,

There are serveal problems here:

  1. There is not point in wrapping a direct update like that in a database transaction. It only makes sense to use a db transaction when you have more than one action (or when you want to lock the object).
  2. After you update the balance, how do you know what is the new balance? If the initial balance was 100$ and you deposited 50$, is it safe to assume the new balance is 150$? No it’s not. Another session might updated the balance in the meantime so either way you have to fetch the object again to check the current balance. If you dont need to know the new balance then there is not problem, other wise you didn’t save any queries.

Full Stack Developer, Team Leader, Independent. More from me at https://hakibenita.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store