Bird
0
0

This Kafka multi-datacenter replication code has a bug. What is it?

medium📝 Debug Q14 of 15
Kafka - Multi-Datacenter and Replication
This Kafka multi-datacenter replication code has a bug. What is it?
def replicate_message(message, datacenters):
    for dc in datacenters:
        if dc == "primary":
            continue
        datacenters[dc].append(message)

clusters = {"primary": [], "backup": []}
replicate_message("hello", clusters)
print(clusters)
AIt causes an infinite loop
BIt tries to append to a string instead of a list
CIt modifies the dictionary keys instead of values
DIt skips replicating to the primary datacenter
Step-by-Step Solution
Solution:
  1. Step 1: Review the replicate_message function logic

    The function skips the datacenter named "primary" and only appends message to others.
  2. Step 2: Understand the impact of skipping primary

    Skipping primary means the original datacenter does not get the message, which is a bug for replication.
  3. Final Answer:

    It skips replicating to the primary datacenter -> Option D
  4. Quick Check:

    Skipping primary = Bug in replication [OK]
Quick Trick: Check which datacenters get the message appended [OK]
Common Mistakes:
  • Thinking it modifies keys instead of values
  • Assuming infinite loop due to for loop
  • Confusing list and string types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes