A Kafka topic is a category or feed name to which records are published. It acts like a folder where messages are stored and organized.
Click to reveal answer
beginner
How do you create a Kafka topic using the command line?
You use the command kafka-topics.sh --create --topic <topic-name> --bootstrap-server <server> --partitions <num> --replication-factor <num> to create a topic.
Click to reveal answer
intermediate
What does the replication factor mean in Kafka topic creation?
Replication factor is the number of copies of the topic's data across different Kafka brokers. It helps with fault tolerance.
Click to reveal answer
intermediate
Why do you specify the number of partitions when creating a Kafka topic?
Partitions allow Kafka to split data into smaller parts for parallel processing and scalability. More partitions mean better throughput.
Click to reveal answer
beginner
Can Kafka topics be created automatically?
Yes, Kafka can auto-create topics when a producer or consumer tries to use a non-existing topic if the broker is configured to allow it.
Click to reveal answer
Which command option is used to create a Kafka topic?
A--delete
B--create
C--list
D--describe
✗ Incorrect
The option '--create' is used with kafka-topics.sh to create a new topic.
What does the replication factor control in a Kafka topic?
ANumber of copies of data across brokers
BNumber of topic partitions
CSize of each message
DRetention time of messages
✗ Incorrect
Replication factor controls how many copies of the topic data exist on different brokers for fault tolerance.
Why are partitions important in Kafka topics?
AThey control message size
BThey encrypt messages
CThey allow parallel processing and scalability
DThey delete old messages
✗ Incorrect
Partitions split data to allow multiple consumers to read in parallel, improving throughput.
What happens if you try to produce to a non-existing topic and auto-creation is enabled?
ATopic is automatically created
BMessage is rejected
CProducer crashes
DMessage is lost
✗ Incorrect
Kafka can auto-create the topic if configured, so the message is accepted.
Which of these is NOT a parameter when creating a Kafka topic?
ATopic name
BNumber of partitions
CReplication factor
DMessage format
✗ Incorrect
Message format is not specified during topic creation; it is handled by producers and consumers.
Explain how to create a Kafka topic using the command line and why you need to specify partitions and replication factor.
Think about how Kafka handles data distribution and fault tolerance.
You got /3 concepts.
Describe what happens when Kafka auto-creates a topic and when this feature might be useful or risky.
Consider convenience versus control.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of a topic in Kafka?
easy
A. To compile Java programs
B. To store user login credentials
C. To manage database connections
D. To organize messages like folders organize files
Solution
Step 1: Understand Kafka topic role
A Kafka topic is a category or feed name to which messages are published.
Step 2: Compare options with topic function
Only To organize messages like folders organize files correctly describes topics as organizing messages like folders organize files.
Final Answer:
To organize messages like folders organize files -> Option D
Quick Check:
Topic = Organize messages [OK]
Hint: Topics group messages like folders group files [OK]
Common Mistakes:
Confusing topics with databases
Thinking topics store user data
Mixing topics with program compilation
2. Which command correctly creates a Kafka topic named orders with 3 partitions and replication factor 2?
A. Creates a topic named 'sales' with 1 partition and replication factor 5
B. Fails because replication factor cannot be 1
C. Creates a topic named 'sales' with 5 partitions and replication factor 1
D. Fails due to missing zookeeper connection
Solution
Step 1: Analyze command parameters
The command specifies topic 'sales', 5 partitions, replication factor 1, and bootstrap server.
Step 2: Understand Kafka topic creation rules
Replication factor 1 is valid (means no replicas), and partitions set to 5 means 5 partitions created.
Final Answer:
Creates a topic named 'sales' with 5 partitions and replication factor 1 -> Option C
Quick Check:
Partitions=5, Replication=1 [OK]
Hint: Replication factor 1 means no replicas, partitions as given [OK]
Common Mistakes:
Confusing partitions with replication factor
Assuming replication factor 1 is invalid
Expecting zookeeper connection with bootstrap-server
4. You tried to create a topic with this command:
kafka-topics.sh --create --topic logs --partitions two --replication-factor 3 --bootstrap-server localhost:9092
What is the error?
medium
A. Missing --create flag
B. Invalid number for partitions: 'two' should be a number
C. Replication factor cannot be 3
D. Bootstrap server address is incorrect
Solution
Step 1: Check partitions parameter
The partitions option expects a number, but 'two' is a word, causing a syntax error.
Step 2: Verify other parameters
Replication factor 3 and bootstrap server are valid; --create flag is present.
Final Answer:
Invalid number for partitions: 'two' should be a number -> Option B
Quick Check:
Partitions must be numeric [OK]
Hint: Partitions must be numeric, not words [OK]
Common Mistakes:
Using words instead of numbers for partitions
Assuming replication factor 3 is invalid
Forgetting --create flag
5. You want to create a Kafka topic for a critical system that must not lose messages and should handle high load. Which topic creation settings are best?
hard
A. Partitions: 10, Replication factor: 3
B. Partitions: 1, Replication factor: 1
C. Partitions: 5, Replication factor: 1
D. Partitions: 3, Replication factor: 2
Solution
Step 1: Understand requirements for critical system
High load needs many partitions for parallelism; no message loss needs high replication factor.
Step 2: Evaluate options
Partitions: 10, Replication factor: 3 has 10 partitions (high load) and replication factor 3 (high safety). Others have fewer partitions or lower replication.
Final Answer:
Partitions: 10, Replication factor: 3 -> Option A
Quick Check:
High load + safety = many partitions + high replication [OK]