Reputation: 528
Apparently some of onCreate/onDelete events our cloud function is triggered by are received more than once! We've observed them arriving even 3 times a few seconds apart from each other spread between instances of the cloud function. Is it a normal behavior or there is something we've been doing wrong?
Upvotes: 0
Views: 69
Reputation: 83048
Have a look at the content of this "Firebase Google Group" post, that I paste below. It was written in August 2018 but is still fully valid at the time of writing this "copy/paste answer".
Cloud Functions typically guarantees that your functions are run "at least once", meaning that it's very possible (but typically rare) that an event may get delivered to your function more than once. To deal with this, your functions should be "idempotent", meaning that the receipt of the same event multiple times should result in no further changes to whatever it is you need to update. This can be kind of challenging, but it's one of the properties of serverless systems that needs to be dealt with, if it's problematic for your app.
https://cloud.google.com/functions/docs/bestpractices/tips#write_idempotent_functions
Upvotes: 1