Kafka
Consumer Group
Data Management
Server Cleanup
System Optimization

Kafka: delete an unused consumer group with kafka-consumer-groups.sh

Codemia Knowledge Hub ·

To delete an unused Kafka consumer group, run kafka-consumer-groups.sh --bootstrap-server <host>:<port> --group <group-name> --delete. First confirm the group is really unused: it has no active consumers and has not committed offsets recently.

What a consumer group is

A consumer group is one or more consumers that together consume a set of subscribed topics. Groups provide load balancing and fault tolerance: Kafka spreads a topic's partitions across the group's consumers, so each message is processed once by the group while partitions are consumed in parallel.

Why clean up stale groups

Unused groups pile up over time, especially with dynamic scaling or frequent configuration changes. Removing them helps with:

  • Resources: each group keeps metadata and state in the cluster.
  • Broker overhead: fewer groups can mean less work for the brokers and better performance.
  • Cost: in managed Kafka environments such as Confluent Cloud, you might be charged based on the number of consumer groups.
  • Monitoring: fewer groups are easier to monitor and operate.

Finding unused consumer groups

A group counts as unused when it has no active consumers connected and hasn't committed offsets recently. List the groups and their status:

bash
kafka-consumer-groups.sh --bootstrap-server <kafka-broker-host>:<port> --describe --all-groups --state

--list and --describe cannot be combined; --describe --all-groups --state prints each group's state and member count. Look for groups in the Empty state with 0 members, or a long time since the last commit.

Deleting the group

bash
kafka-consumer-groups.sh --bootstrap-server <kafka-broker-host>:<port> --group <group-name> --delete

This marks the consumer group for deletion. When the group is actually removed from the cluster depends on the Kafka version and the server configuration.

ActionCommandDescription
List Groupskafka-consumer-groups.sh --bootstrap-server <host>:<port> --listLists all consumer groups
Describe Groupkafka-consumer-groups.sh --bootstrap-server <host>:<port> --group <group-name> --describeShows detailed info on a specific group
Delete Groupkafka-consumer-groups.sh --bootstrap-server <host>:<port> --group <group-name> --deleteDeletes the specified consumer group

Precautions and automation

  • Recovery: have a backup, or an easy way to recreate a group deleted by mistake.
  • Version support: the ability to delete consumer groups has evolved, and older Kafka versions might not support it directly.
  • Automated cleanup: in dynamic environments with many transient groups, build group monitoring and cleanup into your standard operations with custom scripts or third-party tools that can detect and purge unused groups.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design