Reputation: 21
Is there any documentation about the guarantee I have of my firebase function(s) to run for each event and in the correct order one by one?
I will explain by an example. Let say I have an event with 4 people. Each person is buying stuff for the event and insert it to the app, and the app calculates the amount each one should give the other to balance the score.
The calculation is done using Firebase function, using a trigger of "item" in the event. So if person A spent 40$, the app should charge B. C and D with 10$ to A. And if later B spent 20$, now C should give A 15$ and D give A 10$ and B 5$.
The question is, when I insert the second item, can I just calculate what was change (e.g. I know the balance score is 15$, because the current is 10' and I added 20/5) or it is possible that there was another item I may have missed and I need every time to sum all the expenses and calculate from scratch? (for example, a moment after B insert his expense to the app, C also did it, and now the function is triggered again, while I still didn't calculate B expense.)
Upvotes: 1
Views: 199
Reputation: 317322
There is no guarantee about ordering of events. That is something you'll have to figure out if it's important for your function, and deal with accordingly.
There is only an guarantee that a background function will be executed at least once, which means it could be invoked multiple times with the same event id and payload. That is the way serverless functions work.
Upvotes: 1