Skip to main content
Hello, and welcome back. In this lesson we’ll practice creating and inspecting Apache Kafka topics, configuring partitions and replication, and using the Kafka CLI tools to examine topic and broker metadata.

Lab environment

This lab runs in the KodeKloud environment where Kafka is already installed. Start by navigating to the Kafka installation directory to locate the binaries you’ll use:
The Kafka command-line scripts live in the bin directory. Change into bin to see helper scripts used for managing Kafka:
Example excerpt (truncated):

Quick reference: common Kafka CLI commands

Create a simple topic

Create a topic named demo_topic with the Kafka topics script:
What the flags mean:
  • --create — create a new topic.
  • --topic demo_topic — the topic name.
  • --bootstrap-server localhost:9092 — address of a broker to bootstrap against (replace with your cluster’s bootstrap server(s)).
Typical response:
You can also verify the newly created topic using a web UI such as Kafdrop or Confluent Control Center.
The image is a screenshot of a Kafdrop interface showing a Kafka Cluster Overview, including details about bootstrap servers, brokers, and topics.
Clicking the topic in the UI will display configuration and partition metadata.

Create a topic with partitions and replication

Partitions increase throughput and parallelism by spreading data across brokers. Create a topic with three partitions and a replication factor of 1:
Best practices:
Align partition counts to your throughput and consumer parallelism needs. More partitions can improve parallelism but add overhead for management, disk usage, and leader elections.
Replication factor must not exceed the number of available brokers. If you set --replication-factor greater than your broker count, topic creation will fail.

Describe a topic (inspect metadata)

To view topic metadata—partition count, leader, replicas, in-sync replicas (ISR), and per-topic configs—use the --describe option:
Sample output:

Change topic configuration (retention example)

Topic-level configurations can be updated with kafka-configs.sh. For example, set retention to 2 days (milliseconds):
Expected response:
Verify the change by re-describing the topic:
Sample updated output showing retention.ms:

Inspect broker API versions and broker list

To confirm broker identities and supported API versions (useful when troubleshooting compatibility or determining available features), run:
Sample output (truncated):
In this lab you have a single broker (sufficient for practicing topic creation and configuration changes). In production, use at least three brokers for fault tolerance and to support replication.

Further reading and resources

That is it for this lesson. See you in the next one.

Watch Video