Reputation: 1558
I have a project where i need to Write a Data along with an image i.e to both Cloud Storage
and Firestore Database
, there is no batch write to both Cloud Storage and Cloud Firestore combined, so the only solution is to do one after the other i.e write one thing to database and when it is successful then write the next.
Problem is when writing the first data is succesfull and second data is a failure, then i have to revert the transaction, i think doing this from client side is not good there can be loss of internet connection.
So my question is should i use Cloud Functions for everything i write to database or not ?.
Upvotes: 3
Views: 273
Reputation: 599081
Cloud Functions are essentially small Node scripts that use the Admin SDK to access Firebase. They have no special powers beyond the API, which means they have the same limitations as using that API in other places.
Using a Cloud Function will reduce the chances of having an interruption between the related operations, but it does not eliminate that chance.
This means that you'll have to deal with the interruptions in some way. Typically this is a two-step process:
I'll admit that the second step is often something I add later. The first step already ensures the apps run fine anyway, so the cleanup is just some data storage optimization at that point.
Upvotes: 1