Course: ksqlDB 101

Push Queries and Pull Queries

2 min
Allison WaltherIntegration Architect (Course Presenter)
Robin MoffattStaff Developer Advocate (Course Author)

Push Queries and Pull Queries

There are two ways of querying data in ksqlDB: push queries and pull queries.

  • Push queries are identified by the EMIT CHANGES clause. By running a push query, the client will receive a message for every change that occurs on the stream (that is, every new message).
  • Pull queries return the current state to the client, and then terminate. In that sense, they are much more akin to a SELECT statement executed on a regular RDBMS. They can only be used against ksqlDB tables with materialized state, that is, a table in which there is an aggregate function. Currently, tables declared against an existing Apache Kafka topic cannot be queried with a pull query (as of ksqlDB v0.15 / February 2021).

Applying this to the aggregate ORDERS_PER_HOUR_BY_MAKE table from Stateful Aggregations (Materialized Views), we can query it both ways. A pull query returns the current state of the aggregate:

pull-query-returns

New events will update the aggregate, but we’d need to execute the pull query again in order to see the new value:

aggregate-two

Compare this to a push query against the same table. Here, we receive a continuous stream of all changes to the aggregate:

KSQLDB PUSH QUERY

Use the promo code KSQLDB101 to get $101 of free Confluent Cloud usage

Be the first to get updates and new content

We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.