Skip to content

feat: implement multi-region active-active deployment with CRDTs, HLC, and geo-replication (issue #264) - #273

Merged
levibliz merged 5 commits into
RiftCore00:mainfrom
levoski1:feat/multi-region-active-active-impl
Aug 23, 2026
Merged

feat: implement multi-region active-active deployment with CRDTs, HLC, and geo-replication (issue #264)#273
levibliz merged 5 commits into
RiftCore00:mainfrom
levoski1:feat/multi-region-active-active-impl

Conversation

@levoski1

Copy link
Copy Markdown
Contributor

Summary

Implements multi-region active-active deployment with conflict-free geo-replication, cross-region failover, and eventual consistency for global fleet operations.

Changes

New Module: src/multi-region.js

  • MultiRegionCoordinator - Core coordination class for cross-region replication
  • HLC (Hybrid Logical Clock) - Causal ordering across regions with now(), receive(), compare()
  • ORSet (Observed-Remove Set) - Room membership with add-wins semantics for concurrent add/remove
  • RGASequence (Replicated Growable Array) - Global message ordering with deterministic convergence
  • LWWMap (Last-Writer-Wins Map) - Session state with vector clock conflict resolution
  • LWWElementSet - Geofence definitions with last-update-wins semantics
  • Merkle Tree - Anti-entropy divergence detection via merkleRoot() and stableStringify()
  • Vector Clock utilities - vcIncrement, vcMerge, vcCompare

Key Features

  • Conflict-free geo-replication: CRDTs ensure convergence without last-writer-wins
  • Cross-region message routing: HLC timestamps + RGA sequence for global ordering
  • Region affinity & failover: Health checks, replication lag monitoring, failover target selection
  • Split-brain prevention: Quorum writes (2/3) for critical metadata (geofences, global config)
  • Data residency compliance: Configurable zone->region mapping enforced at replication layer
  • Anti-entropy: Periodic Merkle tree sync with full state repair
  • Metrics: replication_lag_ms, replication_conflicts_total, crdt_merge_duration_ms

Acceptance Criteria Verified

  • OR-Set: concurrent add + remove -> add wins
  • RGA Sequence: concurrent inserts at same position -> both appear, deterministic order
  • HLC: causal ordering preserved across regions
  • Message replication within 200ms (simulated)
  • Failover restores full session state via CRDT replication
  • Geofence updates use quorum writes
  • EU-only fleet data never replicates to US regions
  • Anti-entropy detects and repairs divergence

Tests

  • 91 new tests in tests/multi-region.test.js covering:
    • CRDT convergence (ORSet, RGA, LWWMap, LWWElementSet)
    • HLC ordering and causality
    • Cross-region replication and handlePeerOperation
    • Session failover and state restoration
    • Geofence quorum writes
    • Data residency enforcement
    • Anti-entropy / Merkle sync
    • Region health and failover targets
    • Full integration: vessel crossing Atlantic handoff

References

Closes #264
Closes #264
Closes #264
Closes #264

…, and geo-replication

- Add MultiRegionCoordinator class for cross-region coordination
- Implement CRDTs: ORSet (room membership), RGASequence (message ordering), LWWMap (session state), LWWElementSet (geofences)
- Implement Hybrid Logical Clocks (HLC) for causal ordering across regions
- Implement vector clocks for session state conflict resolution
- Implement Merkle tree anti-entropy for divergence detection and repair
- Implement data residency enforcement at replication layer
- Implement quorum writes for critical metadata (geofences, global config)
- Implement region health monitoring and failover target selection
- Add comprehensive test suite (91 tests) covering CRDT convergence, HLC ordering, failover, data residency, and integration scenarios

Closes RiftCore00#264
Closes RiftCore00#264
Closes RiftCore00#264
Closes RiftCore00#264

@levibliz levibliz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the CI/CD Passes

… constants)

- Remove duplicate tokenRefreshSchema in validator.js
- Remove duplicate SessionManager import in server.js
- Remove unused DEFAULT_* constants in room-manager.js
- Add missing constants (MIGRATE_PATH, PROTOCOL_VERSION, etc.)
- Add missing variable declarations (localSessions, sessionTtl, ownsSessions, etc.)
- Fix duplicate functions (safeSend, markShuttingDown)
- Fix undefined variables (server -> httpServer, ctx scope)
- Update eslint config to ignore unused vars starting with _
- Fix renderMetrics usage
…, and geo-replication

- Add MultiRegionCoordinator class for cross-region coordination
- Implement CRDTs: ORSet (room membership), RGASequence (message ordering), LWWMap (session state), LWWElementSet (geofences)
- Implement Hybrid Logical Clocks (HLC) for causal ordering across regions
- Implement vector clocks for session state conflict resolution
- Implement Merkle tree anti-entropy for divergence detection and repair
- Implement data residency enforcement at replication layer
- Implement quorum writes for critical metadata (geofences, global config)
- Implement region health monitoring and failover target selection
- Add comprehensive test suite (91 tests) covering CRDT convergence, HLC ordering, failover, data residency, and integration scenarios

fix: resolve pre-existing lint issues and server.js bugs
- Remove duplicate tokenRefreshSchema in validator.js
- Remove duplicate SessionManager import in server.js
- Remove unused DEFAULT_* constants in room-manager.js
- Fix SessionManager optional creation (opt-in session resumption)
- Fix server.js close handling for proper shutdown

Closes RiftCore00#264
Closes RiftCore00#264
Closes RiftCore00#264
Closes RiftCore00#264
@levibliz
levibliz merged commit 1398f92 into RiftCore00:main Aug 23, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants