Apache Kafka is a highly popular distributed event streaming platform used for building real-time data pipelines and applications. Chapter 5 focuses on Kafka Topics and Partitions, covering essential concepts such as topic creation and management, partitioning strategies, retention policies, log segmentation, and topic monitoring. These Apache Kafka MCQs Questions are designed to help learners deepen their understanding of Kafka’s core functionality, ensuring better implementation and management of Kafka-based systems for real-time data processing.
Topic Creation, Deletion, and Configuration
What is a Kafka topic? a) A method for securing data b) A category or feed to which messages are published c) A consumer group in Kafka d) A storage mechanism for logs
How can you create a topic in Kafka? a) Using the kafka-console-producer command b) Using the kafka-topics command c) Using the kafka-server-start command d) By directly editing the metadata
What happens when you delete a Kafka topic? a) Messages in the topic are retained but not accessible b) The topic and all associated messages are permanently deleted c) The topic is archived for recovery later d) The topic is disabled but remains in the cluster
Which configuration property sets the number of partitions for a topic? a) retention.ms b) num.partitions c) log.retention.hours d) segment.bytes
What does the delete.topic.enable property control? a) The ability to delete messages in a topic b) Whether topics can be deleted from the Kafka cluster c) Retention period for deleted messages d) Security settings for topic deletion
Partitioning Strategies and Use Cases
What is the primary purpose of partitioning in Kafka? a) To replicate data across brokers b) To divide data for parallel processing and scalability c) To store data securely d) To log message offsets
How are messages assigned to partitions in Kafka? a) Based on message timestamps b) Using a partition key or round-robin approach c) By the producer’s IP address d) Based on consumer configurations
What happens if a partition key is not provided when publishing a message? a) The message is dropped b) The producer randomly selects a partition c) Kafka assigns the message to a default partition d) The broker rejects the message
What is a common use case for customizing partitioning strategies? a) To optimize data storage b) To ensure messages with the same key are sent to the same partition c) To improve message security d) To enable faster topic creation
Which partitioning strategy ensures messages with the same key always go to the same partition? a) Random partitioning b) Key-based partitioning c) Time-based partitioning d) Round-robin partitioning
Topic Retention Policies
What is a Kafka topic retention policy? a) A method for securing data in topics b) A policy that determines how long Kafka retains messages c) A configuration for topic deletion d) A consumer-based policy
How is the retention period for messages in a Kafka topic set? a) Using the log.retention.hours property b) By defining a partition key c) Using the delete.topic.enable property d) Through the consumer configuration
What happens when a message exceeds the retention period in Kafka? a) The message is archived to external storage b) The message is permanently deleted from the log c) The message is moved to a different partition d) The message is compressed
Which retention policy configuration allows a topic to retain data indefinitely? a) retention.bytes=-1 b) log.retention.hours=0 c) retention.ms=-1 d) segment.bytes=0
What is a typical use case for setting a short retention policy? a) Archiving historical data b) Real-time streaming applications with low storage requirements c) Long-term data analytics d) Multi-cluster replication
Log Segmentation and Cleanup
What is log segmentation in Kafka? a) Dividing log files into smaller, manageable segments b) Archiving logs to external storage c) Compressing older log data d) Removing log files after retention
Which property controls the size of a log segment in Kafka? a) log.segment.bytes b) log.retention.bytes c) num.partitions d) segment.cleanup.ms
What triggers log cleanup in Kafka? a) Exceeding the retention period or log segment size b) When consumers process all messages c) A manual cleanup request d) A broker restart
What is the default cleanup policy in Kafka? a) Archive b) Delete c) Compress d) Log compaction
What is the primary purpose of log compaction in Kafka? a) To delete old data from topics b) To retain the latest value for each key in a topic c) To compress log files for better storage utilization d) To enable faster partitioning
Monitoring and Managing Topics
What is used to monitor Kafka topic performance? a) ZooKeeper logs b) Kafka Metrics and JMX c) Consumer configurations d) Broker replication settings
Which tool provides a graphical interface for managing Kafka topics? a) Kafka CLI b) Kafka Manager c) Kafka Stream API d) Zookeeper UI
How can you list all topics in a Kafka cluster? a) Using the kafka-console-producer command b) Using the kafka-topics command with the --list option c) By querying ZooKeeper directly d) By restarting the Kafka broker
What happens if a topic becomes under-replicated? a) Kafka automatically deletes the topic b) The cluster performance improves c) Messages in the topic are at risk of being lost d) The topic cannot accept new messages
Which metric is used to track the lag between a producer and a consumer? a) Message offset b) Partition size c) Consumer lag d) Broker throughput
How can topic replication be increased in Kafka? a) By reconfiguring num.partitions b) By adding more brokers to the cluster c) By updating the topic replication factor d) By using ZooKeeper commands
What does the replica.lag.max.ms property control? a) The maximum replication delay allowed b) The maximum size of a replica c) The number of messages replicated per second d) The partitioning strategy
What happens when a topic exceeds its configured retention size? a) The oldest messages are deleted b) The topic automatically scales up c) The broker stops accepting new messages d) The topic is archived
Which command is used to describe a Kafka topic’s configuration? a) kafka-configs --describe b) kafka-topics --describe c) kafka-log --describe d) kafka-monitor --describe
What is the best practice for monitoring Kafka topics? a) Periodically check ZooKeeper logs b) Use Kafka-provided metrics with tools like Prometheus or Grafana c) Restart the Kafka broker daily d) Delete old topics regularly
Answers Table
Qno
Answer (Option with the text)
1
b) A category or feed to which messages are published
2
b) Using the kafka-topics command
3
b) The topic and all associated messages are permanently deleted
4
b) num.partitions
5
b) Whether topics can be deleted from the Kafka cluster
6
b) To divide data for parallel processing and scalability
7
b) Using a partition key or round-robin approach
8
b) The producer randomly selects a partition
9
b) To ensure messages with the same key are sent to the same partition
10
b) Key-based partitioning
11
b) A policy that determines how long Kafka retains messages
12
a) Using the log.retention.hours property
13
b) The message is permanently deleted from the log
14
c) retention.ms=-1
15
b) Real-time streaming applications with low storage requirements
16
a) Dividing log files into smaller, manageable segments
17
a) log.segment.bytes
18
a) Exceeding the retention period or log segment size
19
b) Delete
20
b) To retain the latest value for each key in a topic
21
b) Kafka Metrics and JMX
22
b) Kafka Manager
23
b) Using the kafka-topics command with the --list option
24
c) Messages in the topic are at risk of being lost
25
c) Consumer lag
26
c) By updating the topic replication factor
27
a) The maximum replication delay allowed
28
a) The oldest messages are deleted
29
b) kafka-topics --describe
30
b) Use Kafka-provided metrics with tools like Prometheus or Grafana