Synchronous and asynchronous query execution

Queries can be executed against the database synchronously or asynchronously. The correct execution paradigm to use depends on the application.

Synchronous execution

Synchronous query execution is blocking, meaning nothing else in the application proceeds until the result from the query is returned. The application blocks for the entire round trip, from when the query is first sent to the database until the results are retrieved and returned to the application.

The advantage of synchronous queries is that it is simple to tell when a query completes, so the execution logic of the application is easy to follow. However, synchronous queries cause poor application throughput.

Synchronous query execution for drivers

C/C++

C#

Java

Node.js

PHP

Python

Ruby

Asynchronous execution

Asynchronous query execution is more complex. An asynchronous query execute call does not block for results. Instead, a future is immediately returned from the asynchronous execute call. A future is a placeholder object that stands in for the result until the result is returned from the database. Depending on the driver and feature set of the language, this future can facilitate asynchronous processing of results. This typically allows high throughput.

Asynchronous execution example
Asynchronous execution example
Asynchronous query execution for drivers

C/C++

C#

Java

Node.js

PHP

Python

Ruby

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com