kafka bootstrap.servers as DNS A-Record with multiple IPs
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka is a distributed event streaming platform capable of handling trillions of events a day. Initially conceived as a messaging queue, Kafka is based on an abstraction of a distributed commit log. Since it is widely used for real-time streams of data, it can support a large number of consumers and retain large amounts of data with very little overhead.
Understanding bootstrap.servers Configuration
When a Kafka client (producer or consumer) starts, it needs to connect to the Kafka cluster. The bootstrap.servers configuration property plays a critical role in this process. It specifies a list of host and port pairs (one per broker) that the client will use for the initial connection to discover the full set of servers in the Kafka cluster.
DNS A-Record and bootstrap.servers
DNS (Domain Name System) helps in translating human-readable domain names to machine-readable IP addresses. An A-Record (Address Record) points a hostname to a 32-bit IPv4 address. When setting up Kafka, using a DNS A-Record can decouple client configurations from specific IP addresses of the Kafka brokers.
Instead of listing out each broker's IP address in the bootstrap.servers, a DNS hostname can be used. The hostname can have an A-Record that points to multiple IP addresses, each corresponding to a different Kafka broker.
Advantages:
- Simplification of Client Configuration: Clients only need to know one hostname regardless of the number of Kafka brokers.
- Scalability: Easy to add more brokers. Update the DNS record instead of every client configuration.
- High Availability: DNS can provide alternatives if some brokers are down.
Technical Configuration Example:
Suppose you have a Kafka cluster with the following IP addresses: 192.168.1.1, 192.168.1.2, 192.168.1.3. You want to use a DNS A-Record, kafka-cluster.example.com, pointing to all these IPs.
DNS A-Record Setup:
Kafka Client Configuration (producer.properties or consumer.properties):
Considerations Using DNS with Multiple IPs
- DNS Caching: Java, which Kafka clients use, caches DNS names based on the
networkaddress.cache.ttlsetting injava.security. This can cause outdated IPs if not managed properly. - Load Balancing: DNS round-robin (multiple IPs for one hostname) doesn't guarantee equal distribution of connections across the brokers.
- Failure Handling: Kafka client will attempt to connect to other IPs from DNS resolution if one broker is down.
Best Practices
- Keep DNS TTL Short: To handle broker changes dynamically.
- Monitor DNS Changes: Kafka clients should be aware of changes to reflect new broker IPs.
- Use More Than One DNS Name: To avoid a single point of failure in the DNS resolution process.
Summary Table
| Feature | Benefit | Consideration Needed |
| Simplicity | One hostname for all brokers. | Requires DNS management. |
| Scalability | Add brokers without changing client configs. | Keep DNS and Kafka configurations in sync. |
| High Availability | Clients connect to next available broker if one is down. | Monitor and handle IP changes efficiently. |
Conclusion
Using DNS A-Records with Kafka's bootstrap.servers can significantly simplify the configuration and management of Kafka clients, especially in dynamic environments with changes in the broker IPs. This architecture, however, requires careful setup and management of DNS records and Kafka client configurations to ensure high availability and fault tolerance.

