Streaming messages from one Kafka Cluster to another
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 streaming platform known for its high-throughput and low-latency capabilities in handling real-time data feeds. A common scenario in distributed systems involves streaming data from one Kafka cluster to another. This could be needed for various reasons such as geographical data localization, disaster recovery, data aggregation from multiple clusters, or cloud migration.
Mirroring Data Between Kafka Clusters
To stream data between Kafka clusters, Kafka MirrorMaker is typically used. MirrorMaker is a standalone tool provided by Kafka to mirror data from one cluster to another. It essentially reads data from a source Kafka cluster and writes it to a target Kafka cluster.
How Kafka MirrorMaker Works
- Consumers: MirrorMaker uses consumer instances to consume messages from the source cluster.
- Producers: After consuming the messages, these are then produced to the destination cluster by producer instances.
Key Configurations for MirrorMaker
- Source Cluster Configuration: Consumer configurations need to be set, pointing to the source cluster. Important parameters include
bootstrap.servers(list of brokers from the source cluster),group.id, and message decoding settings. - Destination Cluster Configuration: Producer configurations direct the messages to the destination cluster. Key configurations include
bootstrap.servers(list of brokers from the target cluster) and message encoding settings. - Topic Configuration: Decides which topics should be mirrored from the source to the target. This can include all topics or be limited to specific topics.
Steps to Set Up Kafka MirrorMaker
- Install Kafka: Ensure that Kafka is installed and running on both source and destination clusters.
- Configure MirrorMaker:
- Configure the consumer (source) and producer (destination) properties.
- Optionally, configure filters or transformations if specific processing on the messages is needed during mirroring.
- Run MirrorMaker: Start the MirrorMaker using the configured properties.
Example Configuration
Advanced Mirroring Technologies
Apart from using the traditional MirrorMaker, the Kafka community has developed more robust solutions like MirrorMaker 2 (MM2). MM2 offers several improvements over the original MirrorMaker:
- Offset Synchronization: MM2 ensures that the consumer offsets are synchronized between the source and target clusters, supporting failover scenarios.
- Topic Configuration Replication: MM2 can also replicate topic configuration and ACLs.
- Replication of Consumer Groups: It allows the replication of consumer groups, which can be useful for maintaining identical staging and production environments.
Example MM2 Configuration
Troubleshooting
- Network Issues: Ensure that there is proper network connectivity between the source and target clusters.
- Configuration Errors: Double-check all configurations for typographical errors or misconfigurations.
- Performance Bottlenecks: Monitor system metrics to ensure neither the source nor the target clusters are becoming performance bottlenecks.
Summary Table
| Feature | MirrorMaker 1 | MirrorMaker 2 |
| Offset Synchronization | No | Yes |
| Configuration Replication | No | Yes |
| Consumer Group Replication | No | Yes |
| Setup Complexity | Less | More but provides higher reliability |
Conclusion
Streaming messages from one Kafka cluster to another is a vital requirement in distributed systems, particularly for large-scale applications. With tools like Kafka MirrorMaker and MirrorMaker 2, it is possible to effectively mirror data between different Kafka environments. While setting up such systems, it is imperative to closely monitor and manage the configuration and performance to ensure reliable and accurate data streaming across your clusters.
Related reading
- Structured Streaming and Splitting nested data into multiple datasets
- structured streaming Kafka 2.1->Zeppelin 0.8->Spark 2.4 spark does not use jar
- Submitting offsets to kafka after storm batch
- Swapping out MSMQ for RabbitMQ in NServiceBus
- Strict serializability example clarification?
- Strong Consistency in Cassandra
- Structured Streaming - Foreach Sink
- Submit Spark Application on Kubernetes in Cluster mode Configured service account doesn't have access

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.