Kafka MirrorMaker2 - not mirroring consumer group offsets
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka MirrorMaker2 (MM2) is an upgrade to the original MirrorMaker tool used in Kafka, enabling more robust cross-cluster replication functionalities. This tool not only replicates topics and messages across different Kafka clusters but also features enhancements such as replication of topic configuration and more predictable offsets. However, it does not mirror consumer group offsets by default. Here's why this is the case and an in-depth discussion on the functionalities of MM2.
Why MirrorMaker2 Does Not Mirror Consumer Group Offsets
Consumer group offsets, which keep track of the messages that have been consumed by each Kafka consumer group, are not mirrored in MM2 for a few crucial reasons:
- Consumer Independence: Each Kafka cluster may serve different consumers that process data at varying rates. Mirroring consumer offsets between clusters could lead to complications, where consumers on a backup cluster could either miss messages or redundantly reprocess them.
- Failover Management: In scenarios involving failover to a secondary cluster, you typically want the failover to be a deliberate act, closely monitored and possibly involving some modifications or checks. Automatically mirroring offsets could disrupt finely controlled failover processes.
- Offset Conflicts: Since the offsets in two different clusters can diverge (due to differing lag, topic configurations, or simply because of the normal operational delays), direct offset replication could lead to conflicts and inconsistencies, making the failover and recovery processes error-prone.
Technical Insight: How MirrorMaker2 Works Without Mirroring Offsets
MM2 operates by tracking the source and target cluster offsets independently for each replicated topic. Here’s a closer technical view:
- Replication: MM2 continuously replicates messages from a source to a target Kafka cluster.
- Offset Sync: MM2 tracks the latest offset it has successfully replicated per topic-partition. This ensures that the replication process is accurate and records are not lost or duplicated during normal operations.
- Consumer Offset Management: Consumers in the target Kafka cluster maintain their own offsets. During a failover scenario, these consumers can start consuming from the last offset available in the target cluster, which MM2 ensures is up-to-date with the source.
Practical Example
Consider a scenario with a primary and a secondary Kafka cluster where MM2 is used:
In this scenario:
- Consumer Group X on the Primary Cluster has consumed up to offset 345.
- Consumer Group Y on the Secondary Cluster independently consumes the replica of Topic A, and is at offset 123.
- Even if the offsets are different, MM2 ensures message fidelity in the replica.
Handling Failover and Offset Management
In case of a failover:
- Consumer Offset Adjustment: Adjust the offsets in the target (failover) cluster depending on the offset tracked when the last successful sync occurred.
- Manual Offset Management: Administrators may choose to manually set the consumer group offsets in the secondary cluster based on specific requirements or the processing state of the messages.
Summary Table
| Feature | Description |
| Topic Replication | Automatically replicates topic messages and configurations. |
| Offset Tracking | Maintains independent offset tracking for source/target pairs. |
| Offset Mirroring | Does not mirror consumer group offsets. |
| Consumer Independence | Allows each cluster's consumers to operate independently. |
| Failover Handling | Requires manual intervention for adjusting consumer offsets. |
Conclusion
Understanding the operational specifics of Kafka MirrorMaker2, especially regarding offset management, is crucial for designing robust, high-availability Kafka architectures. While the non-mirroring of consumer group offsets might initially seem like a limitation, it actually empowers more granular control during failovers and ensures consumer independence across clusters. This approach affords administrators the flexibility to manage cluster failovers and disaster recovery scenarios meticulously and effectively.

