Kafka CLI cheat sheet
Topic management, console producers and consumers, consumer group lag, offset resets, and config inspection.
Topics
kafka-topics --bootstrap-server localhost:9092 --list- The first command in any investigation. Add --exclude-internal to hide __consumer_offsets.
kafka-topics --create --topic orders --partitions 6 --replication-factor 3- Partitions cap consumer parallelism and cannot be reduced later. Replication factor 3 is the production minimum.
kafka-topics --describe --topic orders- Shows leader, replicas, and ISR per partition. Any partition where ISR is smaller than replicas needs attention now.
kafka-topics --alter --topic orders --partitions 12- Increasing partitions is allowed but breaks key-to-partition affinity, so existing key ordering guarantees change.
kafka-topics --delete --topic orders- Requires delete.topic.enable=true. Deletion is asynchronous; the topic may linger briefly.
Producing and consuming
kafka-console-producer --topic orders --property parse.key=true --property key.separator=:- Lets you send keyed messages by typing key:value, which is essential for testing partition routing.
kafka-console-consumer --topic orders --from-beginning --max-messages 10- Peek at real payloads. Always bound with --max-messages on a busy topic.
kafka-console-consumer --topic orders --property print.key=true --property print.timestamp=true- Prints keys and timestamps alongside values — the fastest way to diagnose an ordering complaint.
kafka-avro-console-consumer --property schema.registry.url=http://localhost:8081- Required for Avro topics; the plain console consumer prints unreadable bytes.
kafka-console-consumer --partition 3 --offset 1500- Read one exact position when reproducing a poison-pill message.
Consumer groups and lag
kafka-consumer-groups --bootstrap-server localhost:9092 --list- Enumerate groups. Orphaned groups from decommissioned services are a common source of confusing lag alerts.
kafka-consumer-groups --describe --group etl-loader- The lag command. CURRENT-OFFSET versus LOG-END-OFFSET per partition, plus which consumer owns each partition.
kafka-consumer-groups --describe --group etl-loader --members --verbose- Shows client IDs and hosts. Use it to find the one stuck consumer holding up a rebalance.
kafka-consumer-groups --reset-offsets --to-earliest --topic orders --group etl-loader --execute- Full replay. Omit --execute for a dry run first; without it the command only prints the plan.
--reset-offsets --to-datetime 2026-08-01T00:00:00.000- Time-based replay for reprocessing a specific incident window. The group must have no active members.
kafka-consumer-groups --delete --group etl-loader- Removes committed offsets entirely. The next start follows auto.offset.reset.
Configuration
kafka-configs --describe --entity-type topics --entity-name orders- Shows only overrides, not inherited broker defaults — a frequent source of "but I set that" confusion.
kafka-configs --alter --entity-type topics --entity-name orders --add-config retention.ms=604800000- Seven-day retention. Retention bounds how far you can replay, so set it from your recovery requirements.
--add-config cleanup.policy=compact- Log compaction keeps the latest value per key forever. Correct for CDC and state topics, wrong for event streams.
--add-config min.insync.replicas=2- With acks=all, this is what actually makes a write durable. Leaving it at 1 defeats replication.
Operations and debugging
kafka-get-offsets --topic orders --time -1- Latest offsets per partition. Compare against -2 for earliest to gauge retained volume.
kafka-run-class kafka.tools.DumpLogSegments --files 00000000000000000000.log- Inspect raw segment contents when a message is unparseable by every consumer.
kafka-reassign-partitions --generate --topics-to-move-json-file topics.json- Rebalance partitions after adding brokers. Always throttle the reassignment or you saturate the network.
kafka-producer-perf-test --topic orders --num-records 100000 --record-size 1000 --throughput -1- Baseline throughput before blaming Kafka for an application bottleneck.
From DataLane — tutorials at/blog, practice SQL live in theplayground.