Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSystem Design for Python JuniorsModule 1 · System Design FundamentalsDatabase replicationpredict7 / 105
+100 XP
Task
📝 **Task:** Predict the 3-line output from a profile-update flow: read replica pre-sync, read primary post-write, read replica post-sync. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

class Replica:
    def __init__(self):
        self.state = {}

    def replicate(self, primary_state):
        # Sync up to the primary's current state.
        self.state = dict(primary_state)


class Primary:
    def __init__(self):
        self.state = {"profile": "Alice"}    # initial


primary = Primary()
replica = Replica()
replica.replicate(primary.state)             # initial sync

# User updates profile on the primary.
primary.state["profile"] = "Alicia"

# Read 1 — went to the lagging replica BEFORE it caught up.
print(replica.state.get("profile"))

# Read 2 — routed to primary (read-your-own-writes pattern).
print(primary.state.get("profile"))

# Replica eventually catches up.
replica.replicate(primary.state)

# Read 3 — same replica, now post-sync.
print(replica.state.get("profile"))

# What does this print? Type your prediction.

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…