Bird
Raised Fist0
Kafkadevops~20 mins

Disaster recovery planning in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kafka Disaster Recovery Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Kafka Consumer Group Offset Behavior After Broker Failure
Consider a Kafka consumer group consuming from a topic with 3 partitions. The consumer commits offsets automatically every 5 seconds. If one broker hosting a partition leader fails and the leader is moved to another broker, what will be the output of the following code snippet that prints the last committed offset for each partition after the failover?
Kafka
from kafka import KafkaConsumer

consumer = KafkaConsumer(
    'my_topic',
    group_id='my_group',
    bootstrap_servers=['broker1:9092', 'broker2:9092', 'broker3:9092'],
    enable_auto_commit=True,
    auto_commit_interval_ms=5000
)

# Simulate reading messages
for _ in range(10):
    msg = next(consumer)
    print(f'Partition: {msg.partition}, Offset: {msg.offset}')

# After broker failure and leader election
committed = {partition: consumer.committed(partition) for partition in consumer.assignment()}
print(committed)
AA runtime error because the consumer cannot fetch committed offsets after broker failure.
BA dictionary with the last committed offsets for all partitions, reflecting the offsets before the broker failure.
CA dictionary with offsets reset to zero for all partitions due to leader re-election.
DAn empty dictionary because the consumer lost all committed offsets after the broker failure.
Attempts:
2 left
💡 Hint
Think about how Kafka stores committed offsets in __consumer_offsets topic and how leader election affects offset availability.
🧠 Conceptual
intermediate
1:30remaining
Understanding Kafka Replication Factor Impact on Disaster Recovery
In Kafka, what is the primary benefit of setting a replication factor greater than 1 for a topic in the context of disaster recovery?
AIt enables consumers to read messages faster by reading from multiple replicas simultaneously.
BIt increases the throughput of message production by parallelizing writes.
CIt allows messages to be stored on multiple brokers, ensuring data availability if one broker fails.
DIt automatically backs up messages to an external storage system.
Attempts:
2 left
💡 Hint
Think about how Kafka handles broker failures and data loss prevention.
🔧 Debug
advanced
2:00remaining
Identify the Cause of Data Loss in Kafka After Broker Crash
A Kafka topic has replication factor 3 and min.insync.replicas set to 2. Producers use acks='all'. After a broker crash, some messages are missing from the topic. Which code snippet below best explains why data loss occurred?
Kafka
producer = KafkaProducer(
    bootstrap_servers=['broker1:9092', 'broker2:9092', 'broker3:9092'],
    acks='all',
    retries=0
)

# Sending messages
producer.send('my_topic', b'message1')
producer.flush()
ARetries set to 0 causes producer to not retry sending messages if a broker is down, leading to data loss.
BAcks='all' causes the producer to wait indefinitely, causing timeout and message loss.
Cmin.insync.replicas=2 means only one replica must acknowledge, so data loss is expected.
DProducer flush() is asynchronous and does not guarantee message delivery.
Attempts:
2 left
💡 Hint
Consider how producer retries affect message delivery guarantees.
📝 Syntax
advanced
1:30remaining
Identify the Syntax Error in Kafka Topic Configuration Code
Which of the following Kafka topic creation code snippets contains a syntax error that would prevent the topic from being created?
Aadmin_client.create_topics([NewTopic(name='my_topic', num_partitions=3, replication_factor=2)])
Badmin_client.create_topics([NewTopic(name='my_topic', num_partitions=3)])
Cadmin_client.create_topics([NewTopic(name='my_topic', num_partitions=3, replication_factor=2, config={'cleanup.policy':'compact'})])
Dadmin_client.create_topics([NewTopic(name='my_topic', num_partitions=3, replication_factor='2')])
Attempts:
2 left
💡 Hint
Check the data types of the parameters passed to NewTopic.
🚀 Application
expert
3:00remaining
Designing a Kafka Disaster Recovery Plan for Multi-Region Deployment
You are tasked with designing a disaster recovery plan for a Kafka deployment spanning two geographic regions. Which approach below best ensures minimal data loss and quick recovery if one region fails?
AUse MirrorMaker 2 to replicate topics asynchronously between regions with monitoring and failover automation.
BUse a single Kafka cluster spanning both regions with no replication between them.
CSet replication factor to 1 and rely on local backups in each region for recovery.
DManually export and import topic data daily between regions using scripts.
Attempts:
2 left
💡 Hint
Consider how Kafka supports cross-region replication and automated failover.

Practice

