Overview
This developer guide will assist you in configuring your server-side Java platform for Feature Flags using the Mixpanel Java SDK. Feature Flags allow you to control the rollout of your features, conduct A/B testing, and manage application behavior without deploying new code.
Prerequisites
Before implementing Feature Flags, ensure:
- You are on an Enterprise subscription plan and have the appropriate version of the SDK installed (minimum supported version is
1.6.0-SNAPSHOT). If not, please follow this doc to install the SDK.
- You have your Project Token from your Mixpanel Project Settings
Flag Evaluation Modes
There are two modes available for using the Java SDK for feature flagging: Local Evaluation and Remote Evaluation.
For local evaluation, the SDK will poll Mixpanel servers for feature flag configurations. Assignment of user contexts to variants will be done locally within the SDK. This mode is recommended for low latency since there is no network call made at assignment time.
For remote evaluation, the SDK will make a network call to Mixpanel servers at assignment time. This mode is recommended for use cases where you want to leverage Mixpanel cohorts for user targeting or sticky variants for persistent variant assignments.
Local Evaluation
Targeting by Mixpanel cohorts and sticky variants are not supported in Local
Evaluation mode.
-
The SDK is configured with a
LocalFlagsConfig object that specifies parameters:
apiHost - If your project is in the EU/IN region, this should be set to route to api-eu.mixpanel.com/api-in.mixpanel.com respectively.
enablePolling - This should be set to true to enable local evaluation.
pollingIntervalSeconds - This is the interval in seconds at which the SDK will poll Mixpanel servers for feature flag configurations.
-
The SDK will continue to poll for the lifetime of the SDK instance or until stopped.
Remote Evaluation
- The SDK is configured with a
RemoteFlagsConfig object to use remote evaluation.
Configuration Options
LocalFlagsConfig Builder Options
projectToken(String) - Your Mixpanel project token (required)
apiHost(String) - API host without protocol (default: "api.mixpanel.com")
- For EU region:
"api-eu.mixpanel.com"
- For India region:
"api-in.mixpanel.com"
enablePolling(boolean) - Whether to enable automatic polling (default: true)
pollingIntervalSeconds(int) - Polling interval in seconds (default: 60)
requestTimeoutSeconds(int) - Request timeout in seconds (default: 10)
RemoteFlagsConfig Builder Options
projectToken(String) - Your Mixpanel project token (required)
apiHost(String) - API host without protocol (default: "api.mixpanel.com")
- For EU region:
"api-eu.mixpanel.com"
- For India region:
"api-in.mixpanel.com"
requestTimeoutSeconds(int) - Request timeout in seconds (default: 5)
Additional Methods
Evaluating All Flags
You can evaluate all flags at once using the getAllVariantsByFlag() method, which returns a map keyed by flag key:
Best Practices
Context Management
- Always include
distinct_id in your user context
- Include any custom properties used in your flag targeting rules
- Use consistent data types for context values across your application
Resource Management
- Initialize the
MixpanelAPI once and reuse it throughout your application
- Always call
close() when shutting down to stop polling and release resources:
- For local evaluation, remember to start polling with
startPollingForDefinitions()
- For local evaluation, you can also explicitly stop polling with
stopPollingForDefinitions():