BackgroundSyncService
Component Detail
Description
Orchestrates the asynchronous synchronization of queued mutations from the local database to the backend REST API. It monitors network availability and processes the sync queue when connectivity is detected. The service coordinates with the retry scheduler to handle transient failures without blocking the main application thread.
background-sync-service
Sources & reasoning
Line 302 explicitly lists "sync queue with retry/backoff" as part of the core offline architecture. The blueprint assigns dedicated components BackgroundSyncService and RetryBackoffScheduler to this feature, confirming it is distinct from the outbox storage layer. Blueprint marks it [MVP], consistent with offline-first being a Phase 1 foundational requirement across all organizations.
-
docs/source/likeperson.md · line 302Offline-first persistence (Drift + SQLCipher encrypted local DB, mutation outbox, sync queue with retry/backoff, ID mapping for offline-created entities, conflict resolver)
Responsibilities
- Detect network connectivity changes and trigger sync attempts
- Dequeue pending mutations and dispatch them to the backend REST API
- Mark mutations as synced or re-queue them on failure
- Coordinate with RetryBackoffScheduler to schedule delayed retries
- Emit sync status events for UI feedback and diagnostic logging
Interfaces
startSync(): Promise<SyncResult>
stopSync(): void
syncNow(): Promise<SyncResult>
getSyncStatus(): SyncStatus
onSyncComplete(handler: (result: SyncResult) => void): void