Multivariate Feature Flag Configuration

Configure multivariate feature flags with string, number, or JSON values instead of simple booleans. Useful for dynamic config, themes, and A/B/n testing.

Advanced Patterns

Detailed Explanation

Multivariate Feature Flags

Multivariate flags go beyond boolean on/off to serve different values to different users. The flag value can be a string, number, or JSON object, enabling dynamic configuration without code deploys.

String Variation Example

{
  "pricing-page-layout": {
    "name": "Pricing Page Layout",
    "description": "Which pricing page layout to show",
    "type": "string",
    "enabled": true,
    "defaultValue": "two-column",
    "targeting": [
      {
        "type": "percentage-rollout",
        "percentage": 30
      }
    ]
  }
}

JSON Variation Example

{
  "homepage-hero-config": {
    "name": "Homepage Hero Configuration",
    "type": "json",
    "enabled": true,
    "defaultValue": {
      "title": "Welcome to Our Platform",
      "subtitle": "Get started in minutes",
      "ctaText": "Sign Up Free",
      "ctaColor": "#3b82f6",
      "showVideo": false
    }
  }
}

LaunchDarkly Multivariate

In LaunchDarkly, multivariate flags use kind: "multivariate":

{
  "kind": "multivariate",
  "variations": [
    { "value": "two-column", "name": "Two Column Layout" },
    { "value": "three-column", "name": "Three Column Layout" },
    { "value": "single-scroll", "name": "Single Scroll Layout" }
  ],
  "fallthrough": {
    "rollout": {
      "variations": [
        { "variation": 0, "weight": 40000 },
        { "variation": 1, "weight": 30000 },
        { "variation": 2, "weight": 30000 }
      ]
    }
  }
}

Use Cases for Each Type

Type Use Case Example
String UI variants, themes "dark", "light", "auto"
Number Rate limits, timeouts 100, 500, 1000
JSON Complex configs {"maxRetries": 3, "timeout": 5000}

Number Variation: Rate Limiting

{
  "api-rate-limit": {
    "type": "number",
    "defaultValue": 100,
    "targeting": [
      {
        "type": "user-segment",
        "segment": "enterprise-users"
      }
    ]
  }
}

Enterprise users get a higher rate limit, while free users get the default.

Type Safety Considerations

  • Always validate the flag value in your application code
  • Define TypeScript types for JSON flag values
  • Use schema validation for complex JSON configurations
  • Provide meaningful defaults that the application can always fall back to

Use Case

A SaaS product wants to test three different pricing page layouts simultaneously. Using a multivariate string flag, they assign 40% of users to the two-column layout, 30% to three-column, and 30% to a single-scroll design. After two weeks of data collection, they choose the layout with the highest conversion rate.

Try It — Feature Flag Config Generator

Open full tool