Kafka Common Commands - CodeSwordsman

Kafka 3.x operations reference: topic creation and partition scaling, console producer and consumer, consumer group lag and offset resets, throughput tests, plus bootstrap servers and log directories.

Kafka 3.xUpdated 2026-10-3018 commands

Topics

Create a topic; partitions drive parallelism and replicas cannot exceed brokers

kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3 --replication-factor 2

List all topics to confirm names before deeper debugging

kafka-topics.sh --bootstrap-server localhost:9092 --list

Show partitions, replicas and ISR; fewer ISR members means lagging followers

kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders

Partitions can only grow; increasing them changes key-based distribution

kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic orders --partitions 6
Risky

Delete the topic and its data; requires delete.topic.enable

kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic orders

Produce & Consume

Interactive producer sending one message per line; exit with Ctrl+C

kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders

Produce with keys like order-1:{"id":1} to keep per-key ordering

kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders --property parse.key=true --property key.separator=:

Consume history from the beginning; fine for debugging only on large topics

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning

Use a consumer group and print key and partition to verify placement

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --group debug-group --property print.key=true --property print.partition=true

Passing --group commits offsets and can disturb production consumers.

Consumer Groups & Offsets

List consumer groups before checking lag

kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

The LAG column shows backlog; an empty CONSUMER-ID means no active consumer

kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group order-service
Risky

Reset offsets to earliest after stopping the group to avoid conflicts

kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group order-service --topic orders --reset-offsets --to-earliest --execute
Risky

Delete a consumer group; only works when it has no active members

kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group debug-group

Throughput Tests

Producer benchmark; throughput -1 is unthrottled and reports latency percentiles

kafka-producer-perf-test.sh --topic orders --num-records 100000 --record-size 1024 --throughput -1 --producer-props bootstrap.servers=localhost:9092 acks=1

Consumer benchmark reporting MB/sec and message counts

kafka-consumer-perf-test.sh --topic orders --bootstrap-server localhost:9092 --messages 100000 --group perf-group

Operations

Without --topic this summarizes all partitions and replica states

kafka-topics.sh --bootstrap-server localhost:9092 --describe

Inspect topic overrides such as retention.ms and cleanup.policy

kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type topics --entity-name orders

Show log directory sizes per broker; the first stop for disk alerts

kafka-log-dirs.sh --bootstrap-server localhost:9092 --describe --topic-list orders

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.