---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ydb.tech/docs/en/recipes/ydb-sdk/balancing-prefer-pile.md?version=v25.4
  - href: en/recipes/ydb-sdk/balancing-prefer-pile.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
sourcePath: en/core/recipes/ydb-sdk/balancing-prefer-pile.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Prefer a pile with a specific state

Below is an example of setting the balancing algorithm option that prefers a [pile](https://ydb.tech/docs/en/concepts/glossary.md?version=v25.4#pile) in a given [state](https://ydb.tech/docs/en/concepts/bridge.md?version=v25.4#pile-states) in the YDB SDK.

If no state is specified when setting the option, the SDK prefers the PRIMARY pile.

This option only makes sense if the cluster is operating in [bridge mode](https://ydb.tech/docs/en/concepts/bridge.md?version=v25.4). Otherwise, the SDK uses [random choice balancing](https://ydb.tech/docs/en/recipes/ydb-sdk/balancing-random-choice.md?version=v25.4).

{% list tabs %}

- Go

  This functionality is not currently supported.

- C++

  ```cpp
  #include <ydb-cpp-sdk/client/driver/driver.h>

  int main() {
    auto connectionString = std::string(std::getenv("YDB_CONNECTION_STRING"));

    auto driverConfig = NYdb::TDriverConfig(connectionString)
      .SetBalancingPolicy(NYdb::TBalancingPolicy::UsePreferablePileState(NYdb::EPileState::PRIMARY));

    NYdb::TDriver driver(driverConfig);
    // ...
    driver.Stop(true);
    return 0;
  }
  ```

- Python

  This functionality is not currently supported.

- JavaScript

  <!-- source: en/_includes/work-in-progress.md -->
  This section is under development.
  <!-- endsource: en/_includes/work-in-progress.md -->

- Java

  This functionality is not currently supported.

- Rust

  <!-- source: en/_includes/feature-not-supported.md -->
  This functionality is not currently supported.
  <!-- endsource: en/_includes/feature-not-supported.md -->

  Track progress or vote for Rust SDK support: [ydb-rs-sdk#491](https://github.com/ydb-platform/ydb-rs-sdk/issues/491)

{% endlist %}
