liveBook · Manning

Parallelism

As explained in Apache Kafka in Action

Parallel processing is the simultaneous execution of work across multiple processing units or workers.

A busy online store can outgrow a single log for every product update. Parallelism lets multiple workers process messages at the same time, but adding servers alone is not enough: the work must be divisible into independent pieces. Otherwise, spreading it across servers can initially make processing slower. section 4.2.1

Partitioning supplies those pieces. Product updates can go to separate partitions, while messages with the same key go to the same partition. This preserves the grouping needed for a product’s updates without requiring one order across every product. Likewise, a cab exchange can keep each city’s trip data together without requiring an order across cities. section 4.2.1

Try a two-partition product topic

Create a topic with `kafka-topics.sh --create --topic products.prices.changelog.multi-partitions --partitions 2 --replication-factor 1 --bootstrap-server localhost:9092`, then send product prices with `kafka-console-producer.sh --topic products.prices.changelog.multi-partitions --bootstrap-server localhost:9092`. A consumer reading from the beginning can display the six example updates in a different overall order from the producer input. For related updates, use producer keys instead: the keyed example sends repeated `coffee pads` updates with the same key. section 4.2.1

Kafka Streams extends this partition-based approach to processing. It assigns partitions of KStreams and KTables to tasks, its smallest processing units, then distributes tasks among application instances. Filtering a 12-partition topic creates 12 tasks: one instance handles all 12, while six instances typically handle two each. Tasks can also run on multiple threads within an instance, configured with `num.threads`. If an instance fails, tasks are redistributed to other 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.

The diagram traces how partition-based tasks spread across threads and instances, and how another instance takes over after a failure. section 12.6

Start by identifying which messages can be processed independently and which must stay together. Partition count determines the number of Kafka Streams tasks, so adding instances without adding partitions does not create more tasks. section 4.2.1 section 12.6

How Apache Kafka in Action covers it

How deep it goes
Explains partition-to-task assignment, instance distribution, threads, and failover; leaves Apache Flink’s different job management without detailed treatment.
Examples
Uses city-based trip data, product-price messages, a two-partition console demonstration, and a 12-partition filtering workload.
What it assumes
Builds from horizontal scaling and partitioning examples before introducing Kafka Streams tasks; assumes no prior Kafka Streams task model.
What you can do after
Operate/configure it by choosing independent partitioned work and distributing Kafka Streams tasks across instances and threads.
How it connects
Connects parallelism to partitioning, message keys, horizontal scaling, Kafka Streams tasks, and the Kafka Rebalance Protocol.

Also explained in

Compare how 38 books explain parallelism →

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.