Kafka Error TOPIC_ALREADY_EXISTS
Error code 36 · Non-retriable Admin
Topic with this name already exists.
Common Causes
- Idempotent topic creation code not using --if-not-exists flag or equivalent AdminClient option, running on restart or re-deploy
- Topic auto-created by a consumer/producer before the admin script ran, resulting in creation with default configs instead of intended settings
- CI/CD pipeline retrying a failed topic-creation step that partially succeeded on a previous run
Solutions
- Use AdminClient.createTopics() with the option to ignore TOPIC_ALREADY_EXISTS error, or check existence with describeTopics() before creating
- Add --if-not-exists to kafka-topics.sh calls in scripts to make them idempotent
- If topic was auto-created with wrong config, delete and recreate with correct partition/replication settings, or alter the config post-creation
Diagnostic Commands
# Describe topic partitions, leaders, and ISR
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topic-name>
# List topics and search for the target topic
kafka-topics.sh --bootstrap-server localhost:9092 --list | grep <topic-name>Related APIs
This error can be returned by: CreateTopics
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.