Geo-replication strategies in Kafka - Commands & Configuration
bootstrap.servers=clusterA.kafka.local:9092 replication.policy.class=org.apache.kafka.connect.mirror.MirrorReplicationPolicy replication.factor=3 topics=important-topic,logs source.cluster.alias=clusterA target.cluster.alias=clusterB emit.heartbeats.enabled=true heartbeat.interval.seconds=30 sync.topic.acls.enabled=true
This configuration file sets up MirrorMaker 2 for geo-replication between two Kafka clusters.
bootstrap.servers: Connects to the source Kafka cluster.
replication.policy.class: Defines the replication strategy used.
replication.factor: Number of replicas for mirrored topics in the target cluster.
topics: Lists topics to replicate.
source.cluster.alias and target.cluster.alias: Names for source and target clusters.
emit.heartbeats.enabled and heartbeat.interval.seconds: Enable and set frequency for heartbeat messages to monitor replication health.
sync.topic.acls.enabled: Ensures access control lists are synced between clusters.
connect-mirror-maker replicator.properties
kafka-topics --bootstrap-server clusterB.kafka.local:9092 --list
--bootstrap-server - Specifies the Kafka cluster to connect to.--list - Lists all topics in the cluster.kafka-consumer-groups --bootstrap-server clusterB.kafka.local:9092 --describe --group mirror_maker_2
--describe - Shows detailed information about the consumer group.--group - Specifies the consumer group to describe.If you remember nothing else from geo-replication, remember: MirrorMaker 2 copies topics between Kafka clusters to keep data consistent and available across locations.
Practice
Solution
Step 1: Understand geo-replication concept
Geo-replication means copying data between clusters in different places to keep data safe and accessible.Step 2: Identify the main goal
The main goal is to keep data safe and close to users worldwide by copying it across locations.Final Answer:
To copy data between Kafka clusters in different locations for safety and availability -> Option CQuick Check:
Geo-replication = Data copying across locations [OK]
- Confusing geo-replication with data compression
- Thinking geo-replication encrypts data
- Assuming geo-replication deletes data
Solution
Step 1: Recall Kafka geo-replication tools
MirrorMaker 2 is designed to replicate data between Kafka clusters in different locations.Step 2: Differentiate from other tools
Kafka Streams processes data streams, Kafka Connect Sink moves data to external systems, and Producer API sends data to Kafka but does not replicate clusters.Final Answer:
MirrorMaker 2 -> Option AQuick Check:
Geo-replication tool = MirrorMaker 2 [OK]
- Choosing Kafka Streams which is for processing, not replication
- Confusing Kafka Connect Sink with replication tool
- Selecting Producer API which only sends data
{
"clusters": {
"A": {"bootstrap.servers": "a.kafka:9092"},
"B": {"bootstrap.servers": "b.kafka:9092"}
},
"mirrors": [{"source.cluster": "A", "target.cluster": "B", "topics": ["orders"]}]
}Solution
Step 1: Analyze source and target clusters
The config shows source.cluster as A and target.cluster as B, meaning data flows from A to B.Step 2: Check topics list
The topics list includes "orders", so only the 'orders' topic is replicated from A to B.Final Answer:
Data from cluster A is copied to cluster B for topic 'orders' -> Option BQuick Check:
Source A to target B for 'orders' topic [OK]
- Reversing source and target clusters
- Thinking topics list is empty
- Assuming data merges instead of copies
{
"clusters": {
"source": {"bootstrap.servers": "source.kafka:9092"},
"target": {"bootstrap.servers": "target.kafka:9092"}
},
"mirrors": [{"source.cluster": "source", "target.cluster": "target", "topics": []}]
}Solution
Step 1: Check topics list in mirror config
The topics list is empty [], so no topics are selected to replicate.Step 2: Validate other config parts
Bootstrap servers are correctly formatted, cluster names as strings are valid, and multiple clusters are allowed.Final Answer:
Empty topics list means no topics are selected for replication -> Option DQuick Check:
Empty topics list = no replication [OK]
- Assuming bootstrap.servers format is wrong
- Thinking cluster names must be numbers
- Believing MirrorMaker 2 supports only one cluster
Solution
Step 1: Understand full data availability goal
Each cluster should have all topics from the others, meaning data must flow both ways between all clusters.Step 2: Choose replication strategy
A full mesh replication with MirrorMaker 2 means each cluster replicates to the other two, ensuring complete data presence everywhere.Final Answer:
Set up MirrorMaker 2 with a full mesh replication where each cluster replicates to the other two -> Option AQuick Check:
Full mesh replication = all clusters have all topics [OK]
- Using one-way replication only
- Replicating only largest topic, missing others
- Confusing Kafka Connect Sink with cluster replication
Ready to prove it?
Pass the test and this pattern moves unknown
