Kafka CLI Quick Reference

Create topics, produce and consume messages, and inspect consumer-group lag from the command line.

Topics

Create
kafka-topics.sh --create --topic orders --partitions 6 --replication-factor 3 --bootstrap-server localhost:9092
List / describe
kafka-topics.sh --list … · --describe --topic orders …
Add partitions
kafka-topics.sh --alter --topic orders --partitions 12 … (can’t shrink)
Delete
kafka-topics.sh --delete --topic orders …

Produce & consume

Produce (stdin)
kafka-console-producer.sh --topic orders --bootstrap-server …
Produce with key
add --property parse.key=true --property key.separator=:
Consume from start
kafka-console-consumer.sh --topic orders --from-beginning …
Consume in a group
add --group my-group — offsets are committed
Show keys
add --property print.key=true

Consumer groups (lag)

List groups
kafka-consumer-groups.sh --list --bootstrap-server …
Describe (lag!)
kafka-consumer-groups.sh --describe --group my-group … — CURRENT-OFFSET, LOG-END-OFFSET, LAG
Reset offsets
--reset-offsets --to-earliest --topic orders --execute --group my-group
Reset to timestamp
--reset-offsets --to-datetime 2026-01-01T00:00:00.000 … — replay from a point in time

Mental model

Partition = ordering unit
Order is guaranteed within a partition, never across them. Same key → same partition → ordered.
Consumer group
Each partition is read by exactly one consumer in the group — parallelism is capped at the partition count.
Offset
A consumer’s bookmark per partition. Committing it is what makes progress durable across restarts.
Lag
LOG-END-OFFSET − CURRENT-OFFSET: how far behind a consumer is. Growing lag = consumers can’t keep up.
Retention ≠ queue
Kafka keeps messages for a retention window even after consumption — replay is a feature, not a bug.