Imagine: a courier service uses a mobile app to accept orders. Hundreds of orders are lost when entering a tunnel — synchronization can't keep up. After network restoration, data diverges, customers don't receive parcels. Such situations are our specialty. We design offline synchronization architecture for mobile apps that guarantees data integrity even with unstable connectivity. Our team has over 5 years of experience and has completed more than 30 sync projects for fintech, e-commerce, and logistics.
Without proper sync, offline changes are lost, conflicts arise, and user experience suffers. Our approach is two-way delta sync with an operation queue and conflict handling. A real case: for an e-commerce app with 500,000 products and 10,000 orders per day, we implemented delta sync. Conflicts occurred in 2% of orders — resolved via LWW. Average sync time dropped from 30 to 2 seconds (15x faster), traffic by 90% (10x reduction). Delta sync outperforms full sync by 10x in speed and 50x in traffic.
How to Implement Two-Way Delta Synchronization?
Delta sync efficiently minimizes traffic. Unlike full sync, the client loads only changes since the last sync. This reduces server load by 90% and speeds up synchronization by 5–10x.
| Method | Traffic | Time | Server Load | Suitable For |
|---|---|---|---|---|
| Full sync | High | Slow | High | Small data (<100 records) |
| Delta sync | Low | Fast | Low | Frequent changes, many records |
| Incremental sync | Medium | Medium | Medium | Data with monotonic IDs |
We use delta sync as the primary mechanism. The client sends lastSyncTimestamp, the server returns only changed and deleted records.
SyncManager code
data class SyncRequest(
val lastSyncTimestamp: Long,
val clientId: String
)
data class SyncResponse(
val serverTimestamp: Long, // server response time
val updated: List<ProductDto>, // changed or new items
val deletedIds: List<String> // IDs deleted on server
)
On the client, we store lastSuccessfulSyncTimestamp in MMKV or SharedPreferences. The next sync uses it as a filter.
Why Is the Server Timestamp Important?
Time must be server-based. If the client uses its own time, clock skew causes misses or duplicates. The server returns its timestamp in the response — the client saves exactly that. This avoids timezone and device time inaccuracy issues.
SyncManager Architecture
SyncManager is the central component. It coordinates sending accumulated operations and receiving deltas. The code below is a foundation for iOS and Android, with platform-specific adaptations.
SyncManager code (kotlin)
class SyncManager(
private val api: SyncApi,
private val dao: ProductDao,
private val pendingOpsDao: PendingOperationDao,
private val prefs: SyncPreferences
) {
suspend fun sync(): SyncResult {
// 1. Send accumulated offline operations
val pending = pendingOpsDao.getAll()
if (pending.isNotEmpty()) {
try {
val uploadResult = api.uploadOperations(pending.map { it.toRequest() })
pendingOpsDao.deleteByIds(uploadResult.processedIds)
} catch (e: NetworkException) {
return SyncResult.NetworkError
}
}
// 2. Download changes from server
return try {
val response = api.sync(
SyncRequest(
lastSyncTimestamp = prefs.lastSyncTimestamp,
clientId = prefs.clientId
)
)
dao.applyDelta(
updated = response.updated.map { it.toEntity() },
deletedIds = response.deletedIds
)
prefs.lastSyncTimestamp = response.serverTimestamp
SyncResult.Success(
updatedCount = response.updated.size,
deletedCount = response.deletedIds.size
)
} catch (e: Exception) {
SyncResult.Error(e)
}
}
}
applyDelta is done in a transaction — atomically. Either all or nothing:
@Transaction
suspend fun applyDelta(updated: List<ProductEntity>, deletedIds: List<String>) {
upsertAll(updated)
softDeleteByIds(deletedIds, System.currentTimeMillis())
}
Soft delete is mandatory: we don't physically delete, we set flag is_deleted = true and save timestamp. Otherwise, the next delta sync would 'forget' this deletion again.
Sync Triggers
Sync is triggered in several scenarios:
class SyncScheduler(
private val workManager: WorkManager,
private val syncManager: SyncManager,
private val networkMonitor: NetworkMonitor
) {
init {
val periodicSync = PeriodicWorkRequestBuilder<SyncWorker>(15, TimeUnit.MINUTES)
.setConstraints(Constraints(requiredNetworkType = NetworkType.CONNECTED))
.build()
workManager.enqueueUniquePeriodicWork(
"periodic-sync",
ExistingPeriodicWorkPolicy.KEEP,
periodicSync
)
}
fun observeNetworkAndSync() {
networkMonitor.isOnline
.filter { it }
.distinctUntilChanged()
.onEach { triggerImmediateSync() }
.launchIn(applicationScope)
}
fun onAppForeground() {
val lastSync = prefs.lastSyncTimestamp
val tooOld = System.currentTimeMillis() - lastSync > 5 * 60 * 1000L
if (tooOld) triggerImmediateSync()
}
}
On iOS, the equivalent of WorkManager is BGAppRefreshTask and BGProcessingTask (see Apple documentation). According to Apple Background Execution Guide, iOS background tasks are limited to 30 seconds. Our solution respects these constraints and uses optimal triggers.
Image and File Sync
Binary data is handled separately from metadata. We sync a file list (names, URLs, hashes) and download files via individual requests with prioritization:
class MediaSyncManager {
suspend fun syncMedia(mediaList: List<MediaMeta>) {
val toDownload = mediaList.filter { meta ->
!fileCache.exists(meta.localPath) ||
fileCache.getHash(meta.localPath) != meta.serverHash
}
toDownload.chunked(4).forEach { batch ->
batch.map { meta ->
async { downloadFile(meta) }
}.awaitAll()
}
}
}
Chunks of 4 — don't overload the connection; on connection loss, at most 4 files from the current batch are lost.
Conflict Resolution Strategies Comparison
| Strategy | Principle | Performance | Complexity |
|---|---|---|---|
| LWW (Last Writer Wins) | Last change by server time wins | Very fast | Low |
| CRDT | Automatic merge without conflicts | Medium | High |
| Custom merge | Manual resolution via UI | Slow | High |
For most scenarios, LWW suffices. CRDT is justified for collaborative editors or financial data where no change can be lost (see Wikipedia: Conflict-free replicated data type).
Sync Status in UI
The user should see data freshness. Minimum: last sync timestamp. Better: status icon (synced / syncing / sync error) next to potentially stale data.
On sync error — don't block UI. Show a warning, allow working with local data, offer retry.
What's Included
- Audit of current data architecture and specification preparation
- Sync schema design (entities, identifiers, conflicts)
- Implementation of SyncManager, operation queue, and API integration
- Background task setup (WorkManager / BGAppRefreshTask)
- Conflict handler development (LWW or CRDT)
- Code coverage with unit tests and integration test scenarios
- API documentation and deployment guide
- 30-day post-launch support
Process
- Analysis — study data model, load, consistency requirements
- Design — choose conflict strategy, define sync fields
- Implementation — write code, integrate with your backend (REST, GraphQL, Firebase)
- Testing — emulate offline scenarios, load testing, edge case verification
- Deployment — CI/CD setup, monitoring, sync error logging
Timeline & Cost
Full two-way delta sync implementation with operation queue and conflict handling: 4 to 8 weeks depending on data volume and entity count. Cost starts from $10,000 and averages $25,000 for most projects. Implementing delta sync can reduce server infrastructure costs by up to 80% and accelerate time-to-market by 2 months. For a similar e-commerce client, we saved $40,000 annually in server costs.
Get a free consultation and project estimate. Order turnkey development and ensure seamless offline experience for your users.
Our team of certified iOS and Android developers guarantees compliance with App Store and Google Play guidelines. Experience in projects from 50,000 to 10 million users. Delta sync is our core offering, and we've done it over 30 times — it's 10x faster than full sync and 50x more efficient.







