Skip to main content

Instantly Push Feature Flag Changes to Clients

· 2 min read
Gergely Sinka

There is a way to stream feature flag and configuration changes to the clients right when they happen. In some cases ConfigCat's pull based architecture does not completely satisfies the requirements when microservices need the latest values instantly, or mobile apps where polling sometimes is a battery consuming anti-pattern.

TL;DR

Your application subscribes to a PubNub channel to get updates about changes. And use

ConfigCat Webhooks to notify PubNub when a feature flag value gets updated.Sample application in Node.js.

push-noti

What do I need?

  • A free ConfigCat account.
  • A PubNub account (there is a free plan). If you don't have, you can keep going with a demo URL: https://ps.pndsn.com/publish/demo/demo/0/configcat-channel/myCallback/%7B%22CMD%22%3A%22FORCEUPDATE%22%7D.

Connecting your app to ConfigCat

  • Log in to ConfigCat Dashboard and create a feature flag.
  • Connect your application.
  • (Optional) You might want to poll ConfigCat for changes anyway but in a longer interval to make sure feature flag values updated even if there is an error delivering notifications.

Set up a Webhook to notify PubNub

  • Add a HTTP GET Webhook using your PubNub URL or use https://ps.pndsn.com/publish/demo/demo/0/configcat-channel/myCallback/%7B%22CMD%22%3A%22FORCEUPDATE%22%7D.

Subscribe to PubNub messages

  • Set up your app to subscribe to PubNub messages.
  • Make sure a configCatClient.forceRefresh() is called to download and update the cache with new feature flag values.
Sample application in Node.js.
// PubNub instance
var pubnub = new PubNub({
subscribeKey: pubnubSubscriberKey,
publishKey: pubnubPublishKey,
uuid: 'configCat-pubNub-sample',
});

// Subscribe to the working demo channel
pubnub.subscribe({
channels: ['configcat-channel'],
});

// Add a listener for PubNub messages
pubnub.addListener({
message: function (m) {
var msg = m.message;
console.log(msg);
if (msg.CMD == 'FORCEUPDATE') {
// Downloads the new feature flag values and updates the cache if the message is: { CMD: 'FORCEUPDATE' }
configCatClient.forceRefreshAsync().then((value) => {
console.log(
'Force update message received from PubNub. Updated cache.',
);
});
}
},
});

Testing

  • Run your application.
  • Update a feature flag value on the ConfigCat Dashboard.