{
  "docVersion": 1,
  "id": "template-distributed-lock-service",
  "name": "Distributed lock service",
  "purpose": "Lease-based locking over a Raft core with fencing tokens: Worker A holds token 33; its paused twin still believes it owns token 32 and is fenced at the resource.",
  "nodes": {
    "wa": {
      "type": "k8s",
      "label": "Worker A",
      "x": 20,
      "y": 60,
      "runtime": "holds lease · token 33",
      "color": "green"
    },
    "wb": {
      "type": "k8s",
      "label": "Worker B",
      "x": 20,
      "y": 280,
      "runtime": "queued — waiting"
    },
    "stale": {
      "type": "k8s",
      "label": "Worker A′ (GC-paused)",
      "x": 20,
      "y": 500,
      "runtime": "stale · token 32",
      "color": "red",
      "style": "dashed",
      "notes": "The nightmare case: paused past its lease, resumes, and still thinks it holds the lock. Without fencing this corrupts data; with fencing the write bounces."
    },
    "lockL": {
      "type": "vault",
      "label": "Lock service (leader)",
      "x": 380,
      "y": 170,
      "runtime": "lease 10s · mints tokens",
      "color": "blue",
      "patterns": [
        "leader-elected"
      ],
      "notes": "Lock state replicates through a consistent core — a lock service on a cache (the Redlock shape) trades away exactly the safety you came for."
    },
    "lockF": {
      "type": "vault",
      "label": "Lock replicas ×2",
      "x": 380,
      "y": 400,
      "runtime": "raft followers",
      "patterns": [
        "replicated"
      ]
    },
    "store": {
      "type": "storage",
      "label": "Protected resource",
      "x": 740,
      "y": 500,
      "runtime": "accepts token ≥ 33",
      "color": "amber",
      "notes": "The final arbiter: checks the fencing token on every write. This check is what makes the whole scheme safe — the lock alone never is."
    }
  },
  "edges": {
    "e1": {
      "from": "wa",
      "to": "lockL",
      "fromSide": "right",
      "toSide": "left",
      "label": "acquire → lease + token 33",
      "animated": true
    },
    "e2": {
      "from": "lockL",
      "to": "wa",
      "fromSide": "top",
      "toSide": "top",
      "label": "heartbeat renew /5s",
      "style": "dashed"
    },
    "e3": {
      "from": "wb",
      "to": "lockL",
      "fromSide": "right",
      "toSide": "left",
      "label": "acquire — queued",
      "style": "dashed"
    },
    "e4": {
      "from": "lockL",
      "to": "lockF",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "raft replicate"
    },
    "e5": {
      "from": "wa",
      "to": "store",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "write (token 33) ✓",
      "animated": true,
      "color": "green",
      "patterns": [
        "authenticated"
      ]
    },
    "e6": {
      "from": "stale",
      "to": "store",
      "fromSide": "right",
      "toSide": "left",
      "label": "write (token 32) ✗ FENCED",
      "style": "dashed",
      "color": "red"
    }
  },
  "boxes": {
    "b1": {
      "x": 340,
      "y": 90,
      "w": 240,
      "h": 500,
      "label": "consistent core",
      "color": "blue",
      "opacity": 0.04
    }
  },
  "texts": {
    "t1": {
      "x": 640,
      "y": 300,
      "text": "the rule: a distributed lock is only as\nsafe as the resource's token check.\nLock + lease + fencing — all three,\nor you have a suggestion, not a lock.",
      "color": "red",
      "size": 12
    }
  },
  "meta": {
    "createdAt": "2026-07-13T09:00:00.000Z",
    "modifiedAt": "2026-07-13T09:00:00.000Z"
  }
}