Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Cassandra Driver Load Balancing Policy

The load balancing policy determines which nodes receive requests. This policy directly affects latency, throughput, and cluster load distribution.


For each request, the load balancing policy returns an ordered list of nodes to try:

Load Balancing Query PlanLoad Balancing Query PlanQuery Plan (ordered)Replicas (preferred)Non-replicas (fallback)1. Node22. Node53. Node14. Node35. Node6Request:SELECT * FROM usersWHERE user_id = 'abc123'Load Balancing Policy Evaluates:1. Which nodes are replicas?2. Which nodes are in local DC?3. Which nodes are healthy?4. How to order nodes?

The driver sends the request to the first node. If that fails and the retry policy allows retry, the next node in the list is tried.


Token-aware load balancing sends requests directly to replica nodes, avoiding an extra network hop:

Token-Aware Routing ComparisonToken-Aware Routing ComparisonWithout Token-Aware (2 network hops)With Token-Aware (1 network hop)ApplicationNode1(coordinator)Node3(replica)ApplicationNode3(replica)1. request4. response2. forward3. response1. request2. response

Token-aware routing requires:

  1. Routing key available — The driver must be able to determine the partition key value
  2. Metadata available — Driver must have current token map

The routing key can be provided via:

  • Prepared statements with bound values (most common)
  • Simple statements with explicit routing key set
  • Simple statements with bound values (driver may infer routing key)
// Token-aware: prepared statement with bound partition key
PreparedStatement prepared = session.prepare(
"SELECT * FROM users WHERE user_id = ?");
BoundStatement bound = prepared.bind(userId); // Driver knows partition key
session.execute(bound); // Routes to replica
// Token-aware: simple statement with explicit routing key
SimpleStatement simple = SimpleStatement.builder(
"SELECT * FROM users WHERE user_id = 'abc123'")
.setRoutingKey(TypeCodecs.UUID.encode(userId, ProtocolVersion.V4))
.build();
session.execute(simple); // Routes to replica
// NOT token-aware: literal values without routing key metadata
SimpleStatement unrouted = SimpleStatement.newInstance(
"SELECT * FROM users WHERE user_id = 'abc123'");
session.execute(unrouted); // Driver cannot extract partition key, uses round-robin

In multi-datacenter deployments, the load balancing policy must be configured with the local datacenter:

Datacenter-Aware RoutingDatacenter-Aware RoutingDC1 (local) - Latency: ~1msDC2 (remote) - Latency: ~50msNode1Node2Node3Node4Node5Node6Application(configured: local_dc = \"dc1\")Local DC nodes preferred.Remote DC usage depends on policy configuration.requestsfallback only
// Java driver
CqlSession session = CqlSession.builder()
.withLocalDatacenter("dc1")
.build();
# Python driver
from cassandra.policies import DCAwareRoundRobinPolicy
cluster = Cluster(
contact_points=['10.0.1.1'],
load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='dc1')
)

Failure to configure local datacenter correctly results in requests potentially routing to remote datacenters with significantly higher latency.


Distributes requests evenly across all nodes without considering replicas:

AdvantageDisadvantage
Simple, predictableExtra network hop for every request
Even distributionNo datacenter awareness

Use case: Development environments, specific analytics workloads.

Round-robin within local datacenter only:

AdvantageDisadvantage
Respects datacenter localityStill not token-aware
Predictable distribution within DCExtra hop for most requests

Use case: When token-aware routing is not possible (e.g., many simple statements).

Section titled “Token-Aware with DC Awareness (Recommended)”

Combines token-aware routing with datacenter preference:

Algorithm:
1. Calculate replica set for partition key
2. Filter to local datacenter replicas
3. Order by health/load (implementation varies)
4. Append non-replica local nodes as fallback
5. Optionally append remote DC nodes as last resort
AdvantageDisadvantage
Minimum latency (direct to replica)Requires prepared statements for full benefit
Respects datacenter localitySlightly more complex configuration
Built-in fallback ordering

This combination is commonly used for production deployments. Verify the default behavior for the specific driver version in use.


Some load balancing policies consider rack placement to improve fault tolerance:

Rack-Aware Replica SelectionRack-Aware Replica SelectionReplicas for partitionrack-arack-brack-cNode1(1st choice)Node2(2nd choice)Node3(3rd choice)Application(in rack-a)same rack(lowest latency)

Rack awareness provides marginal latency improvement when:

  • Application servers are rack-aligned with Cassandra nodes
  • Network topology has rack-level latency differences

Load balancing policies typically exclude nodes that are:

ConditionBehavior
Marked DOWNExcluded from query plan
Recently failedMay be deprioritized (implementation varies)
High latencySome policies track latency and avoid slow nodes
OverloadedSome policies consider in-flight request count

Some drivers offer latency-aware policies that track response times and prefer faster nodes:

Latency-Aware Node SelectionLatency-Aware Node SelectionDriver(tracks latency)Node1avg: 2ms(preferred)Node2avg: 5msNode3avg: 15ms(deprioritized)1st2nd3rd

Considerations:

  • Latency tracking adds overhead
  • May cause herding (all clients avoid same node simultaneously)
  • Typically combined with, not replacing, token-aware routing

DeploymentRecommended Policy
Single datacenterToken-aware with round-robin fallback
Multi-datacenterToken-aware with DC awareness
Analytics/batchRound-robin or DC-aware round-robin
Latency-sensitiveToken-aware with latency tracking
Anti-PatternProblem
No local DC configured in multi-DCRequests may route cross-DC
Round-robin for OLTP workloadsUnnecessary latency for every request
Token-aware without prepared statementsFalls back to round-robin anyway