Kafka Error UNKNOWN_TOPIC_OR_PARTITION
Error code 3 · Retriable Broker
This server does not host this topic-partition.
Common Causes
- Topic does not exist yet and auto.create.topics.enable=false on the broker; producer or consumer references a non-existent topic
- Partition reassignment or broker failure left the metadata cache stale; client is routing to a broker that no longer hosts the partition
- Topic was recently deleted and the client metadata has not refreshed yet
Solutions
- Create the topic explicitly before producing/consuming: kafka-topics.sh --create --topic <name> --partitions N --replication-factor M --bootstrap-server localhost:9092
- Force a metadata refresh on the client side by setting 'metadata.max.age.ms' to a lower value (e.g. 30000) or by restarting the client
- Verify the topic exists and all partitions have leaders: kafka-topics.sh --describe --topic <name> --bootstrap-server localhost:9092; look for 'Leader: none'
Diagnostic Commands
# Describe topic partitions, leaders, and ISR
kafka-topics.sh --describe --topic <topic> --bootstrap-server localhost:9092
# List topics and search for the target topic
kafka-topics.sh --list --bootstrap-server localhost:9092 | grep <topic>Related APIs
This error can be returned by: AddPartitionsToTxn · AlterShareGroupOffsets · DeleteRecords · DescribeLogDirs · DescribeProducers · EndTxn · Fetch · InitProducerId · ListOffsets · OffsetCommit · OffsetDelete · Produce · TxnOffsetCommit · WriteTxnMarkers
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.