Kafka Batching
GitHub Copilot — Kafka Streams Rebalancing and Retry Issue: Root Cause Analysis
Mode: ASK ONLY — STRICTLY NO CODE CHANGES
I am working on Jira PRGCRM-5120, migrating the OneCRM DataService Kafka consumers from Spring @KafkaListener to native Kafka Streams (KStream), while preserving the existing batching and business-processing behavior.
The implementation has been deployed in the CAE environment, and I have also performed local testing against the Confluent non-production cluster.
I am experiencing prolonged consumer-group rebalancing in local testing, particularly for OCP CustExp, along with downstream processing failures and retry-related exceptions.
I need a detailed, evidence-based root cause analysis of the actual current source code before making any modifications.
1. Inspect the complete implementation
Read and trace these classes and relevant supporting code:
ConfluentKafkaStreamsConfig.javaKafkaStreamsBatchingProcessor.javaConfluentKafkaMessageConsumer.javaConfluentKafkaStreamsRunner.javaOCPRecordProcessor.javaRIRecordProcessor.javaRelevant downstream service/client implementations, HTTP timeout and retry configurations
application.yml,application-cae.yml,application-local.ymlRelevant Kafka Streams and consumer configurations
Relevant existing unit and integration tests
Do not limit the analysis to individual methods. Trace the complete execution flow and interactions between classes.
2. Investigate the consumer-group rebalancing issue
Observed behavior:
CAE C1 consumer groups are generally stable and processing messages.
During local D1 testing, the CustExp group has remained in
Preparing Rebalancefor approximately 5–7 minutes or longer.CustReco and RI CAD behave differently and may remain stable.
Kafka logs contain:
Request joining group due to: group is already rebalancingChanges in consumer-group member counts
Failed to lock the state directory for task
An earlier test also produced
InconsistentGroupProtocolExceptionwhen incompatible consumer protocols shared a group.
Analyze:
Could the current code block Kafka Streams processing threads for too long?
Is downstream processing executed synchronously inside the Streams thread?
Could excessive processing time violate
max.poll.interval.ms?Where is
max.poll.interval.msconfigured, and does that property actually reach the Kafka Streams main consumer?Are consumer group IDs/application IDs configured correctly and uniquely for the three independent Kafka Streams applications?
Could multiple instances, duplicate applications, stream-thread configuration or stale group members cause repeated rebalancing?
Are Kafka Streams task migration and RocksDB state-directory locks contributing to the problem?
Is the original Spring Kafka listener completely disabled so that no incompatible consumer is joining the same group?
Could the current topology configuration or bean lifecycle cause additional problems?
Important: Distinguish normal Kafka rebalance messages from actual errors. Do not treat Preparing Rebalance, a member-count difference or a temporary state-directory lock as definitive proof of a code defect.
3. Analyze downstream processing and retry behavior
A previous local log showed:
DATA_SERVICE_ERROR_RUNTIME_EXCEPTION_RECORD_PROCESSED_OCPRetryExhaustedException: Retries exhaustedAn OCP CustExp processing operation lasting approximately 320 seconds
Failures involving downstream HTTP/Reactor processing
Trace the complete execution path from:
KStream → KafkaStreamsBatchingProcessor.process() → flushInternal() → processCollectedBatch() → batchConsumer.apply() → ConfluentKafkaMessageConsumer.receiveOCPFromConfluent() → OCPRecordProcessor.processOCPCustExpRecords() → downstream client.
Check:
Which exact downstream call can take several minutes?
What timeout and retry policies are configured?
Can retry/backoff settings cause Kafka Streams threads to remain blocked?
Are exceptions propagated correctly from downstream processing?
Can a downstream failure be caught and logged internally but still result in
truebeing returned to the batching processor?Can unsuccessful batches be retried repeatedly without adequate delay?
Could repeated processing of retained batches contribute to high processing time or rebalancing?
Is the implementation handling partial batch success correctly?
Could repeated retries cause duplicate downstream writes or events?
Identify actual code evidence for each finding. Do not assume the downstream service is unavailable without supporting evidence.
4. Review the custom batching implementation
Inspect KafkaStreamsBatchingProcessor.java, including:
init()process()flushInternal()collectPendingBatch()parseStateStoreEntry()processCollectedBatch()pendingRecordsCount()close()
Verify:
Whether batching works correctly for 100 records.
Whether the 1000 ms wall-clock punctuation is configured and executed correctly.
Whether a slow downstream call blocks subsequent processing or punctuation.
Whether
pendingRecordsCount()causes unnecessary RocksDB iterations or performance overhead.Whether
stateStore.put()andstateStore.delete()are handled correctly.Whether batches are deleted only when processing genuinely succeeds.
Whether failed batches can be retried safely.
Whether shutdown and rebalancing can result in repeated processing.
Whether record metadata, partition, offset and serialization/deserialization remain correct.
Whether there are risks of data loss or duplicate processing.
Also verify the implications of using:
Stores.persistentKeyValueStore(...) with .withLoggingDisabled().
Explain the impact on pending batch recovery after an application crash, pod restart or task migration. Do not assume that a persistent local RocksDB store guarantees recovery when its changelog is disabled.
5. Review Kafka Streams configuration
Examine buildStreamsPropertiesMap() and all three StreamsBuilderFactoryBean configurations.
Verify:
application.idnum.stream.threadsauto.offset.resetmax.poll.interval.msmax.poll.recordscommit.interval.msConsumer property inheritance
Any application-instance or group-ID conflicts
Whether different streams share any unintended local state directories
Kafka Streams state restoration and offset behavior
Explain why CAE group membership previously showed 18 members and subsequently showed 6 members. Determine what is confirmed by the configuration and what would require runtime instance information.
6. Identify unnecessary or risky code
Inspect the implementation for:
Unused classes or methods
Deprecated wrappers that are no longer called
Redundant configuration or duplicated logic
Unnecessary state-store iterations
Retry logic that may introduce operational instability
Incorrect exception handling
Inefficient synchronous operations inside Kafka Streams threads
Do not suggest removing persistent batching or rewriting the overall implementation unless you demonstrate a concrete technical reason.
7. Required output format
Provide the analysis in the following order.
A. Root cause summary
Explain the top 3 most likely causes of prolonged rebalancing, ranked by likelihood.
B. Code evidence
For every finding include:
Exact file path
Method name
Approximate line number
Relevant code snippet
Why the code may cause the observed issue
Whether the finding is CONFIRMED, LIKELY, POSSIBLE, or NOT YET VERIFIED
C. Rebalancing vs downstream failure
Explain whether these are one connected problem or two independent problems, based on available evidence.
D. Recommended minimal fixes
Recommend the smallest safe changes required, with:
Exact class/method
What should change
Why it should change
Expected benefit
Potential side effects
Required tests
Clearly separate code fixes from configuration fixes and infrastructure/downstream fixes.
E. Validation plan
Explain which specific runtime logs and Kafka consumer-group metrics are needed to confirm the root cause.
F. Final recommendation
Identify the single highest-priority issue to investigate or fix first, explaining why.
Strict instructions
ASK MODE ONLY.
DO NOT modify, create or delete any files.
DO NOT automatically generate patches.
DO NOT refactor the implementation.
DO NOT modify Kafka consumer groups, offsets, cluster resources or topics.
DO NOT change shared CAE configuration.
DO NOT recommend arbitrary timeout increases as a substitute for root cause analysis.
Do not claim runtime facts that cannot be verified from source code or supplied logs.
Preserve existing business behavior, batching requirements and consumer-group identities.
Focus on evidence-based diagnosis and minimal changes.
Start by examining the actual codebase and explain precisely where the rebalancing and retry problems could originate.
Comments
Post a Comment