Skip to content

Monitoring consumer lag on Amazon MSK: why time lag alone misses stalled consumers and raises false alarms

7 minute read
Content level: Intermediate
0

EstimatedMaxTimeLag is documented as a time estimate to drain MaxOffsetLag, so it is derived from offset lag rather than measured on its own. As a result, a stalled consumer group on a low-throughput topic can show 0 seconds of time lag for hours, while a healthy group on a bursty topic can spike to hundreds of seconds. This article explains both patterns and gives reading and alarm rules that combine time lag with offset lag.

Overview

Amazon MSK publishes consumer lag to CloudWatch in two forms: an offset count (MaxOffsetLag, SumOffsetLag) and a time estimate (EstimatedMaxTimeLag). Many teams alarm only on the time estimate, because "seconds behind" is easier to reason about than a raw offset count.

That choice fails in both directions. A consumer group that has stopped committing on a low-throughput topic can show a time lag of 0 for hours, so the alarm never fires. A healthy consumer group on a bursty topic can show a time lag of hundreds of seconds while only a handful of messages are pending, so the alarm fires for nothing.

Both outcomes follow directly from how the metric is defined. This article explains that definition, shows the two failure patterns as they appear in CloudWatch, and gives reading and alarm rules that avoid them.

What the lag metrics are

The consumer lag metrics are available at the DEFAULT monitoring level for both Standard and Express brokers, with the Consumer Group and Topic dimensions. Their documented definitions are:

MetricDocumented definition
MaxOffsetLagThe maximum offset lag across all partitions in a topic.
SumOffsetLagThe aggregated offset lag for all the partitions in a topic.
EstimatedMaxTimeLagTime estimate (in seconds) to drain MaxOffsetLag.
RollingEstimatedTimeLagMaxRolling maximum time estimate (in seconds) to drain the partition offset lag across all partitions in a topic.

Partition-level versions (OffsetLag, EstimatedTimeLag, RollingEstimatedTimeLag) exist only at the PER_TOPIC_PER_PARTITION monitoring level.

The key word in the third row is estimate. EstimatedMaxTimeLag is not an independent measurement of how old the oldest unread message is. It is the offset lag converted into seconds using the rate at which the partition is being drained. It inherits every quirk of that conversion.

Failure pattern 1: a stalled consumer that time lag never reports

Consider a topic that receives only a few messages per second. A consumer group reading it stops advancing its committed offset (for example, because commits are not being issued for that topic, or the consumers are stuck).

What CloudWatch shows:

  • MaxOffsetLag grows in a straight line. In one case we investigated it increased steadily for more than an hour without a single decrease, at roughly 3 messages per second.
  • EstimatedMaxTimeLag stays at 0 the entire time.

The offset lag is real and growing. The time estimate rounds down to nothing because, at that throughput, the "time to drain" is computed as under a second. An alarm on EstimatedMaxTimeLag alone will never catch this.

Why it matters even when nothing looks broken: a consumer resumes from its last committed offset. If the group restarts or rebalances while its committed offset has been stuck, it reprocesses everything since that offset. The longer the stall, the larger the duplicate workload when it finally recovers.

Failure pattern 2: time lag spikes that are not real delay

The opposite pattern shows up on topics whose throughput moves in short bursts.

What CloudWatch shows:

  • EstimatedMaxTimeLag jumps to hundreds of seconds, in some cases around 1,000 seconds, and then drops back.
  • At the same timestamps, MaxOffsetLag is in the single or low double digits.

The consumer is a few messages behind. The time estimate is large because the drain rate used in the conversion dropped momentarily. In one launch-day review we found five consumer groups with this pattern, and every one of them turned out to be healthy once the offset lag was put next to the time lag.

If you page on time lag alone, these are the alerts that train your on-call to ignore the lag alarm.

Reading rules

  1. Always read time lag next to offset lag. Treat EstimatedMaxTimeLag as a convenience view of MaxOffsetLag, not as a separate signal.
  2. If SumOffsetLag equals MaxOffsetLag, the lag is in one partition. SumOffsetLag adds all partitions, MaxOffsetLag takes the largest. When they are equal, every other partition is at 0 (or the topic has a single partition). One stuck partition and a topic that is behind across the board need different responses: the first often points to a single consumer, a hot key, or a partition-specific problem; the second points to consumer capacity.
  3. Compare groups that read the same topic. If several groups show almost identical offset lag on the same topic, the cause is unlikely to be one slow consumer. Check whether the groups are actually expected to commit on that topic, and how they commit.
  4. Drill down to partitions only when you need to. Partition-level OffsetLag requires PER_TOPIC_PER_PARTITION. At PER_BROKER there is no partition dimension, so rule 2 is the only way to tell concentration from spread.

Alarm rules

  • Do not alarm on EstimatedMaxTimeLag alone. Combine it with an offset-lag condition so that both must be true, for example with a CloudWatch composite alarm over two metric alarms: time lag above your latency target AND MaxOffsetLag above a count that is meaningful for that topic.
  • Add a separate offset-lag alarm for stalls. Set MaxOffsetLag above a threshold for several consecutive datapoints. This catches pattern 1, which no time-based condition will.
  • Size thresholds per topic. A pending count of 1,000 is trivial on a high-throughput topic and a serious stall on a topic that receives three messages per second.

When the metrics are missing entirely

An empty lag graph does not mean zero lag. The documentation lists cases where the consumer lag metrics are not emitted:

  • The consumer group is not in a STABLE or EMPTY state (for example, during a rebalance).
  • The consumer group name contains a colon (:).
  • No consumer offset has been set for the group.
  • The consumer group name contains non-ASCII characters. CloudWatch dimension values support only ASCII, so these metrics are dropped.

Check these before concluding that a group has no lag.

Checklist

  1. Put MaxOffsetLag and EstimatedMaxTimeLag on the same graph for each group you care about.
  2. Check whether SumOffsetLag equals MaxOffsetLag to tell one stuck partition from topic-wide lag.
  3. Replace time-lag-only alarms with a composite of time lag AND offset lag.
  4. Add an offset-lag alarm with consecutive datapoints to catch slow, steady stalls.
  5. If a graph is empty, check group state, group name characters, and whether offsets were ever committed.

Key points

  • EstimatedMaxTimeLag is documented as a time estimate to drain MaxOffsetLag. It is derived from offset lag, not measured independently.
  • On low-throughput topics, a stalled group can grow offset lag for hours while time lag stays at 0.
  • On bursty topics, time lag can spike to hundreds of seconds while only a few messages are pending.
  • Alarm on time lag AND offset lag, and keep a separate offset-lag alarm for stalls.
  • SumOffsetLag equal to MaxOffsetLag means the lag sits in a single partition.
  • A missing lag metric can mean an unstable group, a colon or non-ASCII group name, or no committed offset.

References