Apache Kafka & Stream Processing Fundamentals · Lección

Seguimiento y alertas del consumer lag

Aprenda qué significa el consumer lag, cómo medirlo con herramientas integradas y cómo generar alertas antes de que los consumidores se queden peligrosamente atrás.

Lección 4 de 413 pasos

Seguimiento y alertas del consumer lag es una lección gratuita de Apache Kafka & Stream Processing Fundamentals en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Apache Kafka & Stream Processing Fundamentals, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Apache Kafka & Stream Processing Fundamentals incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

What Is Consumer Lag?

Consumer lag is the difference between the latest offset produced to a partition (the log-end offset) and the offset a consumer group has committed.

Lag tells you how far behind your consumers are. Rising lag means consumers can't keep up with producers.

Why Lag Matters

High lag has real consequences:

  • Stale data downstream (dashboards, alerts, ML features).
  • Risk of hitting retention and losing unconsumed messages.
  • A signal of undersized consumers or a stuck partition.

Checking Lag from the CLI

The fastest way to see lag is kafka-consumer-groups.sh with --describe.

kafka-consumer-groups.sh \
  --bootstrap-server localhost:9092 \
  --describe \
  --group order-processors

Reading the Output

The describe output shows per-partition columns:

  • CURRENT-OFFSET — last committed offset.
  • LOG-END-OFFSET — newest offset in the partition.
  • LAG — the difference between them.

Sum LAG across partitions for total group lag.

Lag via JMX Metrics

Each consumer exposes lag through JMX under the consumer-fetch-manager-metrics group.

  • records-lag-max — max lag across assigned partitions.
  • records-lag — per-partition lag.

These are client-side and update in near real time.

Burrow & Kafka Exporter

For production monitoring, dedicated tools poll lag for all groups:

  • Burrow — evaluates lag trend and reports group status (OK/WARN/ERR).
  • kafka_exporter — exposes lag as Prometheus metrics.

Prometheus Lag Metric

With kafka_exporter, lag is available as a labeled time series you can graph and alert on in Grafana.

# Example Prometheus metric
kafka_consumergroup_lag{consumergroup="order-processors",topic="orders",partition="0"} 1423

Writing a Lag Alert

Alert on sustained high lag, not momentary spikes. A common rule fires when total lag exceeds a threshold for several minutes.

# Prometheus alert rule
- alert: HighConsumerLag
  expr: sum(kafka_consumergroup_lag{consumergroup="order-processors"}) > 10000
  for: 5m
  labels:
    severity: warning

Lag Rate vs. Absolute Lag

Absolute lag alone can mislead — 10,000 messages may be seconds of data for a fast topic.

Track the rate of change: if lag keeps growing, consumers are losing the race even if current numbers look fine.

Reducing Lag

When lag climbs, your options include:

  • Add consumers (up to the partition count).
  • Increase partitions to allow more parallelism.
  • Tune max.poll.records and processing efficiency.
  • Check for a slow or stuck partition / poison message.

Operational Best Practices

Make lag a first-class signal:

  • Dashboard total and per-partition lag for every critical group.
  • Alert on lag trend, not just thresholds.
  • Keep lag well below the retention window so you never lose data.

Quick Check

Test your understanding of consumer lag.

Recap

You learned to track and alert on consumer lag.

  • Lag = log-end offset minus committed offset.
  • Inspect it via kafka-consumer-groups.sh, JMX, Burrow, or kafka_exporter.
  • Alert on sustained lag and lag growth rate.
  • Reduce lag by scaling consumers/partitions and tuning processing.
Gratis para empezar

Aprende Apache Kafka & Stream Processing Fundamentals con un tutor de IA — gratis

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Seguimiento y alertas del consumer lag» es gratis?

Sí — el texto completo de «Seguimiento y alertas del consumer lag» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Apache Kafka & Stream Processing Fundamentals, actualiza a CoddyKit PRO. El curso de Apache Kafka & Stream Processing Fundamentals incluye 4 lecciones en total.

¿Qué aprenderé en «Seguimiento y alertas del consumer lag»?

Aprenda qué significa el consumer lag, cómo medirlo con herramientas integradas y cómo generar alertas antes de que los consumidores se queden peligrosamente atrás. Practicas Apache Kafka & Stream Processing Fundamentals con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Apache Kafka & Stream Processing Fundamentals?

No se requiere experiencia previa. Apache Kafka & Stream Processing Fundamentals en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Seguimiento y alertas del consumer lag»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Apache Kafka & Stream Processing Fundamentals?

Sí. Cada lección de Apache Kafka & Stream Processing Fundamentals incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Herramientas de línea de comandos para Kafka
  2. Supervisión de Kafka con JMX y herramientas
  3. Seguridad: autenticación y autorización
  4. Seguimiento y alertas del consumer lag
← Volver a Apache Kafka & Stream Processing Fundamentals