Propagate Remote Config updates in real time

Using the Remote Config background function triggering provided by Cloud Functions for Firebase along with FCM, you can propagate Remote Config updates in real time. In this scenario, you create a function that triggers when you publish or roll back your Remote Config template from the dashboard or the API. The template update triggers the function to send an FCM message to let clients know that their existing config is stale and that their next fetch should be from the server:

The rest of this document walks you through these steps to propagate Remote Config updates in real time.

Subscribe client app instances to an FCM topic

For targeting an FCM message to a large group of client app instances such as your entire user base, topic messaging is the most effecient mechanism. Each app instance that should receive realtime Remote Config updates must subscribe to a topic name like, for example, PUSH_RC:

public void onNewToken(String s) {

Create a function to send an FCM ping on template updates

You can trigger a function in response to Remote Config events, including the publication of a new config version or the rollback to an older version. To propagate template updates in real time, create a function that listens for template publication events, and then use the FCM Admin SDK from your function to send a silent ping to client app instances:

exports.pushConfig = functions.remoteConfig.onUpdate(versionMetadata => {
  // Create FCM payload to send data message to PUSH_RC topic.
  const payload = {
    topic: "PUSH_RC",
    data: {
  // Use the Admin SDK to send the ping via FCM.
  return admin.messaging().send(payload).then(resp => {
    return null;

This function sets a CONFIG_STATE parameter, and then sends that as the data payload of an FCM message to all clients subscribed to the PUSH_RC topic.

Set the Remote Config state on the client

The data payload shown in the previous step always sets CONFIG_STATE to STALE in the app's shared preferences. This indicates that the Remote Config template already stored on the app is now stale due the creation of the new, updated template whose publication triggered the function. Update your notification handler to test for this condition:

public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().containsKey("CONFIG_STATE")) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        sharedPreferences.edit().putBoolean("CONFIG_STALE", true).apply();

Fetch the Remote Config updates on app startup

private void fetchWelcomeMessage() {

    long cacheExpiration = 43200; // 12 hours in seconds.
    // If your app is using developer mode or cache is stale, cacheExpiration is set to 0,
    // so each fetch will retrieve values from the service.
    if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled() ||
            mSharedPreferences.getBoolean("CONFIG_STALE", false)) {
        cacheExpiration = 0;

            .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Toast.makeText(MainActivity.this, "Fetch Succeeded",

                        // After config data is successfully fetched, it must be activated before newly fetched
                        // values are returned.
                    } else {
                        Toast.makeText(MainActivity.this, "Fetch Failed",

Finally, add logic to your app to force the Remote Config fetch from the network (ignoring the cache) because CONFIG_STATE is STALE. If your app fetches from the network too frequently, it may be throttled by Firebase. See Caching and throttling.

Send feedback about...

Need help? Visit our support page.