Configure multiple SDK keys

2 minute read

Initialize and run multiple SDK instances in one application, each bound to a different SDK key and environment. For an explanation of when and why to use this approach, refer to Understanding multiple SDK keys.

Before you begin, ensure the following:

  • SDK v6.x or later for your platform.

  • One SDK key per application-environment you plan to use.

  • The flags you plan to evaluate exist in each application and environment being queried.

  • Network access to CloudBees Unify endpoints from your runtime.

Set up multiple SDK keys

The following steps are SDK-agnostic. For language-specific code examples, refer to the SDK references listed in the related pages section.

  1. Retrieve the SDK keys for the environments you plan to use.

  2. Initialize a separate SDK instance for each key.

  3. Decide how to route requests to instances, for example by tenant, region, or environment selector.

  4. Perform register, fetch, and stream setup on each instance as required by your SDK.

  5. Evaluate flags using the selected instance, passing a consistent user or context object for accurate targeting.

  6. Tag logs or metrics for each instance, and shut down instances you no longer need.

Apply these practices to maintain clear isolation between instances, consistent evaluations, and reliable operations.

Instance management

Store instance references for reuse. Use consistent naming conventions for SDK keys.

Flag naming

Use prefixes to distinguish flags from different configurations. For example: prod_enableFeature vs staging_enableFeature.

Custom properties

Set custom properties on the specific instance. Avoid using static custom property methods with multiple SDK keys.

Error handling

Set up configuration fetched handlers for each instance. Monitor for network errors per instance.

Troubleshoot

Use the following to diagnose and resolve common issues with multiple SDK keys.

Wrong environment evaluated

Ensure you select the intended SDK instance before evaluation.

No updates applied

Confirm that register, fetch, or streaming is configured for that specific instance.

Callbacks not firing

Attach listeners to the same instance that performs fetch or streaming.

Unexpected differences

Compare flag definitions, targeting rules, and salts across environments.

High network activity

Reduce the number of active instances or adjust polling or stream settings.