Catalogue / xavyrrademaker-2021-kafka-long-running-jobs

A project runs long jobs on Kafka consumers, hits rebalance trouble when adding replicas, and pauses consumers one event at a time

Not named in the source. Long-running jobs in an event-driven Java and Spring microservice landscape on Apache Kafka.

Organisation
Not named in the source
Evidence
Reported from production
System
Long-running jobs in an event-driven Java and Spring microservice landscape on Apache Kafka
Source
Dealing with long-running jobs using Apache Kafka

CodeX (Medium), published 2021-07-13

Architecture

Event-driven microservices, mostly Java with Spring and some Python, talk through Apache Kafka. Under time pressure no new components were added: long-running jobs became new microservices consuming events from Kafka.

Near: We used an event-driven microservice architecture mostly | Near: we have also implemented some of them

Figures, as the source states them

FigureAs statedNoteWhere
Spring Kafka default maximum interval between polls5 minutesLibrary default, not a project measurementNear: by default configured to poll at least

Records

Failure#f1

Jobs longer than the Kafka poll interval caused consumers to leave the group once replicas were added

xavyrrademaker-2021-kafka-long-running-jobs#f1 at corpus version 26a1b3a7e3dd
Trigger

Things seemed fine at first, but issues began when the team increased the number of replicas of their microservices.

Near: we started to run into issues when

How it failed

By default a Spring Kafka consumer processes each event on its polling thread and must poll at least every 5 minutes. In the author's illustration, a job running longer blocks the poll, the consumer is marked dead and leaves the group, the rebalance hands its uncommitted event to another consumer, and that one also overruns, so the same event is processed again.

Section: Problem

Why defences did not hold

Kafka consumers' default configuration is built for many fast jobs, not a few long-running ones, and a consumer cannot poll again until it has finished processing its current event.

Near: These issues had everything to do with | Section: Problem

Impact

The author describes the effect with an illustrative example: the same event is processed more than once, wasting time and resources and risking an inconsistent state if events are not idempotent.

Near: This means that event ETP1 will be

Fix

After research the team got it working without changing the tools in their landscape, using different solutions for different types of job; for resource-intensive jobs handled by pausing the consumer, they limited each poll to 1 record.

Near: After doing some research, we managed to | Near: In resource intensive jobs where we used

Reviewer's notes

The post explains the failure through a generic two-consumer example rather than a timeline of the project's own incident; job durations in that example are illustrative.

The reviewer's reading, not the source's claim

Decision#d1

For resource-heavy long jobs, pause the consumer, run the job on a worker thread, poll one record at a time and spread jobs round robin

xavyrrademaker-2021-kafka-long-running-jobs#d1 at corpus version 26a1b3a7e3dd
Chosen

For resource-intensive jobs the consumer is paused while a worker thread runs the job and a callback resumes it. The team limited each poll to 1 record and used round robin partitioning so long jobs spread roughly evenly over all replicas in the consumer group.

Section: Pause consumer with threading and callbacks | Section: Limit number of events consumed per poll | Section: Partitioning strategy

What forced it

Issues started once the team increased the number of replicas; the author explains them as long jobs blocking the consumer's polling loop, so that, in his illustration, consumers drop out of the group and events are reprocessed.

Near: we started to run into issues when | Section: Problem

Reasoning

Polling one record keeps the time a consumer is paused to a minimum and gives the best chance of parallelism when replicas are scaled up while others are busy. Where order of execution does not matter, round robin spreads long jobs evenly; the sticky partitioner, the default for keyless producing from Kafka 2.4, is not helpful with a few long-running jobs.

Near: This forces the consumer to process 1 | Section: Partitioning strategy

What worked before

Long jobs ran on the consumer thread with Kafka's default consumer settings, which seemed to go well at first.

Near: Even though all seemed to go well at

Reviewer's notes

The post presents five approaches mostly as general advice and says solutions varied by job type; only round robin partitioning and the one-record limit with pausing are stated as the project's own choices.

The reviewer's reading, not the source's claim

Review

Extracted by
Claude (feed 70)
Human review
Not started. Status recorded on 2026-12-02.