MCQs on Kafka Topics and Partitions | Apache Kafka MCQs Questions

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

  1. 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
  2. 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
  3. 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
  4. Which configuration property sets the number of partitions for a topic?
    a) retention.ms
    b) num.partitions
    c) log.retention.hours
    d) segment.bytes
  5. 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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

  1. 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
  2. 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
  3. 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
  4. What is the default cleanup policy in Kafka?
    a) Archive
    b) Delete
    c) Compress
    d) Log compaction
  5. 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

  1. What is used to monitor Kafka topic performance?
    a) ZooKeeper logs
    b) Kafka Metrics and JMX
    c) Consumer configurations
    d) Broker replication settings
  2. Which tool provides a graphical interface for managing Kafka topics?
    a) Kafka CLI
    b) Kafka Manager
    c) Kafka Stream API
    d) Zookeeper UI
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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

QnoAnswer (Option with the text)
1b) A category or feed to which messages are published
2b) Using the kafka-topics command
3b) The topic and all associated messages are permanently deleted
4b) num.partitions
5b) Whether topics can be deleted from the Kafka cluster
6b) To divide data for parallel processing and scalability
7b) Using a partition key or round-robin approach
8b) The producer randomly selects a partition
9b) To ensure messages with the same key are sent to the same partition
10b) Key-based partitioning
11b) A policy that determines how long Kafka retains messages
12a) Using the log.retention.hours property
13b) The message is permanently deleted from the log
14c) retention.ms=-1
15b) Real-time streaming applications with low storage requirements
16a) Dividing log files into smaller, manageable segments
17a) log.segment.bytes
18a) Exceeding the retention period or log segment size
19b) Delete
20b) To retain the latest value for each key in a topic
21b) Kafka Metrics and JMX
22b) Kafka Manager
23b) Using the kafka-topics command with the --list option
24c) Messages in the topic are at risk of being lost
25c) Consumer lag
26c) By updating the topic replication factor
27a) The maximum replication delay allowed
28a) The oldest messages are deleted
29b) kafka-topics --describe
30b) Use Kafka-provided metrics with tools like Prometheus or Grafana

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top