Kafka
Consumer Group
API
Data Management
Tutorial

How to delete kafka consumer group (created via new consumer api)?

System Design practice on Codemia

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

Practice system design

Apache Kafka is a distributed event streaming platform capable of handling trillions of events a day. One essential aspect of Kafka is the concept of consumer groups, which allow multiple consumers to read from the same topic, distributing the workload. This detailed overview covers how to delete a Kafka consumer group that was created using the new consumer API, introduced in version 0.9 of Kafka.

Understanding Consumer Groups

In Kafka, a consumer group consists of one or more consumers who subscribe to a common set of topics and share the workload of consuming messages. Each consumer within a group reads from exclusive partitions of the topic, ensuring that no two consumers process the same message.

Why Delete a Consumer Group?

Deleting a consumer group might be necessary during maintenance, application decommission, or to reset the state of the consumer group. When a consumer group is deleted, its offsets (which track the progress of each consumer in the group on a per-partition basis) are also removed. This means that if a new group is created with the same name, it will start consuming messages from either the earliest offset or the latest, depending on the configuration.

How to Delete a Consumer Group

The deletion of a consumer group is typically carried out using Kafka's command line tools, particularly kafka-consumer-groups.sh. This tool allows for various management actions on consumer groups.

Requirements

  • Kafka Broker: Your Kafka environment must be running, and you should know the broker's IP address and port.
  • Command Line Access: Access to the Kafka installation directory, specifically where the bin directory is located.
  • Group Name: The exact name of the consumer group you wish to delete.

Step-by-Step Guide

  1. Open your command line tool: Access your Kafka server where the Kafka binaries are installed.
  2. Navigate to the Kafka bin directory: This directory contains all the scripts needed to manage Kafka.
bash
   cd /path/to/kafka/bin
  1. Use the kafka-consumer-groups.sh tool to delete the group:
bash
   ./kafka-consumer-groups.sh --bootstrap-server <broker-ip>:<broker-port> --delete --group <group-name>

Replace <broker-ip>, <broker-port>, and <group-name> with your Kafka broker's IP address, port, and the name of the consumer group, respectively.

Example

If your Kafka broker is running on localhost:9092 and the consumer group name is test-group, the command would be:

bash
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group test-group

Important Considerations

  • Kafka Version Compatibility: The delete option for consumer groups was added in Kafka 0.9. Be sure that your Kafka version supports this feature.
  • Consumer Group State: You can only delete a consumer group if it is empty, meaning no consumers are currently active in the group.
  • Impact: Deleting a consumer group resets its offset. This could lead to message reprocessing or loss, depending on the situation and new consumer configurations.

Summary Table

FeatureDetail
Minimum Kafka Version0.9
Tool Usedkafka-consumer-groups.sh
RequirementBroker must be running; Consumer group must be inactive/empty
Command Syntax./kafka-consumer-groups.sh --bootstrap-server <broker:port> --delete --group <group>
Common Use CaseResets consumer offset; Useful for testing or redevelopment

Additional Resources

For more advanced Kafka management tasks, including altering consumer groups or troubleshooting, consult the Kafka documentation or community forums. Managing consumer groups effectively is crucial for optimizing Kafka's performance and reliability in production environments.

Deleting a Kafka consumer group is a straightforward task when using the command-line tools provided by Kafka, and knowledge of when and how to properly delete a group is vital for maintaining the health and efficiency of your Kafka streaming applications.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

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

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

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

Practice system design

All Rights Reserved.