> Markdown version of https://www.getunleash.io//blog/complex-targeting-rules-in-feature-flags-unleash-strategy-variants
> For clean Markdown of any blog post, append .md to its URL.
> For a site index, see https://www.getunleash.io//llms.txt.

# Complex Targeting Rules in Feature Flags: Unleash Strategy Variants

_Published 2023-10-02 by Michael Ferranti in Product._

Unleash has evolved through continuous improvement and frequent, iterative releases. Every month, we release a new version of Unleash with many improvements. 

Occasionally, we release something that is a fundamental breakthrough, something that makes Unleash more adaptable and simpler at the same time. [Strategy Variants](https://docs.getunleash.io/reference/strategy-variants) is one of these moments. 

With [Unleash 5.5](https://www.getunleash.io/blog/unleash-5-5-strategy-variants-open-source-segments-and-more), we have made a significant breakthrough in how we handle variants.

For those familiar with [Domain-Driven Design](https://en.wikipedia.org/wiki/Domain-driven_design), this is a **domain breakthrough**. Domain-driven design is software design approach and a set of techniques that we find useful at Unleash. We’ve mentioned it before, including in [Building your own feature flag platform might be a mistake](https://www.getunleash.io/blog/building-your-own-feature-flag-platform-might-be-a-mistake).

![Domain Driven Design: Breakthrough](https://cdn.getunleash.io/uploads/2023/10/ddd.jpg)

Domain Driven Design: Breakthrough

## Feature Flag Variants
In the beginning, Unleash started with feature flag variants that allow for assigning distinct values to different users.

![Variants per Feature Toggle](https://cdn.getunleash.io/uploads/2023/10/Screenshot-2023-08-07-at-11.59.19.png)

So, if a feature was active for a group of users, you could designate a percentage of those users to receive variant A, variant B, and so on. 

This can be seen as a two-tiered approach: first, determining which users have the feature activated and subsequently deciding on the variant to present to each user. Such a system paves the way for A/B/n testing. 

For instance, imagine running a test on a website’s headline: 50% of users could be shown “titleA” while the other 50% see “titleB”. This allows for direct comparison of user engagement or other metrics between the two titles, helping to determine which is more effective.

## Environment-specific Feature Variants
![Variant per feature environment](https://cdn.getunleash.io/uploads/2023/10/Screenshot-2023-08-07-at-12.00.49.png)

As our platform evolved, some users expressed the desire to test different variants in both development and production environments. In response, Unleash introduced environment-specific feature variants. 

To streamline the process for users who maintain consistent variants across environments, we implemented a feature that facilitates the transfer of variants between environments.

## Strategy Variants
![Variant per activation strategy](https://cdn.getunleash.io/uploads/2023/10/Screenshot-2023-08-07-at-12.02.41.png)

Our initial variants catered to a randomized distribution, ideal for A/B/n testing. However, a growing number of users sought to implement intricate conditions in tandem with percentage distributions.

This opened the door to many complex scenarios, such as:

-   Serving the ‘titleForInternalUsers’ to a predefined internal user segment.
-   Presenting ‘titleForGmailUsers’ to customers with ‘@gmail.com’ email addresses (utilizing an ‘ends with’ operator).
-   Dividing the remaining users equally between ‘genericTitleA’ and ‘genericTitleB’ (a percentage split).

While the obvious course might have been to incorporate these capabilities directly within variants, we opted for a different path. 

We realized our [feature flag activation strategies](https://docs.getunleash.io/reference/activation-strategies) already catered to these intricate conditions, supporting constraints, advanced operators, and user segments. 

**Rather than individually adding these targeting options to variants, we integrated variants into strategies**. As a result, every strategy now not only dictates an on/off status but also associates an on condition with a specific variant. 

Implementing the new model felt inherently right from a coding perspective and also offers a more intuitive user experience. 

It was a domain breakthrough event and we’re incredible proud that it was a mere 3 weeks from ideation to a production-ready solution.
