CCDAK practice question 14 of 25

A consumer is configured with enable.auto.commit=false. What happens when close() is called on the consumer object?

Full set: 150 questions
Answer options
A: The uncommitted offsets are committed
B: A rebalance in the consumer group will happen immediately Correct answer
C: The group coordinator will discover that the consumer stopped sending heartbeats. It will cause rebalance after session.timeout.ms
Correct Answer:
B. A rebalance in the consumer group will happen immediately
Explanation

Calling the close() method on a Kafka consumer instance initiates a graceful shutdown. As part of this process, the consumer sends a LeaveGroup request to the group coordinator. Upon receiving this request, the coordinator immediately triggers a rebalance of the consumer group to reassign the partitions from the departing consumer to the remaining active members. This ensures that processing continues with minimal delay and avoids the need to wait for a session timeout to detect a failed consumer. The enable.auto.commit=false setting does not alter this graceful shutdown behavior.

Why Incorrect

A. The uncommitted offsets are committed The close() method only commits offsets if enable.auto.commit is set to true. The question explicitly states this configuration is false.
C. The group coordinator will discover that the consumer stopped sending heartbeats. It will cause rebalance after session.timeout.ms This describes an ungraceful shutdown or failure (e.g., a crash). A graceful shutdown via close() proactively notifies the coordinator, triggering an immediate rebalance. ---

References

1. Apache Kafka Documentation (Javadoc for KafkaConsumer): The official Javadoc for the org.apache.kafka.clients.consumer.KafkaConsumer class specifies the behavior of the close() method. It states, "If auto-commit is enabled, this will commit the current offsets." This implies that if auto-commit is disabled, no commit occurs on close, invalidating option A. The method's purpose is to "part with the group," which is the graceful leave action described in option B.

Source: Apache Kafka 3.x Javadoc, org.apache.kafka.clients.consumer.KafkaConsumer.close() method description.

2. Confluent Documentation, "Rebalances": This document explains the consumer group protocol. It distinguishes between graceful and ungraceceful shutdowns. "When a consumer is shut down cleanly, it will notify the group coordinator that it is leaving the group. The group coordinator will immediately trigger a rebalance to re-assign its partitions to another consumer in the group." This directly supports option B and refutes option C.

Source: Confluent Documentation -> Apache Kafka -> Rebalances -> "What is a rebalance?" section.

3. "Kafka: The Definitive Guide, 2nd Edition" by Narkhede, N., Shapira, G., & Palino, T. (O'Reilly Media, 2021): This authoritative book, written by Kafka's creators, details the consumer group protocol.

Source: Chapter 4, "Kafka Consumers: Reading Data from Kafka", Section "The Group Coordinator and Consumer Groups". It states: "When the consumer wishes to leave the group, it will notify the coordinator. The coordinator will start a rebalance..." This confirms the immediate rebalance on a clean exit. The subsequent section, "Detecting Consumer Failures," explains that the session.timeout.ms mechanism is for failures, not clean shutdowns.

Scroll to Top