Stateful operations in Kafka Streams, which represent the present state of an event stream, include aggregate, reduce, and even KTable, since KTable uses an update stream.
With event streams, a typical pattern is reporting—something like a dashboard application. You can do analytics over the longer term, but you also want to get a window into what's happening at the moment, especially with aggregations and counts. This will let you do alerting, for example.
Reporting usually requires the streaming system to write out its contents to an external database, where it is then queried by a UI layer for live use.
Kafka Streams, however, enables you to directly query the existing state of a stateful operation or a table, without the need of a SQL layer. You do this using interactive queries. They are live, you can see them as they happen, and you don't need to write their intermediate results to an external database. Interactive queries provide a materialized view of your operations in real time, simplifying your architecture.
KTables and aggregations are the eligible targets for Interactive Queries. To enable them, you name the state store via a Materialized object or use the Stores factory class; the Stores class has several methods that you can use to create a state store. (Learn more in the Hands On: Aggregations and Hands On: Processor API exercises.) You also need to provide the serving layer, usually a REST API, by setting the application.server configuration, specifying the host and port. Note that each instance shares metadata with all of the other applications that have the same application ID.
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.