Kafka partitions, producers and consumers by example

Mohammed Hewedy
2 min readApr 8, 2020
Photo by Markus Spiske on Unsplash

I will show 3 cases for running Kafka topic, first case is the topic has 2 partitions and 1 consumer group that has 2 consumers.

In the second case, the topic has 2 partitions, and we have 2 consumer groups each with 1 consumer.

In the third case, the topic has 2 partitions, and we have 2 consumer groups each with 1 consumer. moreover, we producer produce the message using keys (which control the target partition for the message).

The following are 3 diagrams illustrate the 3 cases, and it following by 2 screenshots of terminal windows illustrating the cases as well.

Case 1:

Case 2:

Case 3:

Here are the terminal windows that illustrate the above 3 cases:

This terminal window for case 1 and 2, sending messages with no key, and receive it with 2 consumer group, one of them has 2 consumers:

Click to enlarge

This terminal window for case 3:(sending messages with a key):

Click to enlarge

That’s all! Thanks.

--

--