Kafka Consumer Lag logo

Kafka Consumer Lag

Organization
lensesio
kafka-consumer-lag

Analyse Kafka consumer group lag using the Lenses MCP server. Diagnoses lag causes (throughput bottlenecks, rebalancing, partition skew, stalled consumers) and suggests remediation. Use when user says "check consumer lag", "why are consumers slow", "lag report" or asks about consumer group health or offset progress. Do NOT use for resetting offsets or managing consumer groups.

Overview

Publisherlensesio
Repositoryagentic-engineering-for-apache-kafka
Skill namekafka-consumer-lag
Stars
67
Forks
19
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by lensesio on GitHub. Read the source before you install it.

Installation

Install the Kafka Consumer Lag AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/lensesio/agentic-engineering-for-apache-kafka/tree/main/skills/kafka-consumer-lag
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/lensesio/agentic-engineering-for-apache-kafka.git /tmp/agentic-engineering-for-apache-kafka
mkdir -p .claude/skills
cp -r /tmp/agentic-engineering-for-apache-kafka/skills/kafka-consumer-lag .claude/skills/kafka-consumer-lag
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Kafka Consumer Lag in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Kafka Consumer Lag on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Kafka Consumer Lag is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Kafka Consumer Lag Analysis

Analyses consumer group lag across all groups and diagnoses potential causes. Consumer lag is the most commonly monitored Kafka metric and the first thing engineers check during incidents.

Target environment: $ARGUMENTS

Workflow

Copy this checklist and track your progress:

Lag Analysis Progress:
- [ ] Step 1: Fetch all consumer groups
- [ ] Step 2: Identify problematic groups
- [ ] Step 3: Diagnose root causes
- [ ] Step 4: Generate report
  1. Fetch all consumer groups with state and lag info
  2. Identify problematic groups (high lag, idle, rebalancing)
  3. Diagnose root causes using partition and throughput data
  4. Report findings with per-group remediation steps

Step 1: Fetch Consumer Groups

Use the Lenses MCP list_consumer_groups tool to get all consumer groups with:

  • Group state (Stable, Rebalancing, Empty, Dead)
  • Lag per topic-partition
  • Active member count
  • Coordinator info

For topic-specific analysis, use list_consumer_groups_by_topic to narrow the scope.

Expected output: List of all consumer groups with state, lag and member count.

Validation: If no consumer groups are returned, report this finding and stop - the cluster may have no active consumers.

Step 2: Identify Problematic Groups

Flag consumer groups in these categories:

Critical

  • Groups in Dead or Empty state with committed offsets (consumer has stopped)
  • Groups with lag growing over time (compare current lag against partition end offsets using get_topic_partitions)

Warning

  • Groups in Rebalancing state (consumption paused)
  • Groups with uneven partition assignment (some consumers have significantly more partitions than others)
  • Groups with no committed offsets (consumer may never have started successfully)

Suggestion

  • Groups with very high member count relative to partition count (idle consumers)
  • Groups consuming from topics with no recent messages (use get_dataset_message_metrics to check producer throughput)

Step 3: Diagnose Root Causes

For each problematic group, determine the likely cause:

Growing Lag + Stable Producer Rate

  • Consumer throughput bottleneck
  • Remediation: Scale consumers, increase max.poll.records, reduce processing time per message, check for synchronous blocking calls

Lag Spikes + Rebalancing

  • Rebalancing is pausing consumption
  • Remediation: Switch to cooperative sticky assignor, increase session.timeout.ms, reduce max.poll.interval.ms risk

Single-Partition Lag (others are fine)

  • Hot partition / key skew
  • Remediation: Review partitioning strategy, check for hot keys, consider custom partitioner

All Partitions Lagging Equally

  • Overall consumer slowness
  • Remediation: Profile consumer processing, check for external dependencies (database, API calls), increase consumer instances

