Skip to content Skip to sidebar Skip to footer

Firebase Firestore And Cloud Storage: Deleting Both A Db Entry And Its Associated File Can Result In One Being Actually Deleted, The Other Not

Is it possible to be sure that if my Android app's user wants to delete a Firestore DB document AND the associated file stored in Cloud Storage (identified by the DB document's ID)

Solution 1:

Is it possible to be sure that if my Android app's user wants to delete a Firestore DB document AND the associated file stored in Cloud Storage (identified by the DB document's ID), then actually both of them will be deleted?

If you think that you can add to a batch operation a Firestore delete operation and a Firebase Storage delete operation and be sure that both happen in the same, please note that this is not possible. These operations are apart of different Firebase services and there is no way you can make them atomic.

Unfortunately, none of the Firebase products support cross-product transactional operations. To solve this, you'll have to nest the calls during your delete operations, meaning that if you get an error that occurs when you delete a record from FireStore, then you have to delete the corresponding image from Firebase Storage. But at some point in time, there will be a failure that the client can't rollback. The most common approach for these inevitable failures that might happen, is to make your code robust by handling exceptions and perform occasional cleanups in both places, Firestore, and Firebase Storage.

Post a Comment for "Firebase Firestore And Cloud Storage: Deleting Both A Db Entry And Its Associated File Can Result In One Being Actually Deleted, The Other Not"