Skip to content

Break a Distributed System on Purpose

Category System Design & Kubernetes
Status โœ… Completed
Repo nextwork-break-a-distributed-system-on-purpose
Original NextWork guide nextwork.ai

Learning project

Practice work following a NextWork guide, separate from my production projects.

๐Ÿ“š NextWork learning project. This is a practice project I built while working through NextWork's Break a Distributed System on Purpose guide. It is part of my Learning portfolio and is fully separate from my production projects.

Category: Learning โ€บ System Design & Kubernetes
Status: โœ… Completed

Overview

Partitions aren't hypothetical. Here I cut a node off a Docker network and watch the two choices play out: refuse the write and stay consistent, or accept it and split. Then I heal the split by comparing write times.

Summary

Three replicas of my own key-value node (standard-library Python) ran in Docker on one bridge network, and the experiment script checked every step. With all nodes connected, a CP write reached all three. With node3 cut off, CP refused the write (503) and no node kept it. After switching to AP, cutting off node3 and then node1 gave split-brain: node1 said 'one' and node3 said 'three'. The secret mission's heal step (each node pulls from its peers and the newest write wins) brought all three to 'three'.

The checks behind this are in docs/verification.txt.

Skills & tools

CAP theorem, Replication, Network partitions, Docker Compose, Python http.server, Conflict resolution

What I built

  • node.py: GET/PUT /kv/<key>, GET/POST /policy (CP or AP at runtime), /peer-write, /dump and /heal. In CP mode it checks every peer first, so a refused write leaves no copy anywhere. My first version did leave one, and the experiment now checks for that.
  • Dockerfile (no dependencies) and docker-compose.yml: three nodes on capnet, ports 5001โ€“5003.
  • experiment.sh: connected CP write โ†’ partitioned CP refusal (checked on two nodes) โ†’ AP split-brain from both sides โ†’ heal and converge, with an expected value after every step.

How to run

./experiment.sh            # builds, runs every step, tears down
# by hand:
docker compose up --build -d
curl -X PUT localhost:5001/kv/fruit -H 'Content-Type: application/json' -d '{"value":"apple"}'
docker network disconnect capnet node3

Verification

I ran the verification command on 2026-12-03. The full output is in docs/verification.txt.

./experiment.sh

Notes

Rewritten on 3 Dec 2026: the earlier Flask version followed the guide's code. This one is mine end to end, and the API names changed with it.


Original project: https://nextwork.ai/projects/56330f0f-e0c6-474e-bda9-d625ff412ba0 ยท Part of my NextWork Learning portfolio (hub).

Verification output

From docs/verification.txt:

$ ./experiment.sh

-- 1. all connected, CP
ok   write fruit=apple on node1: 200
ok   node :5001 reads fruit: apple
ok   node :5002 reads fruit: apple
ok   node :5003 reads fruit: apple
-- 2. node3 cut off, CP refuses
ok   write town=Lima on node1: 503
{"node": "node1", "policy": "CP", "refused": "town", "unreachable": ["node3:5000"]}
ok   node1 kept nothing for town: (none)
ok   node2 kept nothing for town either: (none)
-- 3. switch to AP and split the cluster two ways
ok   AP write owner=one on node1 (node3 cut off): 200
{"node": "node1", "policy": "AP", "stored": "owner", "copied_to": ["node2:5000"], "not_copied_to": ["node3:5000"]}
ok   AP write owner=three on node3 (node1 cut off): 200
{"node": "node3", "policy": "AP", "stored": "owner", "copied_to": ["node2:5000"], "not_copied_to": ["node1:5000"]}
ok   node1 still says: one
ok   node3 says: three
-- 4. heal: every node pulls from its peers, newest write wins
ok   node :5001 after heal: three
ok   node :5002 after heal: three
ok   node :5003 after heal: three
EVERY CAP CHECK PASSED

[exit code 0]