• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Big Segments

    Read time: 3 minutes
    Last edited: Feb 27, 2023
    Big Segments is an Enterprise feature

    Big Segments is available to customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.

    Overview

    This topic explains how the Big Segments feature works in the LaunchDarkly SDKs that support it.

    Big Segments are a type of segment that can contain an arbitrarily large number of contexts of any one context kind. To learn more, read Big Segments.

    Newer versions of LaunchDarkly SDKs replace users with contexts

    A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users."

    Creating contexts and evaluating flags based on them is supported in the latest major versions of most of our SDKs. For these SDKs, the code samples on this page include the two most recent versions.

    Using Big Segments

    Client-side SDKs support Big Segments by default, so no additional SDK configuration is required. However, if you use the Relay Proxy with client-side SDKs, then the Relay Proxy must be configured to use persistent storage.

    You must configure server-side SDKs to use the Relay Proxy to get Big Segments data from the Relay Proxy persistent storage. If your server-side SDKs are currently connecting to the Relay Proxy in proxy mode, then your app processes that use server-side SDKs will need direct access to the persistent store that the Relay Proxy uses.

    To learn more, read Configuring the Relay Proxy for Big Segments.

    Details about each server-side SDK's Big Segments feature are available in the SDK-specific sections below.

    Server-side SDKs

    Server-side SDK configuration for Big Segments is comprised of two parts:

    1. The specific database options to get Big Segments data: for example, which database to use, and any other parameters supported by the SDK to configure that database. These are the same database options you specify when configuring server-side SDKs to use external databases as persistent feature stores. For example, key prefix or DynamoDB table name. To learn more about these database options, read Storing data.
    Only certain types of database integration supports Big Segments

    Only the Redis and DynamoDB integrations support Big Segments. If you use Redis, each Redis host needs enough RAM to load the full set of Big Segments and flag configurations.

    1. The general options for the SDK's Big Segments behavior: the table below lists all the general options available. They are all optional and valid for all server-side SDKs and can be used for any supported database integration.
    Config optionDescription
    user or context cache sizeThe maximum number of contexts whose Big Segments status the SDK can cache. The Big Segments status includes all of the Big Segments the context is a part of. A higher value means that the SDK queries the database for recently-referenced contexts' Big Segments statuses less often. If not specified, the default value is 1000.
    user or context cache timeThe maximum length of time that the SDK caches the Big Segments status. If you do not specify a value, the default is five seconds.
    status poll intervalThe interval at which the SDK polls the Big Segments store to make sure it is available and to determine how long ago it was updated. If not specified, the default value is five seconds.
    stale afterThe maximum length of time between updates of Big Segments data before the SDK considers the data out of date. If you do not specify a value, the default is two minutes.

    In all the server-side SDK code examples below, the configuration is set as follows:

    • using a Redis server at my-redis:6379
    • with a key prefix of my-key-prefix
    • cache size: 2000
    • cache time: 30 seconds

    This feature is available in the listed versions and later of the following server-side SDKs:

    .NET (server-side)

    Expand .NET (server-side) code sample

    Big Segments is available in version 6.2.0 and later:

    using LaunchDarkly.Sdk.Server;
    using LaunchDarkly.Sdk.Server.Integrations;
    var config = Configuration.Builder("sdk-key-123abc")
    .BigSegments(
    Components.BigSegments(
    Redis.DataStore()
    .HostAndPort("my-redis", 6379)
    .Prefix("my-key-prefix")
    )
    .ContextCacheSize(2000)
    .CacheTime(TimeSpan.FromSeconds(30))
    )
    .Build();
    var client = new LDClient(config);

    To learn more about the available Big Segments configuration options, read BigSegmentsConfigurationBuilder.

    Go

    Expand Go code sample

    Big Segments is available in version 5.5.0 and later:

    import (
    ld "github.com/launchdarkly/go-server-sdk/v6"
    "github.com/launchdarkly/go-server-sdk/v6/ldcomponents"
    ldredis "github.com/launchdarkly/go-server-sdk-redis"
    )
    var config ld.Config
    config.BigSegments = ldcomponents.BigSegments(
    ldredis.DataStore().
    HostAndPort("my-redis", 6379).
    Prefix("my-key-prefix"),
    ).
    ContextCacheSize(2000).
    ContextCacheTime(time.Second * 30)
    client := ld.MakeCustomClient(sdkKey, config, waitTime)

    To learn more about the available Big Segments configuration options, read BigSegmentsConfigurationBuilder.

    Java

    Expand Java code sample

    Big Segments is available in version 5.7.0 and later:

    import com.launchdarkly.sdk.server.*;
    import com.launchdarkly.sdk.server.integrations.*;
    import java.net.URI;
    import java.time.Duration;
    LDConfig config = new LDConfig.Builder()
    .bigSegments(
    Components.bigSegments(
    Redis.dataStore()
    .uri(URI.create("redis://my-redis:6379"))
    .prefix("my-key-prefix")
    )
    .userCacheSize(2000)
    .userCacheTime(Duration.ofSeconds(30))
    )
    .build();
    LDClient client = new LDClient(sdkKey, config);

    To use either the Redis integration, as shown above, or the DynamoDB integration in the Java SDK, you must also install additional packages. To learn more, read Redis and DynamoDB.

    To learn more about the available Big Segments configuration options, read BigSegmentsConfigurationBuilder.

    Node.js (server-side)

    Expand Node.js (server-side) code sample

    Big Segments is available in version 6.2.0 and later:

    const LaunchDarkly = require('launchdarkly-node-server-sdk');
    const { RedisBigSegmentStore } = require('launchdarkly-node-server-sdk-redis');
    const store = RedisBigSegmentStore({
    redisOpts: { url: 'redis://your-redis:6379' },
    prefix: 'your-key-prefix'
    });
    const config = {
    bigSegments: {
    store: store,
    userCacheSize: 2000,
    userCacheTime: 30
    }
    };
    const client = LaunchDarkly.init(sdkKey, config);

    To learn more about the available Big Segments configuration options, read LDBigSegmentsOptions.

    Python

    Expand Python code sample

    Big Segments is available in version 7.3.0 and later:

    import ldclient
    from ldclient.config import Config, BigSegmentsConfig
    from ldclient.integrations import Redis
    store = Redis.new_big_segment_store(
    url='redis://my-redis:6379',
    prefix='my-key-prefix')
    config = Config(sdk_key, big_segments=BigSegmentsConfig(store=store))
    ldclient.set_config(config)
    client = ldclient.get()

    To use either the Redis integration, as shown above, or the DynamoDB integration in the Python SDK, you must also install additional packages. To learn more, read Redis and DynamoDB.

    To learn more about the available Big Segments configuration options, read BigSegmentsConfig.

    Ruby

    Expand Ruby code sample

    Big Segments is available in version 6.3.0 and later:

    store = LaunchDarkly::Integrations::Redis.new_big_segment_store(
    redis_url: 'redis://my-redis:6379',
    prefix: 'my-key-prefix'
    )
    config = LaunchDarkly::Config.new(
    big_segments: LaunchDarkly::BigSegmentsConfig.new(store: store)
    )
    client = LaunchDarkly::LDClient.new(sdk_key, config)

    To use either the Redis integration, as shown above, or the DynamoDB integration in the Ruby SDK, you must also install additional gems. To learn more, read Redis and DynamoDB.

    To learn more about the available Big Segments configuration options, read BigSegmentsConfig.