Status

Current state: Under Discussion

Discussion thread: https://lists.apache.org/thread/t4h273md03vzcbzk4r3bn86km8rnym66

JIRA:

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:

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 regardless of protocol or membership type.

Public Interfaces

The following public API is affected:

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:

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 (Dynamic Member)Classic Protocol (Static Member)Streams Protocol (Dynamic Member)Streams Protocol (Static Member)
close() (current) [1]Consumer REMAINConsumer REMAINConsumer LEAVEN/A
close() (new) [2]Consumer REMAINConsumer REMAINConsumer DEFAULT (LEAVE)Consumer DEFAULT (REMAIN)
close(REMAIN_IN_GROUP) (current)Consumer REMAINConsumer REMAINConsumer LEAVEN/A
close(REMAIN_IN_GROUP) (new)Consumer REMAINConsumer REMAINConsumer REMAINConsumer REMAIN
close(LEAVE_GROUP) (current)Consumer LEAVEConsumer LEAVEConsumer LEAVEN/A
close(LEAVE_GROUP) (new)Consumer LEAVEConsumer LEAVEConsumer LEAVEConsumer LEAVE

Legend:

  1. close() (current) internally delegates to close(REMAIN_IN_GROUP) 
  2. close() (new) internally delegates to close(DEFAULT) 

Compatibility, Deprecation, and Migration Plan

Test Plan

Rejected Alternatives

n/a