> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Using daemon mode

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

Each SDK connects to several LaunchDarkly web services. These include services for getting feature flag data via streaming or polling, and a service for storing analytics events. By default, the SDK connects directly to LaunchDarkly for these services.

If you are using the Relay Proxy, you must configure the SDK so that it connects to the Relay Proxy for these services instead.

To use the Relay Proxy in **daemon** mode, you must first configure your server-side SDK to use a persistent data store. The SDK and the Relay Proxy must use the same data store. To configure your SDK to use a persistent data store, read [Storing Data](/docs/sdk/features/storing-data).

Then, you must configure your SDK to use daemon mode, as shown in the following examples. When you use the Relay Proxy in daemon mode, the SDK must not connect to any service for flag data.

<Note>
  **Different SDKs have different names for daemon mode**

  When you configure the SDK so that it connects to the Relay Proxy, rather than to LaunchDarkly, for getting feature feature flag data, this mode has different names in different SDKs and SDK versions.

  Some versions of the SDKs refer to this as using "external updates only." Other versions of the SDKs refer to this as "LDD mode," because the Relay Proxy was previously known as the LaunchDarkly Daemon. Some SDKs, such as the C++ (server-side) SDK, refer to this mode as "lazy load," because flag data is loaded from the persistent store lazily, on demand as the SDK requests it. In most SDKs, you then need to pass the configuration in as a parameter when you initialize the client. To learn more, read [SDK configuration](/docs/sdk/features/config).
</Note>

This feature is not available for client-side SDKs because in daemon mode, the SDK connects directly to the Relay Proxy's data store. This is not a supported behavior for client-side SDKs.

## Server-side SDKs

This feature is available for the following server-side SDKs:

