# batchlog_endpoint_strategy Options in Cassandra: Complete Guide with Use Cases

> Explore Cassandra batchlog endpoint strategies: prefer local, random remote, dynamic, and dynamic remote. Learn which option suits your needs for optimal batch logging.

- Repository: [The Apache Software Foundation/cassandra](https://github.com/apache/cassandra)
- Tags: how-to-guide
- Published: 2026-07-29

---

**Apache Cassandra offers four `batchlog_endpoint_strategy` options—`prefer_local`, `random_remote`, `dynamic`, and `dynamic_remote`—that determine how the coordinator selects the replica node to store the batchlog for logged batches, balancing latency, load distribution, and dynamic snitch awareness.**

The batchlog mechanism guarantees durability for logged batches by persisting a temporary mutation on a selected endpoint before the batch is replayed. In the `apache/cassandra` source code, the `batchlog_endpoint_strategy` configuration controls whether the coordinator favors local data replicas, random remote nodes, or latency-optimized selections based on dynamic snitch scores. Choosing the correct strategy is essential for minimizing cross-rack traffic and optimizing write performance across single or multi-datacenter deployments.

## Available batchlog_endpoint_strategy Options

The strategy enum is defined in `org.apache.cassandra.config.Config.BatchlogEndpointStrategy` and applied through [`BatchlogEndpointFilter.java`](https://github.com/apache/cassandra/blob/main/BatchlogEndpointFilter.java). Each option varies in its preference for local versus remote endpoints and its use of dynamic snitch scores.

### prefer_local

**`prefer_local`** selects a **local replica**—a node that already stores the data for the mutation—whenever one is available. If no local replica exists, the coordinator falls back to a random remote node. This strategy **disables dynamic snitch scoring**, making the selection purely topology-based.

Use this strategy in **low-latency, single-DC clusters** where minimizing inter-node traffic is prioritized. It keeps batchlog writes on the same nodes holding the actual data, reducing network hops and cross-rack bandwidth.

### random_remote

**`random_remote`** always selects a **random remote node** outside the local datacenter, regardless of where the data resides. Like `prefer_local`, this strategy **ignores dynamic snitch scores**, relying instead on pure randomization to distribute load.

Deploy this option in **highly available setups** where you want to ensure the batchlog is stored on a node unlikely to share failure domains with the data replicas. This spreads write load evenly across the cluster but may introduce higher latency.

### dynamic

**`dynamic`** chooses a **local replica** based on the **dynamic snitch score**, favoring the node with the best current performance characteristics. Unlike the previous options, this strategy **enables dynamic snitch awareness**, allowing the coordinator to route batchlog writes to the fastest available local replica.

Select this strategy for **performance-critical clusters** that already rely on dynamic snitch for latency-aware routing. It ensures the batchlog follows the same optimized path as standard writes, adapting to real-time load conditions.

### dynamic_remote

**`dynamic_remote`** picks a **remote node** (outside the local DC) using the **dynamic snitch score** to identify the least-loaded remote endpoint. This strategy **enables dynamic snitch scoring** for remote selection, differing from `random_remote` by avoiding randomly overloading specific nodes.

**Note:** Earlier Cassandra versions used the name `dynamic` for this remote-selection behavior; `dynamic_remote` maintains backward compatibility while clarifying the topology preference.

Use this in **multi-DC deployments** where you prefer the batchlog to reside in a remote datacenter for disaster recovery purposes, while still leveraging load-aware placement to prevent hotspots.

## Configuring batchlog_endpoint_strategy

Set the strategy in [`cassandra.yaml`](https://github.com/apache/cassandra/blob/main/cassandra.yaml) using the property name `batchlog_endpoint_strategy`:

```yaml

# cassandra.yaml

batchlog_endpoint_strategy: prefer_local

```

Valid values are `prefer_local`, `random_remote`, `dynamic`, and `dynamic_remote`.

### Programmatic Access

For testing or custom initialization, access the strategy through `DatabaseDescriptor`:

```java
// Set the strategy programmatically
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.DatabaseDescriptor;

DatabaseDescriptor.setBatchlogEndpointStrategy(
    Config.BatchlogEndpointStrategy.prefer_local
);

// Retrieve current configuration
Config.BatchlogEndpointStrategy current = 
    DatabaseDescriptor.getBatchlogEndpointStrategy();
System.out.println("Active strategy: " + current);

```

## Implementation in Source Code

The endpoint selection logic resides in [`src/java/org/apache/cassandra/batchlog/BatchlogEndpointFilter.java`](https://github.com/apache/cassandra/blob/main/src/java/org/apache/cassandra/batchlog/BatchlogEndpointFilter.java), which queries the configured strategy from `DatabaseDescriptor` and applies the selection algorithm accordingly.

Key source files include:

- **[`src/java/org/apache/cassandra/config/Config.java`](https://github.com/apache/cassandra/blob/main/src/java/org/apache/cassandra/config/Config.java)** – Defines the `BatchlogEndpointStrategy` enum with the four available options.
- **[`src/java/org/apache/cassandra/config/DatabaseDescriptor.java`](https://github.com/apache/cassandra/blob/main/src/java/org/apache/cassandra/config/DatabaseDescriptor.java)** – Provides `setBatchlogEndpointStrategy()` and `getBatchlogEndpointStrategy()` accessors.
- **[`src/java/org/apache/cassandra/batchlog/BatchlogEndpointFilter.java`](https://github.com/apache/cassandra/blob/main/src/java/org/apache/cassandra/batchlog/BatchlogEndpointFilter.java)** – Implements the filtering logic that selects the endpoint based on the active strategy and topology.
- **[`test/unit/org/apache/cassandra/batchlog/BatchlogEndpointFilterTest.java`](https://github.com/apache/cassandra/blob/main/test/unit/org/apache/cassandra/batchlog/BatchlogEndpointFilterTest.java)** – Unit tests validating behavior for each strategy variant.

## Summary

- **`prefer_local`** keeps batchlog writes on local data replicas without dynamic snitch input, ideal for reducing cross-node traffic in single-DC clusters.
- **`random_remote`** distributes batchlog writes randomly across remote nodes, useful for load distribution but ignoring latency scores.
- **`dynamic`** selects the best-performing local replica using dynamic snitch scores, optimizing for low-latency writes.
- **`dynamic_remote`** chooses the least-loaded remote node using dynamic snitch scoring, balancing multi-DC durability with performance awareness.
- Configuration is managed via [`cassandra.yaml`](https://github.com/apache/cassandra/blob/main/cassandra.yaml) or programmatically through `DatabaseDescriptor` in `org.apache.cassandra.config`.

## Frequently Asked Questions

### Which batchlog_endpoint_strategy options ignore dynamic snitch scores?

The `prefer_local` and `random_remote` strategies operate without dynamic snitch awareness. They select endpoints based purely on topology (local replica preference) or randomization, respectively, without evaluating node performance scores.

### What is the difference between dynamic and dynamic_remote strategies?

While both strategies use dynamic snitch scores to select the optimal endpoint, **`dynamic`** targets **local replicas** within the same datacenter, whereas **`dynamic_remote`** targets **remote nodes** outside the local DC. The former optimizes for local write latency, while the latter optimizes for remote durability with load awareness.

### When should I use random_remote instead of prefer_local?

Choose **`random_remote`** when you want to guarantee that batchlog mutations are stored on nodes separate from your data replicas, providing better fault isolation. Use **`prefer_local`** when minimizing write latency and network traffic is the priority, as it keeps the batchlog on the same node that holds the data.

### How does Cassandra apply the batchlog_endpoint_strategy during write operations?

When a logged batch is received, the coordinator invokes `BatchlogEndpointFilter` to select the batchlog endpoint. The filter checks the `batchlog_endpoint_strategy` value from `DatabaseDescriptor` and applies the corresponding selection logic—checking local replicas, randomizing across remote nodes, or querying the dynamic snitch—to determine where the batchlog mutation is stored before the batch is replayed.