Service Layer high complexity mobile
3
Dependencies
2
Dependents
7
Entities
0
Integrations

Description

Processes the mutation outbox by polling pending Drift table rows and uploading them to the backend when connectivity is available. Implements exponential backoff (1s, 2s, 4s … 60s cap) per operation, tracking attempt count and last-attempt timestamp. Triggers JWT auto-refresh via ApiHttpClient before sync attempts that follow long offline periods.

Feature: Background Sync

sync-queue-service

Sources & reasoning

Core driver of the Background Sync feature - owns the upload cycle that moves queued local mutations to the backend. Exponential backoff and connectivity-aware polling are essential to ensure reliable data delivery without battery drain or server overload on reconnect, preserving Bufdir reporting integrity for offline-captured activity registrations and expense entries.

No source references — this artifact was included based on reasoning alone (see above).

Responsibilities

  • Poll the Drift mutation outbox for pending queued operations ordered by insertion time
  • Upload each queued mutation to the REST API when network connectivity is detected
  • Apply exponential backoff on transient upload failures up to the 60s cap
  • Invoke ApiHttpClient JWT auto-refresh to handle token expiry before sync attempts
  • Emit sync status and completion events for downstream consumers

Interfaces

startSync(): Future<SyncResult>
pauseSync(): void
resumeSync(): void
getPendingCount(): Future<int>
onSyncStatus: Stream<SyncStatus>
clearCompletedEntries(): Future<void>