Apache Kafka Tutorial 0/111 lessons ~6 min read Lesson 68

    Slow Consumers

    What is Slow Consumers?

    Course progress0%
    Focus
    9 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    What is Slow Consumers? Slow consumers fall behind because processing is slow, downstream dependencies block, max.

    Understanding the topic

    What happens — Slow Consumers:

    • Identify topic, partition, offset scope.
    • Check broker health and ISR.
    • Inspect consumer errors and deploys.
    • Remediate: scale, DLT, replay, or fix schema.
    TermDescription
    Consumer groupA set of consumers sharing work — each partition goes to at most one member at a time.
    OffsetPosition in a partition log — where this consumer last read.
    Poll loopconsumer.poll() fetches batches of records; keep processing faster than max.poll.interval.ms.
    CommitSaving offset to Kafka after processing — sync or async, manual or auto.
    LagDifference between latest offset and consumer offset — key health metric.

    Visual explanation

    Pipeline view:

    text
    Consumer polls records from topic partitions
    Process business logic (DB, API, etc.)
    Commit offset after success
    Monitor consumer lag

    Step-by-step explanation

    1. Subscribe — Consumer joins a group and receives partition assignments.
    2. Poll — Fetch records in batches with consumer.poll().
    3. Process — Run business logic for each record.
    4. Commit — Save offset after successful side effects.
    5. Repeat — Continue polling; rebalance if group membership changes.

    Informative example

    Example:

    bash
    kafka-topics --bootstrap-server localhost:9092 --create --topic slow-consumers --partitions 6 --replication-factor 3
    kafka-console-producer --bootstrap-server localhost:9092 --topic slow-consumers
    kafka-console-consumer --bootstrap-server localhost:9092 --topic slow-consumers --from-beginning
    kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group slow-consumers-service

    Execution workflow

    1Slow Consumers workflow
    1 / 5

    Subscribe

    Consumer joins a group and receives partition assignments.

    Best practices

    • Use manual commits for critical side effects.
    • Make consumers idempotent with event IDs or unique constraints.
    • Keep processing under max.poll.interval.ms or use pause/resume patterns.
    • Send poison messages to DLT with failure metadata.

    Common mistakes

    • Committing before database writes complete.
    • Scaling consumers beyond partition count and expecting more throughput.
    • Blocking the poll loop with slow downstream calls.

    Summary

    Slow Consumers — Commit offsets only after successful processing; make handlers idempotent; monitor lag per partition.

    Ready to mark this lesson complete?Track your journey across the entire course.