Run a multi-armed bandit optimization
How to run a multi-armed bandit optimization in Optimizely Feature Experimentation.
A multi-armed bandit (MAB) optimization is a different type of experiment, compared to an A/B test, because it uses reinforcement learning to allocate traffic to variations that perform well while allocating less traffic to underperforming variations.
️Important
MAB optimizations do not generate statistical significance. Instead, the algorithm pushes traffic to variations with the most conversions; the reason for a variation's performance is unimportant.
See Run a multi-armed bandit optimization in Feature Experimentation in the user documentation for additional information and use cases.
Configuration overview
To configure a MAB, complete the following:
-
(Prerequisite) Create a flag in your Feature Experimentation project.
-
(Prerequisite) Handle user IDs.
Note
You should configure a user profile service to ensure consistent user bucketing if you are using a server-side SDK.
- Create and configure a MAB rule.
- If you have not done so yet, implement the Optimizely Feature Experimentation SDK's Decide method in your application's codebase through a flag.
- Test your MAB rule in a development environment. See Test and troubleshoot.
- Discard any test user events and enable your MAB optimization rule in a production environment.
Configure an MAB optimization in your Feature Experimentation project
With the Feature Experimentation UI
To create an optimization in the Optimizely app, see Create an MAB optimization in your Feature Experimentation project section in the user documentation.
With the REST API
Use the Update the Ruleset for a Flag in an Environment endpoint to add a new rule with type
set to multi_armed_bandit
.
Run the MAB rule
Start your new MAB rule and flag (if it is not already running).
With the Feature Experimentation UI
See Run a multi-armed bandit optimization in Feature Experimentation in the user documentation.
With the REST API
First, enable the flag by using the Enable the Ruleset for a Flag in an Environment endpoint. Then, launch your MAB by enabling the rule by using the Update the Ruleset for a Flag in an Environment endpoint and setting the enabled
path to true
.
Implement the MAB
If you have already implemented the flag in your application's codebase, no further configuration is required for the flag delivery. If you have not, implement the Decide method call in your code to enable or disable the flag for a user:
// Decide if user sees a feature flag variation
let user = optimizely.createUserContext(userId: "user123", attributes: ["logged_in":true])
let decision = user.decide(key: "flag_1")
let enabled = decision.enabled
// Decide if user sees a feature flag variation
user := optimizely.CreateUserContext("user123", map[string]interface{}{"logged_in": true})
decision := user.Decide("flag_1", nil)
enabled := decision.Enabled
# Decide if user sees a feature flag variation
user = optimizely.create_user_context("user123", {'logged_in': True})
decision = user.decide("flag_1")
enabled = decision.enabled
// Decide if user sees a feature flag variation
$user = $optimizely_client->createUserContext('user123', ['logged_in' => true]);
$decision = $user->decide('flag_1');
$enabled = $decision->getEnabled();
# Decide if user sees a feature flag variation
user = optimizely_client.create_user_context('user123', {'logged_in' => true})
decision = user.decide('flag_1')
enabled = decision.enabled
// Decide if user sees a feature flag variation
var user = optimizely.CreateUserContext("user123", new UserAttributes { { "logged_in", true } });
var decision = user.Decide("flag_1");
var enabled = decision.Enabled;
// Decide if user sees a feature flag variation
OptimizelyUserContext user = optimizely.createUserContext("user123", new HashMap<String, Object>() { { put("logged_in", true); } });
OptimizelyDecision decision = user.decide("flag_1");
Boolean enabled = decision.getEnabled();
// Decide if user sees a feature flag variation
const user = optimizely.createUserContext('user123', { logged_in: true });
const decision = user.decide('flag_1');
const enabled = decision.enabled;
// Decide if user sees a feature flag variation
const decision = useDecision('flag_1', null, { overrideUserAttributes: { logged_in: true }});
const enabled = decision.enabled;
// Decide if user sees a feature flag variation
var user = await flutterSDK.createUserContext(userId: "user123");
var decisionResponse = await user!.decide("flag_1");
var decision = decisionResponse.decision;
var enabled = decision!.enabled;
See the following for more detailed examples.
- Android example usage
- Go example usage
- C# example usage
- Flutter example usage
- Java example usage
- JavaScript example usage – SDK versions 6.0.0 and later.
- Javascript (Browser) example usage – SDK versions 5.3.5 and earlier.
- JavaScript (Node) example usage – SDK versions 5.3.5 and earlier.
- PHP example usage
- Python example usage
- React example usage
- Ruby example usage
- Swift example usage
Optimizely Feature Experimentation uses the Decide method call to decide whether a user qualifies for the rule and which variation they receive. The Optimizely Feature Experimentation SDKs let you reuse the exact flag implementation for different flag rules.
Remember, a user evaluates against all the rules in a ruleset in order before being bucketed into a rule's variation. See Create feature flags.
Updated 15 days ago