2019-02-08 08:30:07 +01:00
---
2020-08-10 10:10:41 +02:00
id: toggle_variants
title: Feature Toggle Variants
2019-02-08 08:30:07 +01:00
---
2020-08-10 10:10:41 +02:00
> This feature was introduced in _Unleash v3.2.0_.
2019-02-08 08:30:07 +01:00
2019-03-05 09:26:34 +01:00
Do you want to facilitate more advanced experimentations? Do you want to use Unleash to handle your A/B experiments? Say hello to feature toggle variants!
2019-02-08 08:30:07 +01:00
2019-03-05 09:26:34 +01:00
You can now extend feature toggles with multiple variants. This feature enables you to extend a feature toggle to divide your traffic among a set of variants.
2019-02-08 08:30:07 +01:00
2021-06-04 11:17:15 +02:00
![toggle_variants ](/img/variants.png 'Feature Toggle Variants' )
2019-02-08 08:30:07 +01:00
2021-06-04 11:17:15 +02:00
#### How does it work? {#how-does-it-work}
2019-02-08 08:30:07 +01:00
2019-03-05 09:26:34 +01:00
Unleash will first use activation strategies to decide whether a feature toggle is considered enabled or disabled for the current user.
2019-02-08 08:30:07 +01:00
2019-03-05 09:26:34 +01:00
If the toggle is considered **enabled** , the Unleash client will select the correct variant for the request. Unleash clients will use values from the Unleash context to make the allocation predictable. `UserId` is the preferred value, then `sessionId` and `remoteAdr` . If no context data is provided, the traffic will be spread randomly for each request.
2019-02-08 08:30:07 +01:00
If the toggle is considered **disabled** you will get the built-in `disabled` variant.
2021-02-11 17:59:16 +01:00
A json representation of the empty variant will be the following:
2020-10-30 09:22:01 +01:00
```json
{
"name": "disabled",
"enabled": false
}
```
2021-02-11 17:59:16 +01:00
The actual representation of the built-in the client SDK will vary slightly, to honor best practices in various languages.
2020-10-30 09:22:01 +01:00
2019-03-05 09:26:34 +01:00
> If you change the number of variants, it will affect variant allocations. This means that some of the users will be moved to the next variant.
2019-02-08 08:30:07 +01:00
_Java SDK example:_
```java
Variant variant = unleash.getVariant("toggle.name", unleashContext);
System.out.println(variant.getName());
```
2021-06-04 11:17:15 +02:00
#### Client SDK Support {#client-sdk-support}
2019-02-08 08:30:07 +01:00
2019-03-05 09:26:34 +01:00
To make use of toggle variants, you need to use a compatible client. Client SDK with variant support:
2019-02-08 08:30:07 +01:00
- [unleash-client-node ](https://github.com/Unleash/unleash-client-node ) (from v3.2.0)
- [unleash-client-java ](https://github.com/Unleash/unleash-client-java ) (from v3.2.0)
2019-11-13 09:30:59 +01:00
- [unleash-client-ruby ](https://github.com/Unleash/unleash-client-ruby ) (from v0.1.6)
- [unleash-client-python ](https://github.com/Unleash/unleash-client-python ) (from v3.3.0)
2020-10-30 09:51:13 +01:00
- [unleash-client-dotnet ](https://github.com/Unleash/unleash-client-dotnet ) (from v1.3.6)
2021-06-22 10:44:05 +02:00
- [unleash-client-go ](https://github.com/Unleash/unleash-client-go ) (from v3 branch)
2021-10-04 22:18:39 +02:00
- [unleash-client-php ](https://github.com/Unleash/unleash-client-php ) (from v1.0.0)
2019-02-08 08:30:07 +01:00
2019-03-05 09:26:34 +01:00
If you would like to give feedback on this feature, experience issues or have questions, please feel free to open an issue on [GitHub ](https://github.com/Unleash/unleash/ ).