Service Layer medium complexity mobile
0
Dependencies
0
Dependents
5
Entities
0
Integrations

Description

Orchestrates reconciliation between local offline mutations and the remote REST API once connectivity is restored. Drains the mutation outbox with retry and exponential backoff, maps temporary client IDs to server-issued IDs, and resolves conflicts when records were modified on both sides.

Feature: Background Sync

sync-engine

Sources & reasoning

Second canonical feature of the Offline & Sync area per §8. The Core/Shared architecture block explicitly describes mutation outbox, retry/backoff, ID mapping, and conflict resolver - all responsibilities of this feature. MVP because offline support is unsafe without reconciliation.

  • Offline-first persistence (Drift + SQLCipher encrypted local DB, mutation outbox, sync queue with retry/backoff, ID mapping for offline-created entities, conflict resolver)
  • Optimistic mutations with automatic rollback on failure (contact edits and paginated list updates)
  • offline-sync | Offline & Sync | Offline Data Support, Background Sync

Responsibilities

  • Drain mutation outbox against REST API in order
  • Apply exponential backoff and retry on transient failures
  • Map client-generated temporary IDs to server-issued IDs
  • Detect and resolve conflicts using last-write-wins or merge strategies
  • Emit sync lifecycle events (started, progress, completed, failed)

Interfaces

startSync(): Promise<SyncResult>
cancelSync(): void
resolveConflict(local, remote): Resolution
mapTempId(tempId, serverId): void