Skip to content Skip to sidebar Skip to footer

Cloud Code Function Running Twice

I have written a cloud function that is working well. Sometimes this function is being executed more than one time for the same user (I made sure that only one request is being req

Solution 1:

As in the comments I also don't believe the client SDKs would duplicate a Cloud Function call on a bad connection. The expected behaviour would be for them to throw a network-related exception on the client side and not call it again. A problem would arise if the Cloud Function runs successfully and the client is only unable to get the result back.

I can think of the following solutions, with no more details about the Cloud Function itself:

  1. Try to make the function idempotent - Meaning that even if it runs twice the end result is the same, assuming the same input/parameters.

  2. Cache the results and manually throttle the function - This is more complicated, and is only needed if the network problem persists and you can't work around eliminating the side effects of the function. You would have to create another Class to cache the results of the function (maybe keyed by the parameters) and returning the same result with no computation and side effects.

Post a Comment for "Cloud Code Function Running Twice"