We are excited to announce the release of the OpenFeature “Multi-Provider” for JavaScript and NodeJS. This new provider allows developers to access multiple OpenFeature providers through a unified interface, with customizable strategies that reconcile inconsistencies between providers. The Multi-Provider supports use cases including provider migrations and long-term support for multiple feature flag sources. It is currently available for the Javascript OpenFeature SDKs @openfeature/server-sdk and @openfeature/web-sdk.

How It Works

const multiProvider = new MultiProvider(
	[
		{
			provider: new ProviderA(),
		},
		{
			provider: new ProviderB()
		}
	]
)
await OpenFeature.setProviderAndWait(multiProvider)

openFeatureClient = OpenFeature.getClient()
const value = await openFeatureClient.getStringValue(
	'flag-key', 
	'default value', 
	someUser
)

The Multi-Provider behaves like any other provider, but under the hood it combines results from any number of providers. It takes a list of providers as its only required parameter, then evaluates flags by progressing through the list of providers in order. By default, it will only evaluate the next provider if the current one indicates the flag was not found. Once there is a flag match, the Multi-Provider will return that result and not evaluate with the remaining providers.

Strategies

In order to support diverse use cases, the Multi-Provider also accepts a Strategy parameter, which can be customized to control which providers are evaluated and how the final result is determined.

const multiProvider = new MultiProvider(
	[
		{
			provider: new ProviderA(),
		},
		{
			provider: new ProviderB()
		}
	],
	new SomeStrategy()
)

FirstMatchStrategy

The default Strategy is the FirstMatchStrategy. This will evaluate providers in order, moving on to the next provider only if the current provider returns a FLAG_NOT_FOUND result. If an error is thrown by any provider, the Multi-Provider will throw that error. The OpenFeature SDK will then catch the error and return the default value.

This strategy is useful for migrating from one provider to another, when some flags have been ported to the new system while others remain in the old one. By putting the new provider first in the provider's list, the Multi-Provider will prefer results from the new system but keep the old as a fallback.

FirstMatchStrategy can also be used to pull feature flags from multiple sources, and return as soon as the flag is found.

FirstSuccessfulStrategy

FirstSuccessfulStrategy is similar to FirstMatchStrategy, except that errors from evaluated providers do not halt execution. Instead, it will return the first successful result from a provider. If no provider successfully responds, it will throw an error result.

One use case for this strategy is if you want the Multi-Provider to fallback to another provider in the case of an error, rather than throwing an error itself. For example, if an external vendor provider goes down, you may want to automatically fall back to a config file.