Kafka Broker
Topic Creation
Distributed Systems
Data Streaming
Apache Kafka

Kafka Topic creation upon specific broker

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Apache Kafka is a distributed streaming platform capable of handling trillions of events a day. Primarily, Kafka is used for building real-time streaming data pipelines and applications that adapt to the data streams. One of the fundamental concepts in Kafka is the topic, which is essentially a category or feed name to which records are published.

Understanding Kafka Topics

A Kafka topic is a user-defined category through which Kafka maintains feeds of messages in the form of records. Topics in Kafka are always multi-subscriber; that is, a topic can have zero, one, or many consumers that subscribe to the data written to it.

Key Characteristics

  • Partitioned: Topics are divided into partitions, allowing for data to be scaled horizontally across multiple Kafka brokers.
  • Replicated: Each partition can be replicated across multiple Kafka brokers to ensure fault tolerance and high availability.
  • Immutable Sequence: Records in a partition are immutable and are identified by their offset.

Creating Topics on Specific Broker

While you cannot directly create a topic on a specific Kafka broker — since topics are properties of the entire Kafka cluster — you can influence where partitions of a topic reside through careful broker and topic configuration management.

Step-by-Step Guide to Create a Topic

  1. Pre-Requisites: Ensure that Kafka is installed and that your cluster is up and running. Make sure you have access to the Kafka command line tools.
  2. Command Line Creation: You can use the Kafka command line tool to create topics. The basic syntax is:
bash
   kafka-topics.sh --create --bootstrap-server <broker-list> --replication-factor <number> --partitions <number> --topic <topic-name>

Here, <broker-list> is a list of brokers in the format host1:port1,host2:port2.

Example:

bash
   kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 3 --topic my-example-topic
  1. Validate Topic Creation: Check if the topic has been created successfully with the describe command:
bash
   kafka-topics.sh --describe --topic my-example-topic --bootstrap-server localhost:9092

Configuring Topic Placement

While you can't specify a "specific" broker for a topic, you can use the concept of broker rack awareness to control the distribution of topic partitions across different physical racks or brokers.

Broker Rack Awareness Setup

You need to configure the broker.rack parameter in the broker’s config file (e.g., server.properties). Assign each broker a rack ID (which can also simulate a logical grouping of brokers).

properties
broker.rack=Rack1

Then update the topic's configuration to spread the partition across different racks using the replica.selector.class for custom control.

Summary Table of Kafka Topic Commands

CommandDescriptionExample Command
Create TopicCreate a new topic in the Kafka cluster.kafka-topics.sh --create
Describe TopicGet details about one or more topics.kafka-topics.sh --describe
List TopicsList all topics in the cluster.kafka-topics.sh --list
Delete TopicDelete a topic from the cluster.kafka-topics.sh --delete

Best Practices for Topic Creation

  • Plan Capacity: Understand the message size and rate to appropriately configure partitions and replicas.
  • Monitor: Regularly monitor topic and partition health across the cluster.
  • Security: Configure ACLs for topic authorization to control who can produce and consume data.

Understanding topic creation and management in Kafka is crucial for effective data stream management in large-scale environments. This knowledge ensures not only performance but also durability and fault tolerance of your data streams.


Course illustration
Course illustration

All Rights Reserved.