title: Firebase: Update multiple objects in single transaction
body: <p>I have found some thread below which talk about this scenario.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/17437695/firebase-how-do-i-update-multiple-resources-atomically">Firebase: How do I update multiple resources atomically</a></li>
  <li><a href="https://stackoverflow.com/questions/29947898/firebase-data-consistency-across-multiple-nodes">Firebase data consistency across multiple nodes</a></li>
  <li><a href="https://stackoverflow.com/questions/29867328/how-to-store-users-and-groups-for-a-chat-using-firebase/29870768#29870768">How to store users and groups for a chat using Firebase</a></li>
  </ul>
  
  <p>However still struggling to find, if there are any recommended data structure design for this. 
  I see a Multi-write library <a href="https://github.com/katowulf/firebase-multi-write" rel="nofollow noreferrer">firebase-multi-write</a> which says you probably don't need this in most cases.</p>
  
  <p>But I think I do need this, my scenario is : 3 users</p>
  
  <pre><code>/users/A : {credit:20}
  
  /users/B : {credit:3}
  
  /users/C :  {credit:10}
  </code></pre>
  
  <p>And each user can steal credits from each other <strong>all at the same time</strong>., </p>
  
  <ul>
  <li>A steals from B credits look like {21, 2}</li>
  <li>B steals from C credits look like {3, 9}</li>
  <li>C steals from A  credits look like {11, 20}</li>
  </ul>
  
  <p>Now I need to update the credits for each user to maintain this consistency, so that each steal operation is atomic in nature.</p>
  
  <p>What will be the best way to handle such scenario, while maintaining data integrity in <strong>Java</strong>?</p>