SYSTEM-DESIGN
    intermediate

    Kafka Consumer Lag

    Software Engineer path · lesson 84 of 99
    0
    current lag
    0
    session peak lag
    0
    log-end-offset
    0
    committed offset

    In production, records-lag-max is the maximum lag across all partitions in the consumer group — alerting on the worst partition, not just the average.

    7/s
    5/s
    Caught up (lag 0)
    partition log (tail)consumer at 0 → head at 0
    Press “Start stream” to produce records…
    consumed lag (not yet consumed)
    Lag over time
    peak 0
    start the stream to chart lag

    Key insight

    Lag is a rate problem: it accumulates whenever produce rate > consume rate. Produce and consume are balanced, so lag stays flat. A traffic spike adds a one-off backlog the consumer must work off. In production you alert on records-lag-max, not instantaneous throughput.

    What happens to lag?

    Sort

    Sort each event by its effect on consumer lag.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Lag grows

    Drop items here

    Lag shrinks

    Drop items here
    6 pieces left to place

    Test your knowledge

    21 questions
    Question 1 of 21
    Score: 0

    How is consumer lag defined?

    The short version

    Consumer lag is like a dish pile by the sink: plates arrive (produced) faster than you wash them (consumed) and the pile grows. Wash faster than they arrive and the pile shrinks. A dinner party is a traffic spike — a sudden backlog you work off over time.

    In more depth

    Consumer Lag

    Lag measures how far a consumer trails the head of the partition log:

    lag = log-end-offset − committed-offset

    It grows whenever consume rate < produce rate and drains once the consumer catches up. The metric to alert on is records-lag-max (the worst partition), because uneven partition load means one hot/stalled partition can build large lag while others stay healthy.

    Remedies

    Scale consumers up to the partition count (more parallelism)
    Speed up processing (batching, async I/O, larger max.poll.records)
    Add partitions to raise the parallelism ceiling
    Apply backpressure / shed load when lag is unrecoverable

    Interview Questions

    Confluent
    Datadog
    Uber
    Datadog
    LinkedIn
    Airbnb
    Meta
    Netflix
    Confluent

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required