This is a simple, plain Kafka Streams application doing a simple record transformation configured using EXACTLY_ONCE_V2.
configurationParameters.put(StreamsConfig.PROCESSING_GUARANTEE_CONFIG, StreamsConfig.EXACTLY_ONCE_V2);
The error I see is as follows. If I remove the EXACTLY_ONCE_V2 setting mentioned above, this error vanishes, and the streams application runs for days without errors. The error log is:
[ERROR] 2021-11-27 18:10:23.141 [kafka-producer-network-thread | id-mapping-app-1eede139-ace6-4aff-9e94-ca508cb9c98d-StreamThread-1-producer] RecordCollectorImpl - stream-thread [id-mapping-app-1eede139-ace6-4aff-9e94-ca508cb9c98d-StreamThread-1] task [0_11] Error encountered sending record to topic data-records-output for task 0_11 due to: org.apache.kafka.common.errors.InvalidProducerEpochException: Producer attempted to produce with an old epoch. Written offsets would not be recorded and no more records would be sent since the producer is fenced, indicating the task may be migrated out
The application is using Kafka Streams 3.0.0, which is the latest as of this writing. Gradle style Maven coordinates are: org.apache.kafka:kafka-streams:3.0.0
The Kafka brokers are running Kafka 2.8.0 under Strimzi 0.23.0 on Kubernetes.
I also experienced the exact same error message with a similar application using the Flink framework instead of Kafka Streams:
Flink 1.13.2: `ProducerFencedException: Producer attempted an operation with an old epoch`
In both Flink and Kafka Streams, disabling exactly once makes the error go away. If I turn on exactly once processing the error occurs.