Consistent Hashing to Rendezvous Hashing Migration Plan
As Sherlock, I'll outline a comprehensive, zero-downtime upgrade plan to migrate a distributed sharding system (e.g., key-value store, database cluster like Cassandra or a custom Dynamo-style system) from consistent hashing (CH) to rendezvous hashing (RH, also known as HRW). RH offers better load balancing in dynamic clusters and simpler node addition/removal with ~1/N data movement per change (vs. K/N in CH with virtual nodes).
Key Assumptions:
- System supports dual writes/reads via client-side or proxy logic.
- Keys are strings/bytes; hashing uses a fast, deterministic function (e.g., XXHash or CityHash for RH:
max over nodes of hash(key + node_id)).
- Cluster has N nodes, replication factor R ≥ 2 for fault tolerance.
- Clients/nodes are upgradable via rolling restarts.
- Background jobs handle data movement/conflict resolution (e.g., via CRDTs, last-write-wins with timestamps, or vector clocks).
- Zero-downtime means <1s p99 latency impact, no data loss, no outages.
Migration Principles:
- Dual Writes: Write to both CH and RH owners during transition.
- Read-from-Old: Reads from CH until cutover.
- Background Catch-Up: Populate RH shards via dual writes + anti-entropy.
- Phased Cutover: Gradual keyspace or node subset switch.
- Idempotency: Writes are idempotent (e.g., via versions/seqnos).
1. Shard Simulation (Pre-Production Validation)
Simulate data movement and performance offline using production snapshots to quantify risks and tune parameters.
Tools & Setup
- Simulator: Custom Go/Rust/Python tool (e.g., using
hashring lib for CH, custom RH impl).
- Data Source: Anonymized snapshot of 10-100M keys from production (via
SELECT COUNT(*) FROM shards or export).
- Cluster Model: Replay current topology (N nodes, virtual nodes if used in CH).
Steps
-
Ownership Mapping:
For each sampled key K:
old_owner = CH_ring.locate(K) # Consistent hash ring
new_owner = argmax_node hash(K + node_id) # RH
if old_owner != new_owner: mark as "mover"
- Compute metrics: % keys moving, GB to migrate, per-node imbalance (stddev <5%).
-
Movement Projections:
| Metric | Target | Alert If |
|---|
| % Keys Moving | <20% | >30% |
| Max Node In/Out | <10% capacity | >20% |
| Post-Migration Balance | Max-min load <5% | >10% |
-
Chaos Simulation:
- Simulate node add/remove/failures under both schemes.
- Traffic Replay: Inject synthetic load (e.g., 1x prod QPS), measure remaps.
-
Validation:
- Run 100+ iterations with cluster sizes N=10..1000.
- Output: Report + JSON artifacts for CI/CD gating.
Timeline: 1-2 weeks pre-rollout. Gate prod migration if sim > thresholds.
2. Rollout Orchestration
Orchestrate via Kubernetes/Helm (nodes), Envoy/Proxy or client SDKs (v2 with dual-hash support). Use a central config store (e.g., etcd, ZooKeeper) for hashing_mode: "ch" | "dual" | "rh".
Phases (Rolling, 1-7 days total)
Timeline:
Prod Canary (10%) → Full Rollout → Cutover → Cleanup
| Phase | Duration | Actions | Client/Node Behavior |
|---|
| 0. Client/Node Upgrades | 1 day (rolling) | Rolling restart nodes/clients to v2 (dual-hash impl). Feature flag enable_rh_dual_writes=false. | Writes: CH only. Reads: CH. |
| 1. Enable Dual Writes | 30min ramp | Set hashing_mode=dual. Dual-write to CH + RH owners (fan-out async). | Writes: CH + RH (idempotent). Reads: CH primary, RH verify (shadow). Background anti-entropy (e.g., Merkle trees) syncs RH shards. |
| 2. Canary Keyspace Partition | 1-2 days | Partition keys by prefix/hash modulo (e.g., 10% buckets). Enable rh_reads=true for bucket 0. | Writes: Always dual. Reads: RH for canary buckets (fallback CH on error). |
| 3. Full Cutover | 1 hour (ramped) | Ramp rh_reads=true across 100% keyspace (10% increments/min). | Writes: Dual → RH-only (after 99th %ile parity). Reads: RH primary. |
| 4. Cleanup | 24-48h | Drain CH shards (delete after TTL/verify empty). | Single RH mode. |
Orchestration Tools
- ArgoCD/Flux: GitOps for config propagation.
- Client-Side: SDKs (e.g., Java/Go) with
HashingMode enum.
- Proxy Mode: Envoy filter computes both hashes, routes accordingly.
- Traffic Shaping: Canary via weighted routing (e.g., 10% traffic to RH-reads).
Data Flow During Dual:
PUT(K,V): owner_ch = CH(K); owner_rh = RH(K); PUT_ch(K,V); PUT_rh(K,V)
GET(K): val_ch = GET_ch(K); if canary: val_rh = GET_rh(K); reconcile if diverge
3. Monitoring
Comprehensive observability to detect anomalies in <5min.
Key Metrics (Prometheus/Grafana Dashboards)
| Category | Metrics | Dashboards/Alerts |
|---|
| Parity | - Dual-write success % (>99.9%)- RH shard catch-up lag (seqno diff <1%)- Key count/size parity (CH vs RH per node)- Divergent reads (#/min) | Parity dashboard: Heatmap node/shard diffs. Alert: >0.1% divergence. |
| Performance | - P99 read/write latency (+<10%)- QPS per scheme- Fan-out overhead (dual-write latency) | Latency histograms. Alert: >20% regression. |
| Balance | - Per-node load (CPU/IO/GB)- RH balance stddev (<5%) | Ring visualizer (CH vs RH). |
| Errors | - Hash computation errors- Owner resolution fails- Anti-entropy repair rate | Error budget: <0.01% overall. |
Logging & Tracing
- Structured Logs:
{"key_prefix": "...", "ch_owner": "n1", "rh_owner": "n2", "moved": true}
- Jaeger/Zipkin: Trace dual-write paths.
- Alerts: PagerDuty on >1min sustained issues (e.g., parity drift >1%).
Success Gates:
- Phase 1: 100% dual-write success for 24h.
- Phase 2: Canary parity 100%, latency stable.
- Phase 3: Global parity >99.99%.
4. Rollback Guardrails
Always Revertible: Dual writes ensure CH remains authoritative until cutover.
Rollback Triggers & Actions
| Trigger | Detection | Rollback Steps |
|---|
| High Errors/Latency | Alert >5min | 1. hashing_mode=ch (reads/writes → CH-only).2. Stop dual writes.3. RH shards "freeze" (read-only). |
| Parity Drift | >0.5% keys diverge | 1. Pause ramp.2. Run emergency anti-entropy.3. Revert if unresolvable. |
| Balance Failure | RH stddev >10% | 1. Revert reads.2. Tune RH (e.g., node_id salting). |
| Manual | Operator dashboard button | Atomic config flip + traffic shift. |
Guardrails
- Circuit Breakers: Client-side: Fail dual-write → CH-only if RH >2x latency.
- Time-Bombs: Auto-rollback after 30min if parity <99%.
- Dark Pool: 1% shadow traffic always on RH for pre-prod validation.
- Post-Mortem: Always simulate rollback in staging.
Total Risk: <0.01% data loss probability, validated via Chaos Engineering (e.g., Gremlin node kills during dual).
This plan ensures a smooth, data-safe migration. If you provide specifics (e.g., cluster size, DB type, client lang), I can refine with code snippets or diagrams.