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

# Using daemon mode

> This topic explains how to configure LaunchDarkly SDKs to connect to your Relay Proxy when you are running in daemon mode.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

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](/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 title="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 [Configuration](/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)](#nodejs-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" 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" 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)" 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 */
          }
    ```

    ```c title="C SDK v2.x (native)" theme={null}
          struct LDConfig *config = LDConfigNew("YOUR_SDK_KEY");

          struct LDStoreInterface *store = ConstructYourFeatureStoreInterface();

          LDConfigSetFeatureStoreBackend(config, store);
          LDConfigSetUseLDD(config, true);
    ```
  </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" 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" 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" 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" 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" 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" theme={null}
          local config = {
              dataSystem = {
                  lazyLoad = {
                      source = makeYourSource()
                  }
              }
          }
    ```

    ```lua title="Lua SDK v1.x" theme={null}
          local backend = makeYourBackendInterface()

          local config = {
              key = "YOUR_SDK_KEY",
              featureStoreBackend = backend,
              useLDD = true
          }
    ```
  </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)" theme={null}
          import * as ld from '@launchdarkly/node-server-sdk';

          const store = SomeKindOfFeatureStore(storeOptions);

          const options: ld.LDOptions = {
            featureStore: store,
            useLdd: true,
          };
    ```

    ```js title="Node.js SDK v7.x (JavaScript)" theme={null}
          const store = SomeKindOfFeatureStore(storeOptions);

          const options = {
            featureStore: store,
            useLdd: true,
          };
    ```

    ```ts title="Node.js SDK v7.x (TypeScript)" theme={null}
          import LDOptions from 'launchdarkly-node-server-sdk';

          const store = SomeKindOfFeatureStore(storeOptions);

          const options: 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" 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" 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" 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" 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" theme={null}
          use launchdarkly_server_sdk::{ConfigBuilder, PersistentDataStoreBuilder};


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

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