* [.NET (server-side)](#net-server-side)
* [C++ (server-side)](#c++-server-side)
* [Erlang](#erlang)
* [Go](#go)
* [Haskell](#haskell)
* [Java](#java)
* [Lua](#lua)
* [Node.js (server-side)](#node-js-server-side)
* [PHP](#php)
* [Python](#python)
* [Ruby](#ruby)
* [Rust](#rust)

### .NET (server-side)

<Accordion title="Expand .NET (server-side) code sample">
  Use the `DataStore` builder method to set a persistent feature store. Then, use the `DataSource` builder method and `Components.ExternalUpdatesOnly` to configure daemon mode:

  <CodeGroup>
    ```csharp title=".NET SDK DataStore" lines wrap theme={null}
    var config = Configuration.Builder("YOUR_SDK_KEY")
        .DataStore(
            Components.PersistentDataStore(
                SomeDatabaseName.DataStore()
            )
        )
        .DataSource(Components.ExternalUpdatesOnly)
        .Build();
    ```
  </CodeGroup>

  If you are using the newer DataSystem configuration added in .NET SDK 8.11+, use the `DataSystem` builder with `Components.DataSystem().Daemon()` to configure daemon mode:

  <CodeGroup>
    ```csharp title=".NET SDK 8.11+ DataSystem" lines wrap theme={null}
    var config = Configuration.Builder("YOUR_SDK_KEY")
        .DataSystem(
            Components.DataSystem().Daemon(
                Components.PersistentDataStore(Redis.DataStore())
            )
        )
        .Build();
    ```
  </CodeGroup>
</Accordion>

### C++ (server-side)

<Accordion title="Expand C++ (server-side) code sample">
  Use `LazyLoadBuilder` to set a persistent feature store:

  <CodeGroup>
    ```cpp title="C++ SDK v3.0 (native)" lines wrap theme={null}
    using LazyLoad = server_side::config::builders::LazyLoadBuilder;

    auto config_builder = server_side::ConfigBuilder(sdk_key);

    auto some_source = YourDatabaseIntegration();

    config_builder.DataSystem().Method(
        LazyLoad().Source(some_source)
    );

    auto config = config_builder.Build();
    if (!config) {
        /* an error occurred, config is not valid */
    }
    ```
  </CodeGroup>
</Accordion>

### Erlang

<Accordion title="Expand Erlang code sample">
  Set the `feature_store` property to use a persistent data store. Then set the `use_ldd` property to configure daemon mode:

  <CodeGroup>
    ```erlang title="Erlang" lines wrap theme={null}
    ldclient:start_instance("YOUR_SDK_KEY", #{
      use_ldd => true,
      feature_store => your_feature_store
    })
    ```
  </CodeGroup>
</Accordion>

### Go

<Accordion title="Expand Go code sample">
  Use `PersistentDataStore()` to set the persistent data store. Then, use `ExternalUpdatesOnly()` to configure daemon mode:

  <CodeGroup>
    ```go title="Go" lines wrap theme={null}
    config := ld.Config{
        DataStore:  ldcomponents.PersistentDataStore(
          examplepackage.DataStore().SomeStoreOptions(),
        ),
        DataSource: ldcomponents.ExternalUpdatesOnly(),
    }

    ```
  </CodeGroup>
</Accordion>

### Haskell

<Accordion title="Expand Haskell code sample">
  Use `configSetStoreBackend` to set the persistent data store. Then, use `configSetUseLdd` to configure daemon mode:

  <CodeGroup>
    ```haskell title="Haskell" lines wrap theme={null}
    {-# LANGUAGE OverloadedStrings #-}

    import LaunchDarkly.Server.Config

    import Data.Function ((&))

    config :: Config
    config = (makeConfig "YOUR_SDK_KEY")
        & configSetUseLdd True
        & configSetStoreBackend backend
    ```
  </CodeGroup>
</Accordion>

### Java

<Accordion title="Expand Java code sample">
  Set the `dataStore` property to `persistentDataStore()` to use the persistent data store. Then, set the `dataSource` property to `externalUpdatesOnly()` to configure daemon mode:

  <CodeGroup>
    ```java title="Java SDK dataStore" lines wrap theme={null}
    LDConfig config = new LDConfig.Builder()
      .dataStore(
        Components.persistentDataStore(
          SomeDatabaseName.DataStore(storeOptions)
        )
      )
      .dataSource(Components.externalUpdatesOnly())
      .build();
    ```
  </CodeGroup>

  If you are using the newer DataSystem configuration added in Java SDK 7.11+, use the `dataSystem` builder with `Components.dataSystem().daemon()` to configure daemon mode:

  <CodeGroup>
    ```java title="Java SDK 7.11+ DataSystem" lines wrap theme={null}
    import com.launchdarkly.sdk.server.*;

    LDConfig config = new LDConfig.Builder()
        .dataSystem(
            Components.dataSystem().daemon(
                Components.persistentDataStore(Redis.dataStore())
            )
        )
        .build();

    LDClient client = new LDClient("YOUR_SDK_KEY", config);
    ```
  </CodeGroup>
</Accordion>

### Lua

<Accordion title="Expand Lua code sample">
  Specify a `lazyLoad` data source to set a persistent feature store:

  <CodeGroup>
    ```lua title="Lua SDK v2" lines wrap theme={null}
    local config = {
        dataSystem = {
            lazyLoad = {
                source = makeYourSource()
            }
        }
    }
    ```
  </CodeGroup>

  To learn more about the configuration options, read [`clientInit`](https://launchdarkly.github.io/lua-server-sdk/modules/launchdarkly-server-sdk.html#clientInit).
</Accordion>

### Node.js (server-side)

<Accordion title="Expand Node.js (server-side) code sample">
  Set the `featureStore` property to use a persistent feature store. Then, set the `useLdd` property to configure daemon mode:

  <CodeGroup>
    ```ts title="Node.js SDK v8.x+ (TypeScript)" lines wrap theme={null}
    import * as ld from '@launchdarkly/node-server-sdk';

    const store = SomeKindOfFeatureStore(storeOptions);

    const options: ld.LDOptions = {
      featureStore: store,
      useLdd: true,
    };
    ```
  </CodeGroup>
</Accordion>

### PHP

<Accordion title="Expand PHP code sample">
  Set the `feature_requester` property to use a persistent data store and daemon mode:

  <CodeGroup>
    ```php title="PHP" lines wrap theme={null}
    $client = new LaunchDarkly\LDClient("YOUR_SDK_KEY",
        [ 'feature_requester' => LaunchDarkly\Integrations\NameOfDatabase::featureRequester() ]);
    ```
  </CodeGroup>
</Accordion>

### Python

<Accordion title="Expand Python code sample">
  Set the `feature_store` property to use a persistent data store. Then, set the `use_ldd` property to configure daemon mode:

  <CodeGroup>
    ```python title="Python" lines wrap theme={null}
    store = SomeKindOfFeatureStore(store_options)

    config = Config(
      feature_store=store,
      use_ldd=True)
    ```
  </CodeGroup>
</Accordion>

### Ruby

<Accordion title="Expand Ruby code sample">
  Set the `feature_store` property to use a persistent feature store. Then, set the `use_ldd` property to configure daemon mode:

  <CodeGroup>
    ```ruby title="Ruby SDK feature_store" lines wrap theme={null}

    store = SomeKindOfFeatureStore.new(storeOptions)

    config = LaunchDarkly::Config.new(
      feature_store: store,
      use_ldd: true
    )
    ```
  </CodeGroup>

  If you are using the newer DataSystem configuration added in Ruby SDK 8.12.0+, use the `data_system_config` option with `LaunchDarkly::DataSystem.daemon()` to configure daemon mode:

  <CodeGroup>
    ```ruby title="Ruby SDK 8.12.0+ DataSystem" lines wrap theme={null}
    require 'ldclient-rb'

    store = SomeKindOfFeatureStore.new(storeOptions)

    config = LaunchDarkly::Config.new(
      data_system_config: LaunchDarkly::DataSystem.daemon(store).build
    )

    client = LaunchDarkly::LDClient.new("YOUR_SDK_KEY", config)
    ```
  </CodeGroup>
</Accordion>

### Rust

<Accordion title="Expand Rust code sample">
  Using the `PersistentDataStoreBuilder`, provide a persistent store factory.

  Enable daemon mode by calling `daemon_mode(true)` on the `ConfigBuilder`:

  <CodeGroup>
    ```rust title="Rust" lines wrap theme={null}
    use launchdarkly_server_sdk::{ConfigBuilder, PersistentDataStoreBuilder};


    let persistent_store_factory = SomeKindOfFeatureStore::new(store_options);
    let persistent_data_store_builder = PersistentDataStoreBuilder::new(Arc::new(persistent_store_factory));

    let config = ConfigBuilder::new("sdk-key")
                .daemon_mode(true)
                .data_store(&persistent_data_store_builder)
                .build()
                .expect("config should build");
    ```
  </CodeGroup>
</Accordion>
