Bird
0
0

Given this simplified Kafka setup code snippet, what happens if datacenter1 goes down?

medium📝 Predict Output Q13 of 15
Kafka - Multi-Datacenter and Replication
Given this simplified Kafka setup code snippet, what happens if datacenter1 goes down?
clusters = {"datacenter1": ["broker1", "broker2"], "datacenter2": ["broker3", "broker4"]}
replication_factor = 2

# Messages are replicated across datacenters
messages = ["msg1", "msg2"]

# Simulate datacenter1 goes down
del clusters["datacenter1"]

# Consumer reads from datacenter2 if datacenter1 fails
consumer_datacenter = "datacenter2" if "datacenter1" not in clusters else "datacenter1"
print(f"Consumer reads from {consumer_datacenter}")
AConsumer reads from datacenter2
BConsumer reads from datacenter1
CConsumer reads from both datacenters simultaneously
DConsumer fails to read any data
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition for consumer_datacenter

    The code sets consumer_datacenter to datacenter2 if datacenter1 is missing from clusters.
  2. Step 2: Analyze what happens if datacenter1 goes down

    If datacenter1 is removed or down, it won't be in clusters, so consumer_datacenter becomes datacenter2.
  3. Final Answer:

    Consumer reads from datacenter2 -> Option A
  4. Quick Check:

    Failover to datacenter2 = Consumer reads datacenter2 [OK]
Quick Trick: Check condition for datacenter presence in clusters [OK]
Common Mistakes:
  • Assuming consumer always reads datacenter1
  • Thinking consumer reads both datacenters at once
  • Ignoring the if condition logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes