Everything looks synchronized when a single developer tests an app on Wi-Fi with one simulator. The moment a real user opens their account on an iPad on a flight, checks off three tasks, updates a fourth item on their phone over spotty LTE, and reconnects both devices an hour later, naive REST sync silently drops edits, duplicates records, or resurrects deleted rows.
Multi-device synchronization is one of the hardest problems in mobile app development because networks fail mid-flight and device clocks lie. You do not need an exotic distributed database to solve it cleanly—you need four disciplined primitives shared between your local SQLite store and your backend API.
Why Wall-Clock Timestamps Break Sync
The most common anti-pattern in mobile APIs is GET /items?updated_after=2026-04-23T10:00:00Z. It breaks in three ways:
- Clock skew: A device with its clock set three minutes ahead stamps an old edit in the future, or an older server transaction commits slightly after a newer
updated_attimestamp was generated—causing delta queries to skip rows forever. - In-flight transactions: Two concurrent API writes take 40ms and 120ms to commit. A polling client querying at millisecond 80 advances its
updated_aftercursor past the slower transaction and never sees it. - Hard deletes vanish: Running
DELETE FROM tasks WHERE id = ?leaves no trace for an offline tablet returning three days later.
Replace wall-clock cursors with a server-assigned monotonic sequence (server_seq) and tombstone soft deletes.
The Core Sync Schema (Backend + Local SQLite)
Whether your backend runs PostgreSQL or MySQL and your client runs Flutter (drift / sqflite) or React Native (op-sqlite / WatermelonDB), both sides share the same sync contract:
-- Backend authoritative table (PostgreSQL)
CREATE TABLE project_notes (
id UUID PRIMARY KEY,
account_id BIGINT NOT NULL,
title TEXT NOT NULL,
body TEXT NOT NULL,
version INTEGER NOT NULL DEFAULT 1,
server_seq BIGINT NOT NULL,
deleted_at TIMESTAMPTZ,
updated_by VARCHAR(64) NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE SEQUENCE global_sync_seq START 1;
CREATE INDEX idx_notes_account_seq ON project_notes (account_id, server_seq);
-- Idempotency ledger to absorb mobile retries safely
CREATE TABLE sync_mutations (
mutation_id UUID PRIMARY KEY,
account_id BIGINT NOT NULL,
applied_seq BIGINT NOT NULL,
response_body JSONB NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
On the mobile device, never mutate synced tables directly from UI buttons and fire HTTP calls in the background without persistence. Write every user intent to a local outbox table inside a single SQLite transaction:
- Apply the optimistic change to the local
project_notestable so the UI responds in under 16ms—keeping frame budgets clean as outlined in Flutter's performance guidelines and React Native's new architecture. - Insert a row into local
pending_mutationswith a client-generated UUID (mutation_id),base_version, and serialized payload. - A single background sync worker drains
pending_mutationssequentially whenever connectivity is healthy.
Push First, Then Pull: The Two-Step Sync Cycle
Running push and pull in the wrong order causes local pending edits to get overwritten by stale server state mid-sync. Always execute Push -> Pull per sync cycle:
1. Push Local Outbox (POST /api/v1/sync/push)
The client sends a batch of pending mutations with each record's mutation_id and base_version:
{
"device_id": "ios_9f42c1",
"mutations": [
{
"mutation_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"entity": "project_notes",
"record_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"op": "upsert",
"base_version": 4,
"payload": {
"title": "Site Inspection #42",
"body": "Replaced breaker panel cover."
}
}
]
}
Inside one database transaction, the server:
- Checks
sync_mutationsformutation_id. If found, it skips execution and returns the cachedresponse_body(true idempotency). - Compares
base_versionagainst the current row'sversion. - If
base_version == current.version, applies the update, incrementsversion, assignsnextval('global_sync_seq')toserver_seq, and records the mutation. - If
base_version < current.version, applies the configured conflict rule and returns the winning state or conflict marker.
2. Pull Deltas (GET /api/v1/sync/pull?since_seq=18420&limit=200)
Once pending mutations are acknowledged and deleted from the local outbox, the client pulls changes where server_seq > last_pulled_seq ORDER BY server_seq ASC LIMIT 200. It loops until has_more is false, updating last_pulled_seq in SQLite only after each batch commits locally.
Choosing the Right Conflict Resolution Strategy
Different entities inside the same app often need different conflict rules. Pick deliberately rather than defaulting blindly:
| Strategy | How It Works | Strengths | Failure Mode / Risk | Ideal Use Cases |
|---|---|---|---|---|
| Server-Ordered Last Write Wins | Higher server_seq wins entire row |
Simple to reason about and audit | Concurrent offline edits on separate fields overwrite each other | User preferences, profile settings, status flags |
Field-Level Merge (changed_fields) |
Client sends only dirty columns + base_version |
Preserves non-overlapping edits (e.g., Device A edits title, Device B marks done) | Slightly larger mutation payload & merge logic | Task managers, CRM records, inspection forms |
| Append-Only Event Log | Mutations are immutable facts (add comment, check in, stock adjustment) | Zero overwrite conflicts by design | Requires derived projection tables for fast reads | Financial ledgers, inventory counts, field logs |
| CRDTs (Automerge / Yjs) | Mathematical merge on every character/tree op | Real-time co-editing without central lock | High storage overhead, hard schema migrations | Collaborative docs, whiteboards, rich notes |
For most multi-device B2B and consumer apps, append-only logs for activity/transactions + field-level merge for editable records eliminates 99% of user-visible data loss without the operational complexity of CRDTs.
Handling Real-World Mobile Edge Cases
- Re-syncing after long offline gaps: Set a retention window on tombstones (for example, 90 days). If a device wakes up with
since_seqolder than your tombstone purge watermark, return410 Gone(reset_required: true) so the client runs a clean full snapshot hydration instead of missing old deletions. - Large binary attachments: Never block JSON metadata sync on 15MB photo uploads. Sync the attachment record (
upload_status: "pending") immediately, upload binaries separately via pre-signed S3/R2 URLs, and patchremote_urlonce uploaded. - Cross-device live nudges: Polling wastes battery. Keep sync authoritative over HTTP
push/pull, and use silent push notifications (APNscontent-available, FCM data messages) or lightweight WebSockets solely as a wakeup signal saying "newserver_seqavailable—run pull now." - Tombstone cleanup without orphan resurrection: Never allow an old offline client to
PUTan update to a row whosedeleted_at IS NOT NULLunless your product explicitly supports "restore from trash."
Shipping Sync Without Burning Months of Runway
Sync bugs are notoriously expensive to retrofit after launch because every table, local cache, and optimistic UI hook assumes direct online reads. Getting the schema, outbox queue, and sequence cursors right upfront saves weeks of support pain later.
If you need an experienced principal engineer to design or debug your offline and multi-device sync layer, I work directly with product teams at $55/day (8–9 hours of focused engineering) or $1,999/month dedicated delivery—backed by 170+ shipped case studies across global SaaS and mobile products. You can also explore dedicated developer engagement or book a technical architecture review through our launch consulting page.
Building a multi-device mobile app and want a sync protocol that survives real-world networks? Get in touch here with your data model and stack.