liveBook · Manning

Kafka Streams

As explained in Apache Kafka in Action

Kafka Streams is a Java library for building applications that process Kafka records as streams.

Suppose records arrive in Kafka and another application needs a filtered or transformed stream. Kafka Streams is a Kafka-native Java library for that processing. A Streams application acts as both consumer and producer: it reads records, processes them, and writes results back to Kafka. It can filter, transform, and merge data rather than requiring a hand-built combination of consumers and producers. section 4.3.3 section 12.1.1

That read–process–write pattern raises a reliability question: output may span topic partitions, while progress is recorded in consumer offsets. Those writes need to be coordinated for exactly-once processing. Kafka Streams provides a library for this common pattern; merely writing a consumer and producer does not resolve the coordination problem. section 5.2.1

Filtering a 12-partition topic

Kafka Streams creates one task per partition, so filtering a 12-partition topic creates 12 tasks. One application instance handles all 12; with six instances, each typically handles two. Adding instances distributes existing tasks rather than creating more of them. If an instance fails, Kafka’s rebalance protocol assigns its tasks to surviving instances. section 12.6

Figure 12.13 Kafka Streams applications are divided into tasks that are distributed across different threads on different instances. If an instance fails, another instance takes over the tasks.
A screenshot of a computer game

AI-generated content may be incorrect.

See how tasks are distributed across instance threads and reassigned after an instance fails. section 12.6

For production use, keep the work and its operating cost in view:

  • Tasks are the smallest processing units, and their count depends on the partitions being processed. Tasks can run across instances and across threads within an instance; configure the latter with num.threads. section 12.6
  • Monitor failed threads, processing rates and duration, and dropped records. Repeated task termination and recreation outside startup, shutdown, or topology changes calls for investigation. section 15.3.4
  • Avoid assuming every transformation belongs in Streams. Consolidating raw core-system data may require so many joins and state stores that the application becomes difficult to operate; complex joins in a separate relational database, followed by CDC, may be preferable. section 18.2

How Apache Kafka in Action covers it

How deep it goes
Explains partition-to-task assignment, instance failover, thread configuration, and monitoring; flags complex joins as an operational limit.
Examples
Illustrates a 12-partition filter spread across one or six instances and a core-system consolidation burdened by complex joins.
What it assumes
Uses Kafka producer, consumer, topic, and partition concepts while introducing Streams as the Java library for processing their records.
What you can do after
Operate/configure it by distributing partition-bound tasks across instances and threads, then monitoring failures and processing behavior.
How it connects
Connects Kafka Streams to producers, consumers, partitions, consumer offsets, Kafka Connect, Apache Flink, and change data capture.

Also explained in

Compare how 3 books explain Kafka Streams →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.