0
0
Kafkadevops~10 mins

Topic configuration in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Topic configuration
Create Topic Request
Broker Receives Request
Validate Configurations
Apply Configurations
Topic Created with Settings
Topic Ready for Use
This flow shows how a Kafka topic is created with specific configurations, validated by the broker, and then made ready for use.
Execution Sample
Kafka
bin/kafka-topics.sh --create --topic my-topic --partitions 3 --replication-factor 2 --config cleanup.policy=compact
This command creates a Kafka topic named 'my-topic' with 3 partitions, replication factor 2, and a cleanup policy set to compact.
Process Table
StepActionConfiguration ParameterValueResult
1Receive create topic requesttopicmy-topicRequest accepted
2Validate partitionspartitions3Valid number of partitions
3Validate replication factorreplication-factor2Valid replication factor
4Apply topic configcleanup.policycompactConfig applied
5Create topic metadataN/AN/ATopic metadata created
6Topic creation completeN/AN/ATopic 'my-topic' ready for use
💡 Topic creation ends after all validations and configurations are successfully applied.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
topicN/Amy-topicmy-topicmy-topicmy-topic
partitionsN/A3333
replication-factorN/AN/A222
cleanup.policydefault (delete)default (delete)default (delete)compactcompact
topic statusnot createdvalid partitionsvalid replicationconfig appliedready
Key Moments - 3 Insights
Why must the replication factor be less than or equal to the number of brokers?
Because each replica must be on a different broker, so replication factor cannot exceed available brokers. See execution_table step 3 where replication factor is validated.
What happens if an invalid configuration is provided?
The broker rejects the topic creation request during validation steps, stopping the process before topic creation. This is implied in execution_table steps 2 and 3 validations.
Why is the cleanup.policy configuration important?
It controls how Kafka manages old data in the topic. Setting it to 'compact' changes retention behavior, as shown in step 4 where the config is applied.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'partitions' after step 2?
Adefault
B2
C3
DN/A
💡 Hint
Check the 'partitions' column in the execution_table row for step 2.
At which step is the cleanup.policy configuration applied?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look for the row mentioning 'Apply topic config' in the execution_table.
If the replication factor was set to 5 but only 3 brokers exist, what would happen during execution?
AValidation would fail at step 3
BTopic would be created with replication factor 5
CCleanup policy would be ignored
DPartitions number would be adjusted automatically
💡 Hint
Refer to key_moments about replication factor validation and execution_table step 3.
Concept Snapshot
Kafka Topic Configuration:
- Create topic with partitions and replication factor
- Validate configs on broker
- Apply configs like cleanup.policy
- Topic ready after successful creation
- Invalid configs cause creation failure
Full Transcript
This visual execution shows how Kafka creates a topic with specific configurations. First, the create topic request is received with parameters like topic name, partitions, replication factor, and configs. The broker validates the number of partitions and replication factor to ensure they are valid. Then, it applies configurations such as cleanup.policy. After all validations and configurations are applied, the topic metadata is created and the topic becomes ready for use. If any validation fails, the topic creation stops. Variables like partitions and replication factor are tracked through each step to show their values. Key moments clarify why replication factor must be less than or equal to the number of brokers, what happens with invalid configs, and the importance of cleanup.policy. The quiz questions help reinforce understanding of the steps and values during topic creation.