concept state in category kafka

appears as: state, state
Kafka Streams in Action: Real-time apps and microservices with the Kafka Streams API

This is an excerpt from Manning's book Kafka Streams in Action: Real-time apps and microservices with the Kafka Streams API.

Note that KStream.foreach is stateless. If you need state to perform some action for each record, you can use the KStream.process method. The KStream.process method will be discussed in the next chapter when you add state to a Kafka Streams application.

In this chapter, you’ll extract the maximum amount of information from the Kafka Streams application. To get this level of information, you’ll need to use state. State is nothing more than the ability to recall information you’ve seen before and connect it to current information. You can utilize state in different ways. We’ll look at one example when we explore the stateful operations, such as the accumulation of values, provided by the Kafka Streams DSL.

Another example of state we’ll discuss is the joining of streams. Joining streams is closely related to the joins performed in database operations, such as joining records from the employee and department tables to generate a report on who staffs which departments in a company.

We’ll also define what the state needs to look like and what the requirements are for using state when we discuss state stores in Kafka Streams. Finally, we’ll weigh the importance of timestamps and look at how they can help you work with stateful operations, such as ensuring you only work with events occurring within a given time frame or helping you work with data arriving out of order.

Figure 4.4. The transformValues processor uses information stored in local state to update incoming records. In this case, the customer ID is the key used to retrieve and store the state for a given record.