Zero Lag but Empty Group

  • Consumer crashed or was decommissioned
  • Remediation: Check consumer process health, restart if needed, clean up stale groups

Step 4: Verify Data Flow

Use the Lenses MCP execute_sql tool to sample recent messages from lagging topics:

sql
SELECT * FROM {topic} LIMIT 5

This confirms the topic has active producers and messages are flowing.

Success Criteria

Quantitative

  • Triggers on 90% of lag-related queries (test with 10-20 varied phrasings)
  • Completes analysis in under 12 MCP tool calls
  • 0 failed MCP calls per run

Qualitative

  • Each flagged group has a specific diagnosis and remediation
  • Report distinguishes symptom from root cause
  • Consistent results when re-run on the same environment

Examples

Example 1: Incident investigation

User says: "Consumers are falling behind, check the lag"

Actions:

  1. Fetch all consumer groups for the environment
  2. Sort by total lag descending to find the worst offenders
  3. Diagnose root causes for each critical group Result: Prioritised report with per-group diagnosis and remediation

Example 2: Topic-specific lag check

User says: "Check consumer lag for orders.payment.completed"

Actions:

  1. Use list_consumer_groups_by_topic to get groups consuming from that topic
  2. Check partition-level lag distribution
  3. Verify data flow with execute_sql Result: Focused report on a single topic's consumer groups

Example 3: Stale group cleanup

User says: "Find any dead or empty consumer groups"

Actions:

  1. Fetch all consumer groups
  2. Filter for Dead or Empty state with committed offsets
  3. Report stale groups that can be safely cleaned up Result: List of candidate groups for deletion

Troubleshooting

Consumer groups list is empty

Cause: No consumer groups exist in the environment or permissions are restricted. Solution: Verify consumers are running. Check Lenses agent permissions allow listing consumer groups.

Lag numbers seem incorrect

Cause: Consumer group offsets may be stale if the consumer recently stopped. Solution: Compare lag against partition end offsets from get_topic_partitions. Note when offsets were last committed.

execute_sql returns no data

Cause: Topic is empty or has very old messages beyond the query window. Solution: Use get_dataset_message_metrics to check if the topic has recent throughput. An empty topic with lagging consumers indicates a producer issue.

Output Format

## Consumer Lag Report

### Environment: {name}

### Critical (immediate action)
| Consumer Group | Topic | Total Lag | State | Diagnosis | Remediation |
|---------------|-------|-----------|-------|-----------|-------------|
| group-name | topic | 50000 | Stable | Throughput bottleneck | Scale consumers |

### Warning (investigate)
| Consumer Group | Topic | Total Lag | State | Diagnosis | Remediation |
|---------------|-------|-----------|-------|-----------|-------------|

### Suggestion (optimise)
| Consumer Group | Topic | Total Lag | State | Diagnosis | Remediation |
|---------------|-------|-----------|-------|-----------|-------------|

### Summary
- X consumer groups analysed
- Y groups with critical lag
- Z groups with warnings
- Stale/empty groups: N

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Kafka Consumer Lag AI skill do?

Analyse Kafka consumer group lag using the Lenses MCP server. Diagnoses lag causes (throughput bottlenecks, rebalancing, partition skew, stalled consumers) and suggests remediation. Use when user says "check consumer lag", "why are consumers slow", "lag report" or asks about consumer group health or offset progress. Do NOT use for resetting offsets or managing consumer groups.

Why use Kafka Consumer Lag on TypingMind?

Because you install it once and use it with any model. Kafka Consumer Lag is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Kafka Consumer Lag in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/lensesio/agentic-engineering-for-apache-kafka/tree/main/skills/kafka-consumer-lag. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Kafka Consumer Lag?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Kafka Consumer Lag?

As many as you like. As long as a model supports skills, you can use Kafka Consumer Lag with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Kafka Consumer Lag AI skill free?

Yes. It is published on GitHub by lensesio under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