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 Speculative execution
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/speculative-execution.md.

Speculative execution¶

Speculative execution starts another execution branch when an earlier branch has not completed after a configured delay. It can reduce tail latency, but extra executions increase cluster load. The first branch to finish, whether successfully or with an error, determines the result returned to the caller. The driver then cancels sibling work where cancellation is observed; a request already sent to the server can continue running there.

Configure it for one query:

query := session.Query(statement, values...).
	Idempotent(true).
	SetSpeculativeExecutionPolicy(&gocql.SimpleSpeculativeExecution{
		NumAttempts:  1,
		TimeoutDelay: 100 * time.Millisecond,
	})

NumAttempts counts additional attempts beyond the initial request. A value of 1 permits one speculative attempt, for up to two concurrent requests while the initial attempt remains pending. NumAttempts must be non-negative; zero disables speculative execution. When it is positive, TimeoutDelay must be greater than zero; otherwise query execution panics.

Use speculative execution only for idempotent operations. Choose conservative delays from measured production latency instead of starting parallel attempts for ordinary response times.

The context attached with Query.WithContext is passed to driver operations that observe cancellation, including waits for speculative attempts. It does not bound the complete execution: requests already sent can continue running on the server, and speculative workers can remain blocked in retry-policy methods that do not observe the context. Each attempt remains subject to the query’s request timeout. See Request timeouts.

Was this page helpful?

PREVIOUS
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