I am facing a challenge with my Firebase Function, as it needs to update various collections that are all interrelated. I want to ensure that these updates occur in a batch write to maintain consistency - all or nothing. However, the updates are performed by different functions separately:
await update1(data) // update to firestore
await update2(data) // update to firestore and realtime
await update3(data) // update to firestore and auth
I am considering passing a reference to the batchWrite into each function and then executing batch.commit() at the end of all updates. While this approach seems feasible for Firestore writes, I am uncertain how to handle updates within the Auth and Realtime Database. One idea is to return a callback function that handles the Auth and Realtime updates upon a successful batch.commit, but what if those operations fail...
How can I structure a multi-function batch write across different databases (Firestore, Auth, Realtime) while ensuring atomicity?
Thank you for your insights.