Overview
When a request fails, the retry policy decides:- Whether to retry the request
- Which target to retry on (same node or next node)
- Whether to change the consistency level
- Whether to ignore write errors
RetryPolicy Trait
Any type implementing theRetryPolicy trait can be used:
RetryDecision
The policy returns one of these decisions:DefaultRetryPolicy
The default policy retries when there’s a high chance a retry will succeed. It’s based on the DataStax Java Driver behavior.Usage
Retry Behavior
The default policy handles various error types:Connection Errors
- BrokenConnectionError: Retries on next node (idempotent queries only)
Server Errors
- Overloaded: Retries on next node (idempotent queries only)
- ServerError: Retries on next node (idempotent queries only)
- TruncateError: Retries on next node (idempotent queries only)
- IsBootstrapping: Always retries on next node
Unavailable Errors
- Unavailable: Retries once on next node (any query)
- Subsequent unavailable errors are not retried
Read Timeout
- ReadTimeout: Retries once on same node if:
- Received >= required responses
- data_present == false (only checksums received)
Write Timeout
- WriteTimeout: Retries once on same node if:
- Query is idempotent
- write_type == BatchLog
Stream Allocation
- UnableToAllocStreamId: Retries on next node
No Retry
These errors are never retried:- SyntaxError
- Invalid
- AlreadyExists
- AuthenticationError
- Unauthorized
- ConfigError
- ReadFailure
- WriteFailure
- Unprepared
- ProtocolError
FallthroughRetryPolicy
Never retries, immediately returns errors to the user:- Debugging and testing
- Applications handling retries at a higher level
- Latency-sensitive applications preferring fast failures
DowngradingConsistencyRetryPolicy
Retries with progressively lower consistency levels:Custom Retry Policy
Implement theRetryPolicy trait for custom behavior:
Request Information
The policy receives information about the failed request:Idempotency
A request is idempotent if applying it multiple times has the same effect as applying it once:- SELECT queries are idempotent
- INSERT/UPDATE with unique values are NOT idempotent
- INSERT/UPDATE with conditional clauses may be idempotent
Using with Execution Profiles
Attach a retry policy via execution profile:Metrics
The driver tracks retry statistics:Best Practices
- Use
DefaultRetryPolicyfor most applications - Mark idempotent queries appropriately
- Avoid
DowngradingConsistencyRetryPolicyunless you understand the risks - Consider timeouts in addition to retries
- Use
FallthroughRetryPolicyfor testing and debugging - Monitor retry metrics to detect issues
Interaction with Other Policies
- Load Balancing: Determines which nodes to retry on
- Speculative Execution: Retries happen in parallel with speculative requests
- Timeouts: Overall request timeout includes retry time
Next Steps
- Load Balancing - Control node selection
- Speculative Execution - Parallel retries
- Execution Profiles - Group execution options
