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:
|
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.
-
Retrieve the SDK keys for the environments you plan to use.
-
Initialize a separate SDK instance for each key.
-
Decide how to route requests to instances, for example by tenant, region, or environment selector.
-
Perform register, fetch, and stream setup on each instance as required by your SDK.
-
Evaluate flags using the selected instance, passing a consistent user or context object for accurate targeting.
-
Tag logs or metrics for each instance, and shut down instances you no longer need.
Recommended practices
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_enableFeaturevsstaging_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.