Back to all devlogs
Cross-platform4 min read

Architecting Offline-First Mobile Sync for iOS & Android

How we designed a Conflict-Free Replicated Data Type (CRDT) engine to power real-time mobile sync with zero data loss.

mobilearchitecturecrdtsqliteoffline-first

Architecting Offline-First Mobile Sync for iOS & Android

When building mobile applications for developers and power users, the single most frustrating experience is a loading spinner when offline, or worse, losing notes due to sync conflicts.

For elnitodev apps like Unburden and StickFit, our design philosophy is strictly local-first:

  1. All reads and writes occur against local on-device SQLite databases first.
  2. Network requests happen purely asynchronously in background workers.
  3. Conflicts are resolved deterministically using state-based CRDTs (Conflict-free Replicated Data Types).

The Synchronization Lifecycle

[User Action] -> [Local SQLite Database] -> [Optimistic UI Update]
                      |
              [Background Sync Queue]
                      |
              [Encrypted Payload] -> [WebSocket / HTTP2] -> [Sync Node]

Why not standard REST upserts?

Standard REST APIs rely on last-write-wins (LWW) with server timestamps. On mobile networks with flaky tunnels, packet drops, or airplane mode switching, LWW leads to silent data corruption when two devices edit offline concurrently.

With state-based CRDTs, each edit generates an immutable operation with a logical Lamport timestamp and a client node ID. When the client reconnects, both operation graphs merge seamlessly without asking the user to manually pick "Version A or Version B".

Performance Benchmark

  • Cold read time: < 4ms
  • Local encryption latency (AES-GCM): < 2ms
  • Sync turnaround time on 4G LTE: ~120ms

In our next devlog, we will explore background tasks and push notification triggers for silent background downloads on iOS and Android.

Interactive Mobile Benchmark Data

Cold-Read & Query Latency (Milliseconds)

Measured on 4G mobile connection with 50,000 localized records. Lower is better.

Traditional REST Endpoint245 ms
GraphQL Over Mobile Cellular185 ms
Remote WebSocket Stream92 ms
elnitodev Local-First CRDT3.4 ms

By serving reads synchronously from an encrypted local SQLite engine and processing conflict resolution in background micro-queues, cold reads drop from hundreds of milliseconds to under 4ms.

98.6% Latency Reduction
Interactive Architecture Flowchart

The Synchronization Lifecycle

Interactive pipeline showing how elnitodev mobile applications achieve instant optimistic on-device commits while streaming background cryptographic state synchronization.

[Local SQLite Database]1 - 3 ms

Encrypted SQLite3 (WAL Mode + Lamport Clock)

Direct atomic write into local SQLite storage with Write-Ahead Logging (WAL). Computes the monotonic Lamport timestamp and appends the immutable delta to on-device storage.

Implementation Contract
db.prepare("""
  INSERT INTO document_deltas (id, doc_id, lamport, client_id, delta)
  VALUES (?, ?, ?, ?, ?)
""").run(uuid, docId, nextLamport(), deviceId, binaryDelta)

Why not standard REST upserts?

In typical cloud web apps, standard HTTP REST endpoints with PUT /v1/documents/:id rely on Last-Write-Wins (LWW) using server-generated timestamps. For high-performance mobile applications, this approach introduces severe architectural flaws:

Standard REST APIs (Mobile Failures)
  • Silent Data Loss: When a user goes through a subway tunnel or airplane mode, late-arriving REST calls overwrite newer edits made on other devices.
  • UI Blocking & Spinners: Awaiting an HTTP response before updating views causes lag, frame drops, and failed action banners.
  • Painful Conflict Modals: Forces intrusive "Version A vs Version B" diff popups upon the user.
elnitodev Local-First CRDT Engine
  • Instant Local Commit: Commits to encrypted SQLite on-device in under 4ms. Never blocked by network status.
  • Mathematical Convergence: Edits generate immutable Lamport operations that merge deterministically without human conflict resolution.
  • Zero-Loss Offline Handoff: When reconnecting, background workers flush queued deltas seamlessly without touching visible screen state.

Did you find this technical breakdown valuable?

React with emojis or follow this technical series for upcoming deep dives.

E
elnitodev Mobile Lab
Core Systems & Low-Latency Architecture
elnitodev Dispatches via Brevo

Follow our mobile architecture series

Subscribe to receive our technical teardowns and open-source benchmarks straight to your inbox.

Zero spam. Unsubscribe at any time with one click. Read our Privacy Policy.