The data stored in Kafka Streams state stores could potentially be used outside the context of the applications. We could save it in an external database to be queried using a different application or microservice, but Kafka Streams provides us with an easier and faster solution: interactive queries.

Interactive queries allow us to query state stores and expose the results, usually through a REST API. We will run a simple stateful topology with a reduce operator, which concatenates received records to a single sentence by the record’s key.

Then, we will expose a REST endpoint that will retrieve values from the state store associated with the reduce operator by key.

We will be using the following code to start:

Get hands-on with 1200+ tech skills courses.