Disaster recovery planning in Kafka - Time & Space Complexity
When planning disaster recovery in Kafka, it's important to understand how recovery time grows as data size increases.
We want to know how the time to restore data changes when the amount of messages or partitions grows.
Analyze the time complexity of restoring data from Kafka backups.
// Pseudocode for restoring Kafka topic data
for each partition in topicPartitions {
for each message in partitionBackup {
produce message to Kafka topic partition
}
}
This code restores messages by replaying each message from backup into each partition.
Look at what repeats in the code.
- Primary operation: Sending each message back to Kafka.
- How many times: Once for every message in every partition backup.
As the number of messages grows, the time to restore grows too.
| Input Size (messages) | Approx. Operations |
|---|---|
| 10 | 10 sends |
| 100 | 100 sends |
| 1000 | 1000 sends |
Pattern observation: The time grows directly with the number of messages to restore.
Time Complexity: O(n)
This means the recovery time grows in a straight line with the number of messages to restore.
[X] Wrong: "Recovery time stays the same no matter how many messages there are."
[OK] Correct: Each message must be replayed, so more messages mean more work and longer recovery.
Understanding how recovery time scales helps you design systems that can bounce back quickly after problems.
"What if we parallelize restoring partitions? How would that affect the time complexity?"
Practice
Solution
Step 1: Understand disaster recovery goal
Disaster recovery planning focuses on protecting data and maintaining service availability during failures.Step 2: Match goal to options
Only To keep Kafka data safe and services running after failures mentions keeping data safe and services running after problems, which matches the goal.Final Answer:
To keep Kafka data safe and services running after failures -> Option AQuick Check:
Disaster recovery = data safety and uptime [OK]
- Confusing disaster recovery with performance tuning
- Thinking it reduces cluster size
- Assuming it speeds up consumers
Solution
Step 1: Identify replication tool for backup clusters
MirrorMaker is designed to copy data between Kafka clusters for backup and disaster recovery.Step 2: Compare options
Kafka Connect is for data integration, Kafka Streams for processing, and Producer for sending data, so only MirrorMaker fits replication to backup clusters.Final Answer:
MirrorMaker -> Option CQuick Check:
Replication to backup = MirrorMaker [OK]
- Choosing Kafka Connect which is for integration, not replication
- Confusing Kafka Streams with replication
- Thinking Kafka Producer replicates data
bin/kafka-mirror-maker.sh --consumer.config consumer.properties --producer.config producer.properties --whitelist='topic1,topic2'
Solution
Step 1: Understand MirrorMaker command components
The command uses consumer and producer configs and a whitelist of topics to replicate.Step 2: Interpret whitelist usage
The whitelist='topic1,topic2' means only these topics are replicated from source to target cluster.Final Answer:
Replicate only topic1 and topic2 from source to target cluster -> Option DQuick Check:
Whitelist limits topics replicated [OK]
- Thinking it only consumes without replication
- Assuming it produces only on source cluster
- Believing it deletes topics
bootstrap.servers=source:9092
group.id=mirror-group
whitelist=topicA,topicB
What is wrong?
Solution
Step 1: Check MirrorMaker config requirements
MirrorMaker needs both consumer (source) and producer (target) bootstrap.servers configs to replicate data.Step 2: Identify missing config
The given config only shows source bootstrap.servers; missing producer config causes replication failure.Final Answer:
Missing producer bootstrap.servers config for target cluster -> Option BQuick Check:
Both consumer and producer configs needed [OK]
- Thinking quotes are mandatory around whitelist
- Confusing group.id with producer group
- Setting bootstrap.servers to target cluster only
Solution
Step 1: Understand replication factor role
A replication factor of 3 means data is copied to 3 brokers, reducing data loss risk.Step 2: Combine with MirrorMaker backup
MirrorMaker copies data to a separate cluster, adding disaster recovery protection.Final Answer:
Use topic replication factor 3 and MirrorMaker to backup cluster -> Option AQuick Check:
Replication + MirrorMaker = minimal data loss [OK]
- Relying only on MirrorMaker without replication
- Using replication factor 1 which risks data loss
- Confusing Kafka Streams with replication tool
Ready to prove it?
Pass the test and this pattern moves unknown
