liveBook · Manning

Repartition topic

As explained in Kafka Streams in Action, Second Edition

A repartition topic is an intermediate Kafka topic that temporarily receives records so they can be redistributed according to their updated keys.

A repartition topic is an intermediate Kafka topic that receives records after their keys change, allowing Kafka Streams to redistribute them to partitions before key-dependent processing. This matters when a stream is regrouped for aggregation or joined with another stream. section 7.2.3

Track repartitioning through the topology:

  • selectKey changes the record key and marks the resulting stream as requiring repartitioning. section 7.2.3
  • A later processor that uses the key, such as groupByKey or a join, triggers repartitioning; Kafka Streams adds sink and source nodes around the repartition topic. section 7.2.3
  • Manual repartitioning clears the pending repartition flag, preventing later aggregations or joins from creating redundant repartition topics. section 7.2.3
  • Kafka Streams can also remove redundant repartition topics through optimizations; repartitioning still adds network round trips and processing latency. section 7.2.3 section 7.2.5
  • Increasing repartition partitions can increase task count only when keys are distributed relatively evenly. section 7.2.5

Explicitly creating a repartition topic

KStream<String, String> repartitioned = initialStream.repartition(Repartitioned.with(stringSerde, stringSerde).withName("multiple-aggregation").withNumberOfPartitions(10)); section 7.2.5

Figure 7.7 Redundant repartition nodes due to a key changing operation occurring previously in the topology
figure

Inspect the topology to see how an earlier key-changing operation can produce redundant repartition nodes before aggregation and joining. section 7.2.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains automatic and manual repartitioning, topology nodes, optimization, latency, naming, and partition-count trade-offs.
Examples
Uses selectKey, groupByKey, aggregation, joins, topology diagrams, and an explicit ten-partition Repartitioned configuration.
What it assumes
Assumes Kafka Streams streams and keys, while explaining that valid keys are required for grouping and joining.
What you can do after
Operate/configure Kafka Streams repartitioning and avoid redundant topics when building key-dependent processing topologies.
How it connects
Connects key changes with Kafka Streams, aggregations, joins, partitions, tasks, topologies, and stateful operations.

Also explained in

Compare how 2 books explain repartition topic →

Related concepts

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