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 FundamentalsCAP theorempredict10 / 105
+100 XP
Task
📝 **Task:** Predict the four-line verdict from a partition simulator: a CP system, an AP system, a CP system asked to READ stale data, and an AP system asked to READ stale data. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

class Node:
    def __init__(self, name, mode):
        self.name = name
        self.mode = mode               # "CP" or "AP"
        self.partitioned = False
        self.state = {}

    def write(self, key, value):
        if self.partitioned and self.mode == "CP":
            return "refuse"            # would risk inconsistency
        self.state[key] = value
        return "ok"

    def read(self, key):
        if self.partitioned and self.mode == "CP":
            return "refuse"            # better to fail than serve stale
        return self.state.get(key, "missing")

trading = Node("trading", mode="CP")
feed    = Node("feed",    mode="AP")

trading.partitioned = True
feed.partitioned    = True

trading.state = {"price": 100}
feed.state    = {"feed_count": 42}

print(trading.write("price", 101))       # CP partitioned → refuse
print(feed.write("feed_count", 43))      # AP partitioned → ok (local)
print(trading.read("price"))             # CP partitioned read → refuse
print(feed.read("feed_count"))           # AP partitioned read → 43 (fresh local)

# 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…