Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Status

Current state:   [One of "Under Discussion", "Accepted", "Rejected"]

Discussion thread: here [Change the link from the KIP proposal email archive to your own email thread]

JIRA: here [Change the link from KAFKA-1 to your own ticket]

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

Describe the problems you are trying to solve.

Public Interfaces

Briefly list any new interfaces that will be introduced as part of this proposal or any existing interfaces that will be removed or changed. The purpose of this section is to concisely call out the public contract that will come along with this feature.

A public interface is any change to the following:

  • Binary log format

  • The network protocol and api behavior

  • Any class in the public packages under clientsConfiguration, especially client configuration

    • org/apache/kafka/common/serialization

    • org/apache/kafka/common

    • org/apache/kafka/common/errors

    • org/apache/kafka/clients/producer

    • org/apache/kafka/clients/consumer (eventually, once stable)

  • Monitoring

  • Command line tools and arguments

  • Anything else that will likely break existing users in some way when they upgrade

Proposed Changes

...

Motivation

KafkaStreams currently allows users to control shutdown behavior via CloseOptions, with two existing values: LEAVE_GROUP and REMAIN_IN_GROUP. When no options are provided, KafkaStreams.close() implicitly uses REMAIN_IN_GROUP.

With the introduction of the Streams Protocol (KIP-1071), this implicit default has become semantically inconsistent:

  • Classic Protocol: REMAIN_IN_GROUP behaves as expected, the member stays in the consumer group, enabling a faster rebalance upon restart.
  • Streams Protocol (KIP-1071): The member unconditionally leaves the group regardless of this setting, since remaining in the group provides no benefit for non-static members under the new protocol.

To resolve this ambiguity and provide a cleaner API for the long term, we should introduce a new enum value: CloseOptions.DEFAULT. This allows the "default" behavior to be adaptive based on the underlying protocol, while strictly reserving REMAIN_IN_GROUP for when the user explicitly requests that intent.

Public Interfaces

The following public API is affected:

  • org.apache.kafka.streams.CloseOptions — new enum value DEFAULT will be added.
  • KafkaStreams.close() — default behavior will be updated to use CloseOptions.DEFAULT.

Proposed Changes

1. Add CloseOptions.DEFAULT

A new enum constant DEFAULT is added to org.apache.kafka.streams.CloseOptions. This value signals that the runtime should choose the most appropriate closing behavior based on the active protocol. 

2. Update KafkaStreams.close() Behavior

Currently, KafkaStreams.close() internally delegates to close(CloseOptions.REMAIN_IN_GROUP). This will be changed to delegate to close(CloseOptions.DEFAULT), making the no-arg form truly protocol-agnostic.

3. Define Logic for CloseOptions.DEFAULT

When CloseOptions.DEFAULT is used, the behavior adapts based on the active protocol:

  • Classic Protocol → maps to Consumer CloseOptions.REMAIN_IN_GROUP (preserves existing behavior; no regression for current users).
  • Streams Protocol (KIP-1071) → maps to Consumer CloseOptions.DEFAULT (leaves the group for dynamic members, consistent with protocol design).

4. Redefine CloseOptions.REMAIN_IN_GROUP

REMAIN_IN_GROUP transitions from being the implicit default to an explicit user intent. When specified, it will always map to Consumer CloseOptions.REMAIN_IN_GROUP, regardless of the active protocol. Users who rely on this specific behavior under the Streams Protocol must now opt in explicitly.

5. Implement Consumer CloseOptions.REMAIN_IN_GROUP support in KIP-1071

Currently, the Streams Protocol implementation in StreamsGroupHeartbeatManager does not honor REMAIN_IN_GROUP. This gap must be addressed as part of this KIP to ensure the option functions correctly end-to-end under KIP-1071: Streams Rebalance Protocol#Compatibility,DeprecationandMigrationPlan.

Behavior Matrix

Streams CloseOptionClassic Protocol BehaviorStreams Protocol (KIP-1071) Behavior
DEFAULT (New)Uses Consumer REMAINUses Consumer DEFAULT
REMAIN_IN_GROUPUses Consumer REMAINUses Consumer REMAIN
LEAVE_GROUPUses Consumer LEAVEUses Consumer LEAVE

Compatibility, Deprecation, and Migration Plan

  • What impact (if any) will there be on existing users?
  • If we are changing behavior how will we phase out the older behavior?
  • If we need special migration tools, describe them here.
  • When will we remove the existing behavior?

Test Plan

Describe in few sentences how the KIP will be tested. We are mostly interested in system tests (since unit-tests are specific to implementation details). How will we know that the implementation works as expected? How will we know nothing broke?

Rejected Alternatives

  • Classic Protocol users: No behavioral change. KafkaStreams.close() continues to result in the member remaining in the group, as before.
  • Streams Protocol users: The behavior of the no-arg close() becomes cleaner and consistent with the protocol's design intent. Users who explicitly need REMAIN_IN_GROUP semantics under the Streams Protocol must now pass that option explicitly.
  • No existing enum values are removed or deprecated. The new DEFAULT value is purely additive.

Test Plan

  • All existing regression tests must continue to pass without modification.
  • New unit tests should cover:
    • The routing logic of CloseOptions.DEFAULT for both protocol variants.
    • REMAIN_IN_GROUP behavior under the Streams Protocol via StreamsGroupHeartbeatManager.
  • New integration tests should cover end-to-end close behavior for all three CloseOptions values under both the Classic and Streams protocols.

Rejected Alternatives

n/aIf there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.