Skip to main content
In this tutorial, you’ll learn how to create an Apache Kafka topic using the Kafka UI. A topic in Kafka is a named stream where related events are stored—a logical channel for appending and reading records. By the end of this lesson, you’ll have a topic named kafka-lab ready for producers and consumers.
  • A running Kafka cluster (e.g., via Docker).
  • Kafka UI configured and accessible.
  • Apache Kafka Documentation for deeper reference.

1. Creating a Topic via the Kafka UI

  1. In the Kafka UI sidebar, select Topics.
  2. Click Add a topic.
  3. Enter Topic name: kafka-lab
Topic names cannot contain spaces or special characters. Use hyphens (-) or underscores (_) to separate words.
  1. Configure the following options:
    • Number of partitions: 1
    • Message retention: 7 days
  2. Leave the remaining settings at their defaults and click Create topic.
The image shows a user interface for creating a new topic in Apache Kafka, with fields for topic name, number of partitions, cleanup policy, and other configuration options.

Why These Settings Matter

ConfigurationPurposeExample Impact
Number of partitionsParallelism & distribution across brokersMore partitions = higher throughput
Message retentionDuration Kafka retains messages before deletion7 days = temporary event storage

2. Verifying Your Topic

After creation, you can confirm the topic details in the UI:
The image shows a user interface for Apache Kafka, displaying details of a topic named "kafka-lab" with information on partitions, replication factor, and message count.
This overview displays:
  • Partitions: How many shards the topic is split into.
  • Replication factor: Number of copies for fault tolerance.
  • Message count: Total events stored so far.

3. (Optional) Creating a Topic via CLI

For automation or scripting, use the kafka-topics.sh tool:
bin/kafka-topics.sh \
  --create \
  --topic kafka-lab \
  --bootstrap-server localhost:9092 \
  --partitions 1 \
  --replication-factor 1 \
  --config retention.ms=$((7*24*60*60*1000))
This command mirrors the UI settings: one partition, one replica, and a seven-day retention period.

Next Steps

That’s it for setting up your first Kafka topic! Proceed to the next lesson to start streaming data.