Search code examples
firebasefirebase-admin

Does the Firebase Admin Node.JS SDK support exponential back off?


I'm looking to set up a simple Node.JS server which will listen for requests from an app I'm building and from it build a "send message" request to Firebase Cloud Messaging (as stated here: https://firebase.google.com/docs/cloud-messaging/send-message) so that a push notification is sent out to relevant client-side apps. In order to do this one needs to make use of the Firebase Admin SDK.

On Google's Firebase Cloud Messaging documentation under "Server Environments" (https://firebase.google.com/docs/cloud-messaging/server), it's said that running the Firebase Admin SDK requires a server environment which is able to handle requests and resend them using exponential back off. In this case I guess using exponential back off means that the "send message" request to Firebase Cloud Messaging must be retried using an exponential back off algorithm.

It's not said in the documentation however if the Node.JS Firebase Admin SDK already supports such exponential back off functionality or if I have to implement it on my own when using aspects of the Admin SDK.

According to an earlier Stack overflow post (Firebase Admin SDK Java Backoff/retry) the Java SDK does support exponential back off, but I'm not sure whether the Node.JS one does.


Solution

  • firebaser here

    The default retry configuration in the Firebase Admin Node.js SDK automatically retries up to 4 times on connection reset, timeout, and HTTP 503 errors. If the error response contains Retry-After header, the default retry config respects that, too.

    In the default config, the backOffFactor is set to 0.5. This results in the exponential retry pattern of 0s, 1s, 2s, and 4s.

    /**
     * Default retry configuration for HTTP requests. Retries up to 4 times on connection reset and timeout errors
     * as well as HTTP 503 errors. Exposed as a function to ensure that every HttpClient gets its own RetryConfig
     * instance.
     */
    export function defaultRetryConfig(): RetryConfig {
      return {
        maxRetries: 4,
        statusCodes: [503],
        ioErrorCodes: ['ECONNRESET', 'ETIMEDOUT'],
        backOffFactor: 0.5,
        maxDelayInMillis: 60 * 1000,
      };
    }
    

    Reference to code in documentation