...

/

Kafka Topic Partitions in Practice

Kafka Topic Partitions in Practice

Learn how to find the number of partitions in a topic, determine the number of partitions for new topics, and change the number of partitions of an existing topic.

Checking the number of partitions in a topic

How can we find out the number of partitions in a topic? Connect to the terminal below (the Kafka server will start running automatically). Then, create a topic like we did in previous lessons by running the following:

Press + to interact
/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --topic educative
Terminal 1
Terminal
Loading...

Now that we know about the existence of partitions, we can wonder how many partitions a topic created with this command have. The answer is usually 1, but it might be configured. Let’s verify this by running the following command:

Press + to interact
/kafka/bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic educative | head -n 1

In the output, we can see a few important properties of the topic, including PartitionCount, which is indeed 1! We used the same script that we used to create the topic (kafka-topics.sh), but instead ...