Expand description
Path-based Merkle tree for efficient sync verification.
§Design
Uses reverse DNS object IDs to create a natural tree structure:
uk.nhs.patient.record.123
Becomes:
uk ─────────────────── hash(nhs)
└── nhs ───────────── hash(patient)
└── patient ───── hash(record)
└── record ── hash(123, 456, ...)
├── 123 ─ leaf hash
└── 456 ─ leaf hash§Storage Strategy
Merkle nodes are stored separately from data in Redis:
data:uk.nhs.patient.record.123→ SyncItem (evictable by tan curve)merkle:hash:uk.nhs.patient.record→ 32-byte hash (NEVER evicted)merkle:children:uk.nhs.patient.record→ sorted set of child:hash pairs
This allows efficient sync verification even when data is evicted from cache.
§Sync Protocol
- Client sends their root hash
- If different, server sends top-level children with hashes
- Client identifies differing branches
- Drill down until leaves are reached
- Transfer only the differing items
This is O(diff_size × tree_depth) instead of O(total_items).
Structs§
- Merkle
Batch - Batch of Merkle updates to apply atomically.
- Merkle
Cache Store - Redis cache for SQL Merkle tree.
- Merkle
Node - A node in the path-based Merkle tree.
- Path
Merkle - Manages path-based Merkle tree operations.
- Redis
Merkle Store - Redis-backed Merkle tree storage.
- SqlMerkle
Store - SQL-backed Merkle tree storage (ground truth).