(1/5)
1. What is the main purpose of disaster recovery planning in Kafka?
easy
A. To keep Kafka data safe and services running after failures
B. To improve Kafka message throughput
C. To reduce Kafka cluster size
D. To speed up Kafka consumer processing

Solution

  1. Step 1: Understand disaster recovery goal

    Disaster recovery planning focuses on protecting data and maintaining service availability during failures.
  2. 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.
  3. Final Answer:

    To keep Kafka data safe and services running after failures -> Option A
  4. Quick Check:

    Disaster recovery = data safety and uptime [OK]
Hint: Disaster recovery means data safety and uptime [OK]
Common Mistakes:
  • Confusing disaster recovery with performance tuning
  • Thinking it reduces cluster size
  • Assuming it speeds up consumers
2. Which Kafka feature is used to replicate data to a backup cluster for disaster recovery?
easy
A. Kafka Connect
B. Kafka Streams
C. MirrorMaker
D. Kafka Producer

Solution

  1. Step 1: Identify replication tool for backup clusters

    MirrorMaker is designed to copy data between Kafka clusters for backup and disaster recovery.
  2. 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.
  3. Final Answer:

    MirrorMaker -> Option C
  4. Quick Check:

    Replication to backup = MirrorMaker [OK]
Hint: MirrorMaker copies data between clusters [OK]
Common Mistakes:
  • Choosing Kafka Connect which is for integration, not replication
  • Confusing Kafka Streams with replication
  • Thinking Kafka Producer replicates data
3. Given the following MirrorMaker command, what is its purpose?
bin/kafka-mirror-maker.sh --consumer.config consumer.properties --producer.config producer.properties --whitelist='topic1,topic2'
medium
A. Consume messages from topic1 and topic2 without replication
B. Delete topic1 and topic2 from the target cluster
C. Produce messages to topic1 and topic2 only on source cluster
D. Replicate only topic1 and topic2 from source to target cluster

Solution

  1. Step 1: Understand MirrorMaker command components

    The command uses consumer and producer configs and a whitelist of topics to replicate.
  2. Step 2: Interpret whitelist usage

    The whitelist='topic1,topic2' means only these topics are replicated from source to target cluster.
  3. Final Answer:

    Replicate only topic1 and topic2 from source to target cluster -> Option D
  4. Quick Check:

    Whitelist limits topics replicated [OK]
Hint: Whitelist limits topics MirrorMaker replicates [OK]
Common Mistakes:
  • Thinking it only consumes without replication
  • Assuming it produces only on source cluster
  • Believing it deletes topics
4. You wrote a MirrorMaker config but replication fails. Which is a likely cause?
bootstrap.servers=source:9092
group.id=mirror-group
whitelist=topicA,topicB

What is wrong?
medium
A. The whitelist should be 'whitelist='topicA,topicB' with quotes
B. Missing producer bootstrap.servers config for target cluster
C. group.id should be 'producer-group' instead of 'mirror-group'
D. bootstrap.servers should point to target cluster, not source

Solution

  1. Step 1: Check MirrorMaker config requirements

    MirrorMaker needs both consumer (source) and producer (target) bootstrap.servers configs to replicate data.
  2. Step 2: Identify missing config

    The given config only shows source bootstrap.servers; missing producer config causes replication failure.
  3. Final Answer:

    Missing producer bootstrap.servers config for target cluster -> Option B
  4. Quick Check:

    Both consumer and producer configs needed [OK]
Hint: Both consumer and producer configs are required [OK]
Common Mistakes:
  • Thinking quotes are mandatory around whitelist
  • Confusing group.id with producer group
  • Setting bootstrap.servers to target cluster only
5. You want to ensure minimal data loss during a disaster. Which combination is best for Kafka disaster recovery?
hard
A. Use topic replication factor 3 and MirrorMaker to backup cluster
B. Use only MirrorMaker without replication factor increase
C. Use replication factor 1 and rely on manual backups
D. Use Kafka Streams to replicate data to backup cluster

Solution

  1. Step 1: Understand replication factor role

    A replication factor of 3 means data is copied to 3 brokers, reducing data loss risk.
  2. Step 2: Combine with MirrorMaker backup

    MirrorMaker copies data to a separate cluster, adding disaster recovery protection.
  3. Final Answer:

    Use topic replication factor 3 and MirrorMaker to backup cluster -> Option A
  4. Quick Check:

    Replication + MirrorMaker = minimal data loss [OK]
Hint: Combine replication factor and MirrorMaker for best safety [OK]
Common Mistakes:
  • Relying only on MirrorMaker without replication
  • Using replication factor 1 which risks data loss
  • Confusing Kafka Streams with replication tool
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard