Event Streaming with Kafka
Foundations of Event Streaming
Demo Creating First Topic in Kafka
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.
Prerequisites
- 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
- In the Kafka UI sidebar, select Topics.
- Click Add a topic.
- Enter Topic name:
kafka-lab
Warning
Topic names cannot contain spaces or special characters. Use hyphens (
-
) or underscores (_
) to separate words. - Configure the following options:
- Number of partitions:
1
- Message retention:
7 days
- Number of partitions:
- Leave the remaining settings at their defaults and click Create topic.
Why These Settings Matter
Configuration | Purpose | Example Impact |
---|---|---|
Number of partitions | Parallelism & distribution across brokers | More partitions = higher throughput |
Message retention | Duration Kafka retains messages before deletion | 7 days = temporary event storage |
2. Verifying Your Topic
After creation, you can confirm the topic details in the UI:
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
- Produce and consume messages with
kafka-console-producer.sh
andkafka-console-consumer.sh
. - Monitor topic metrics in the Kafka UI or Prometheus.
- Explore advanced topic configurations in the Kafka topic configuration reference.
That’s it for setting up your first Kafka topic! Proceed to the next lesson to start streaming data.
Watch Video
Watch video content