Skip to content

feat: implement offline-first subscription sync layer with CRDT#697

Merged
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
rindicomfort:feat/offline-first-crdt-sync
Jun 28, 2026
Merged

feat: implement offline-first subscription sync layer with CRDT#697
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
rindicomfort:feat/offline-first-crdt-sync

Conversation

@rindicomfort

Copy link
Copy Markdown
Contributor

Resolves #665

Context

This pull request introduces a robust offline-first synchronization layer for SubTrackr subscription data management. It allows users to create, update, delete, and toggle subscriptions offline, with automatic deterministic state merging and conflict resolution on network recovery.

Implementation Details

  1. NetworkMonitor (src/services/network/networkMonitor.ts):

    • Monitors connectivity events using @react-native-community/netinfo.
    • Exposes listener and query interfaces for online status.
  2. SubscriptionCRDT (src/services/cache/crdt.ts):

    • Implements a State-based LWW-Element-Set + property-level LWW-Register CRDT merge engine.
    • Deterministically merges divergent subscription states, managing additions, modifications, and tombstoned deletions.
  3. useSubscriptionStore Integration (src/store/subscriptionStore.ts):

    • Extends Zustand state with syncStatus ('idle' | 'pending' | 'syncing' | 'conflict' | 'error') and crdtMetadata.
    • Automatically timestamps modifications and schedules synchronization immediately if online.
    • Implements persistent AsyncStorage serialization for CRDT metadata.
  4. useOfflineSync Hook (src/hooks/useOfflineSync.ts):

    • Monitors network transitions to auto-trigger synchronization upon connection recovery.
    • Utilizes exponential backoff for failed/transient retry attempts (starting at 1s, capped at 60s).
  5. Test Coverage:

    • src/services/cache/__tests__/crdt.test.ts (covers property-level merging, deletion priorities, tombstones, and algebraic correctness).
    • src/hooks/__tests__/useOfflineSync.test.ts (covers hook recovery triggers and exponential backoff retry cycles).
  6. Documentation:

    • Added complete architecture and sync guarantees design doc in docs/offline-architecture.md.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@rindicomfort Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17 Smartdevs17 merged commit aa78e09 into Smartdevs17:main Jun 28, 2026
8 of 31 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.

Implement offline-first subscription data synchronization layer with CRDT

2 participants