Kafka Replication
- Anand Nerurkar
- May 2
- 2 min read
š Kafka in Multi-Region (Active-Active or Active-Passive) Setup
š Data Replication Flow: Region A ā Region B
1. Active-Passive Setup (One-Way Replication)
ā¶ Use Case:
Region A is active, Region B is backup (DR).
ā¶ Flow:
Producers write to Region AĀ Kafka cluster.
MirrorMaker 2Ā replicates data to Region B.
Consumers in Region B are inactive until failover.
Benefits:
Simpler, more consistent
Region B can take over if Region A fails (Disaster Recovery)
2. Active-Active Setup (Bi-Directional Replication)
ā¶ Use Case:
Both Region A and Region B actively handle traffic (e.g., global users).
ā¶ Flow:
Producers in Region A write to Kafka A; producers in Region B write to Kafka B.
MirrorMaker 2 (or Confluent Replicator) replicates:
Region A ā Region B
Region B ā Region A
You must prefix topicsĀ to avoid cyclic replication:
regionA.orders, regionB.orders
Important Caveats:
Avoid conflict: Same topic names can cause infinite loops.
Use deduplicators, topic renaming, or routing rules.
Maintain global IDsĀ (e.g., UUIDs) to track message uniqueness.
āļø Example Kafka Replication Topology
pgsql
+------------------------+
| Kafka Cluster A |
| (Azure - East US) |
+------------------------+
| |
MirrorMaker2 MirrorMaker2
(East ā West) (West ā East)
| |
+------------------------+
| Kafka Cluster B |
| (Azure - West Europe) |
+------------------------+
š Networking and Security Between Regions
VNET PeeringĀ or ExpressRouteĀ for fast & secure transfer
TLS Encryption, SASL Auth, ACLs
Can use Azure Private LinkĀ or VPN Gateway
ā Tips for Successful Replication
Challenge | Solution |
Message duplication | Use message deduplicationĀ logic via UUIDs |
Topic conflicts | Use prefixes or renamingĀ strategy |
Replication lag | Monitor with Prometheus/Grafana |
Network latency | Use regional edge zonesĀ or ExpressRoute |
Failover complexity | Implement external DNS + Traffic Manager |
Commentaires