ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Deployments
    • Cloud
    • Server
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
    • Supported Driver Versions
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Install
Search Ask AI
ScyllaDB Docs ScyllaDB gocql driver Load balancing
For AI agents: a documentation index is available at https://gocql-driver.docs.scylladb.com/master/llms.txt. A Markdown version of this page is at https://gocql-driver.docs.scylladb.com/master/load-balancing.md.

Load balancingΒΆ

Use a token-aware policy so requests go to replicas that own the queried partition. In a multi-datacenter cluster, wrap a data-center-aware fallback policy and use local consistency:

cluster := gocql.NewCluster(hosts...)

fallback := gocql.RoundRobinHostPolicy()
if localDC != "" {
	fallback = gocql.DCAwareRoundRobinPolicy(localDC)
	cluster.Consistency = gocql.LocalQuorum
}

cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(fallback)

Token-aware routing needs metadata for every partition-key component. Bind all partition-key values instead of embedding them in the CQL string:

// Routable: both partition-key components are bound values.
session.Query(
	"SELECT value FROM events WHERE account_id = ? AND bucket = ?",
	accountID,
	bucket,
)

DCAwareRoundRobinPolicy prioritizes the configured local data center. RackAwareRoundRobinPolicy adds a local-rack preference inside that data center. Both can be used as the fallback for TokenAwareHostPolicy.

When ScyllaDB advertises a supported, nonzero shard configuration, the driver routes connections to shards and opens one connection per shard; ClusterConfig.NumConns has no effect. If server-side shard-aware drivers are disabled or valid sharding metadata is unavailable, the driver uses its normal connection pool and honors NumConns.

See Connecting to the cluster for shard-aware port and network requirements.

Was this page helpful?

PREVIOUS
Data types
NEXT
Retry policy configuration
  • Create an issue
  • Edit this page
ScyllaDB gocql driver
Search Ask AI
  • master
    • master
  • Quick start
  • Connecting to the cluster
    • Compression
    • Authentication
    • TLS
    • Client routes (PrivateLink / Private Service Connect)
  • Executing CQL statements
    • Paging
    • Batch statements
    • Lightweight transactions
    • Request timeouts
  • Data types
  • Load balancing
  • Retry policy configuration
  • Speculative execution
Docs Tutorials University Contact Us About Us
© 2026 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 14 Sep 2026.
Powered by Sphinx 9.1.0 & ScyllaDB Theme 1.9.3