Self-tuning Kafka consumer for Spring Boot: PID-controlled throughput, circuit breaker, tracing
234
A Kafka consumer that tunes itself. Instead of guessing max.poll.records
and fetch.max.wait.ms and living with the consequences, this Spring Boot
consumer measures its own throughput and adjusts its settings continuously,
while staying up when the database underneath it does not.
docker pull devdownin/kafkaconsumerautotune:latest

Tuning a Kafka consumer is a guessing game. Set the batch size too low and you waste the resources you are paying for. Set it too high and you saturate your database — or trigger the rebalance storms that take a consumer group offline for minutes at a time. The right value is not a constant anyway: it changes with load, with network health, with how tired your database is at 3 a.m.
KafkaConsumerAutoTune stops treating it as a configuration problem and starts treating it as a control problem.
Think of how you hold a constant speed in a car. You do not fix the accelerator at one position — you adjust it against the slope and the wind. A PID controller does the same here:
The result is optimal throughput that holds regardless of load, instead of a number someone picked during a sprint two years ago.

Every adjustment is recorded with the measurement that triggered it, so the consumer's behaviour stays explainable rather than mysterious.
Circuit breaker. When the database goes down, the consumer does not keep hammering it. The breaker opens, the Kafka listener is paused — no lost messages, no error logs filling your disk — and it resumes on its own once the database is healthy.
Surgical fallback. One corrupted message should not cost you the other 99. When a batch fails, each message is retried individually: the healthy ones are persisted, and only the poison message is isolated and routed to the Dead Letter Topic.
From there it is yours to handle: inspect the headers and the error, fix the payload in place, and replay it — or discard it.

The image expects a Kafka broker and a database. The fastest way to see it running is the full stack from the repository:
git clone https://github.com/devdownin/kafkaconsumerautotune.git
cd kafkaconsumerautotune
docker compose up -d
That brings up Kafka, Oracle XE, Prometheus, Jaeger and the application. Then open:
The screenshots above show the interface with sample data; the figures in them are illustrative.
To run the image on its own, point it at your own infrastructure:
docker run -p 8080:8080 \
-e KAFKA_BOOTSTRAP_SERVERS=broker:9092 \
-e DB_HOST=oracle -e DB_SERVICE_NAME=XEPDB1 \
-e DB_USER=appuser -e DB_PASSWORD=... \
devdownin/kafkaconsumerautotune:latest
| Variable | Purpose |
|---|---|
KAFKA_BOOTSTRAP_SERVERS | Broker addresses |
DB_HOST, DB_SERVICE_NAME | Database host and service |
DB_USER, DB_PASSWORD | Database credentials |
KAFKA_SSL_TRUSTSTORE_PASSWORD | TLS truststore, when SSL is enabled |
KAFKA_SSL_KEYSTORE_PASSWORD, KAFKA_SSL_KEY_PASSWORD | TLS keystore and key |
LOG_PATH | Directory for the file log appender |
SPRING_PROFILES_ACTIVE | dev for the embedded database, or your own profile |
No credentials are baked into the image — every one of them is read from the environment.
| Tag | Points to |
|---|---|
latest | Most recent stable release |
1.0.1 | An exact release |
1.0, 1 | Latest patch and latest minor of that line |
sha-<commit> | One precise build, for pinning |
Pre-releases are published under their own version and never take latest.
Built from a multi-stage Dockerfile, it runs as an unprivileged user,
exposes port 8080, and ships a HEALTHCHECK against
/actuator/health so your orchestrator knows when it is genuinely ready.
Spring Boot 3.5 · Apache License 2.0
Source, issues and full documentation: https://github.com/devdownin/kafkaconsumerautotune
Content type
Image
Digest
sha256:0491a7315…
Size
284.6 MB
Last updated
about 1 month ago
docker pull compagnonsdudev/kafkaconsumerautotune