Naar hoofdinhoud
🔒 Voorbeeldmodus. De eerste vijftien Foundations-lessen zijn gratis; deze is Pro. Start een 7-daagse trial om de editor, AI-hints en de rest van het curriculum te ontgrendelen. Kaart vereist, op elk moment opzegbaar in Dashboard.Start 7-daagse trial →
← CursussenSystem Design for Python JuniorsModule 1 · Basisprincipes van systeemontwerpDatabasereplicatiepredict7 / 105
+100 XP
Opdracht
📝 **Taak:** Voorspel de uitvoer van drie regels van een profielupdatestroom: lees replica vóór synchronisatie, lees primaire post-schrijf, lees replica na synchronisatie. 📋 Implementeer bovenstaande functie. Tests worden automatisch uitgevoerd. 💡 **Hint:** Herlees de theorie als je vastloopt.
Voorspel uitvoer

Lees de code zorgvuldig

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.

Wat zal het programma uitprinten? Schrijf hier:

💬 Discussie

Wees de eerste — stel een vraag of deel een tip.
Log in om mee te doen aan de discussie. Lezen is gratis.
Discussie laden…