ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/gossiper/tasks/task-3-3-5-partition-heal
TASK

Implementation

Network partitions split the cluster into isolated groups. After the partition heals, gossip must merge the diverged states. Your task is to simulate this.

Implement:

  1. partition - Block messages to specified nodes
  2. heal - Unblock all nodes
  3. partition_status - Report current partition state
Request:  {"type": "partition", "msg_id": 1, "blocked": ["n3", "n4"]}
Response: {"type": "partition_ok", "in_reply_to": 1}

Request:  {"type": "heal", "msg_id": 2}
Response: {"type": "heal_ok", "in_reply_to": 2}

Request:  {"type": "partition_status", "msg_id": 3}
Response: {"type": "partition_status_ok", "in_reply_to": 3, "blocked": [], "is_partitioned": false, "messages_dropped": 5}

Sample Test Cases

Partition blocks specified nodesTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1","n2"]}}
{"src":"c1","dest":"n1","body":{"type":"partition","msg_id":2,"blocked":["n2"]}}
{"src":"c1","dest":"n1","body":{"type":"partition_status","msg_id":3}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "partition_ok", "in_reply_to": 2, "msg_id": 1}}
{"src": "n1", "dest": "c1", "body": {"type": "partition_status_ok", "blocked": ["n2"], "is_partitioned": true, "messages_dropped": 0, "in_reply_to": 3, "msg_id": 2}}
Heal removes all blocksTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1","n2"]}}
{"src":"c1","dest":"n1","body":{"type":"partition","msg_id":2,"blocked":["n2"]}}
{"src":"c1","dest":"n1","body":{"type":"heal","msg_id":3}}
{"src":"c1","dest":"n1","body":{"type":"partition_status","msg_id":4}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "partition_ok", "in_reply_to": 2, "msg_id": 1}}
{"src": "n1", "dest": "c1", "body": {"type": "heal_ok", "in_reply_to": 3, "msg_id": 2}}
{"src": "n1", "dest": "c1", "body": {"type": "partition_status_ok", "blocked": [], "is_partitioned": false, "messages_dropped": 0, "in_reply_to": 4, "msg_id": 3}}

Hints

Hint 1
A partition blocks all messages between two groups of nodes
Hint 2
Each side continues to gossip internally
Hint 3
On healing, cross-partition gossip resumes and states converge
Hint 4
Track time-to-convergence after partition heals
Hint 5
Implement partition as a blocked-destinations set
OVERVIEW

Theoretical Hub

Concept overview coming soon

Key Concepts

network partitionpartition healingconvergencesplit brain
main.py
python
Simulate Network Partition and Healing - The Gossiper | Build Distributed Systems