org.apache.kafka.common.errors.TimeoutException Topic not present in metadata after 60000 ms
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a distributed event streaming platform capable of handling trillions of events a day. One common issue users might encounter when working with Kafka is the org.apache.kafka.common.errors.TimeoutException. This exception can occur when a topic is not present in Kafka's metadata within the default timeout period, which is typically 60000 milliseconds (or 60 seconds). This article delves into the potential reasons for this error, how to troubleshoot it, and best practices to avoid it in the future.
Understanding the TimeoutException
The TimeoutException typically occurs when a Kafka client tries to produce, consume, or fetch metadata for a topic that does not exist or is not recognized by the cluster. The error message "Topic not present in metadata after 60000 ms" clearly points out that the topic in question is either not created or not propagated properly across the cluster. Here's a brief breakdown of the error components:
- Topic not present in metadata: Indicates the absence of the required topic in the metadata known to the Kafka broker that the client connects to.
- After 60000 ms: Indicates that the broker or the cluster failed to recognize the topic within the 60-second window.
Common Causes and Troubleshooting
Below are some of the common causes for this error and troubleshooting steps you can take:
- Topic does not exist:
- Cause: The specified topic has not been created.
- Resolution: Ensure that the topic is created before it is accessed. In Kafka, you can create topics manually using the Kafka CLI or ensure that automatic topic creation is enabled.
- Network Issues:
- Cause: Broken or slow network connections between the Kafka client and the brokers.
- Resolution: Check network connectivity, firewall rules, and broker settings.
- Broker Configuration:
- Cause: Misconfiguration in the broker may prevent it from properly reading or writing metadata.
- Resolution: Verify the broker's configuration files (e.g.,
server.properties) for any incorrect settings.
- Cluster Metadata Synchronization:
- Cause: The metadata has not been synchronized across all brokers.
- Resolution: Investigate the broker logs to determine if there are any synchronization issues.
- Client Timeout Settings:
- Cause: The default metadata fetch timeout may be too low for some scenarios, especially in high-latency networks.
- Resolution: Adjust the client’s metadata fetch timeout settings by increasing the
metadata.max.age.ms.
Example
Consider a scenario where a Kafka producer is attempting to send records to a topic named myTopic. If myTopic does not exist or is not recognized within the default metadata waiting period, the producer will throw a TimeoutException.
Best Practices
- Regularly monitor and maintain Kafka clusters.
- Ensure proper network connectivity and configurations.
- Use replication and synchronization mechanisms efficiently.
Summary Table
| Issue Component | Cause | Resolution |
| Topic does not exist | Topic not created or misspelled | Pre-create topic or enable auto-creation |
| Network issues | Poor connectivity or firewall rules | Check and rectify connectivity settings |
| Broker configuration | Misconfiguration in broker settings | Verify and correct broker's server.properties |
| Cluster synchronization | Metadata sync delay among brokers | Monitor logs and ensure synchronization is active |
| Client timeout settings | Low default timeout setting | Adjust metadata.max.age.ms in client config |
By understanding and addressing each component of this issue, users can minimize downtime and ensure a smoother operation of their Kafka-powered applications.
Related reading
- org.apache.kafka.common.KafkaException Failed to construct kafka consumer
- org.apache.kafka.common.KafkaException io.confluent.kafka.serializers.KafkaAvroSerializer
- org.apache.kafka.common.network.InvalidReceiveException Invalid receive (size = 30662099 larger than 30662028)
- org.apache.kafka.connect.errors.ConnectException An exception occurred in the change event producer. This connector will be stopped
- org.apache.spark.SparkException Task not serializable
- org.apache.spark.sql.AnalysisException Can't extract value from probability
- org.springframework.context.ApplicationContextException Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry
- OS X and rabbitMQ ERROR epmd error for host xxx address (cannot connect to host/port)

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.