A speculative retry reissues an unfinished database query after a delay. The driver races the original and retry, returning whichever completes first, which can reduce latency when a node or network connection is temporarily degraded. section 10.5.3
Use speculative retries to trade additional request load for faster responses:
- Mark each eligible query as idempotent before enabling speculative execution; repeating it must leave the cluster in the same state. section 10.5.3
- Avoid non-idempotent operations such as appending to a list or generating an ID with uuid(), because retries can create repeated or different results. section 10.5.3
- Keep retry settings conservative when the cluster is already overloaded; extra attempts increase traffic and may worsen the situation. section 10.5.3
Driver configuration
A Python driver can use ConstantSpeculativeExecutionPolicy with a 0.1-second interval and two maximum attempts. The application then marks selected prepared statements, such as ALL_AUTHORS, GET_ARTICLE, and GET_AUTHOR, as idempotent.
