Back to Journal
MobileSQLiteFlutterOfflineFirst· 6 min read

Offline-First Mobile Architecture with Drift SQLite and Background Sync

H
Hridoy Khandakar•

A truly native-feeling mobile experience does not wait for an HTTP request before updating the screen. If a user taps ‘favorite’ or writes a note while offline in the subway, the UI must reflect the change instantly.

The Local Database as Single Source of Truth

The UI subscribes directly to reactive streams emitted by the local database (such as Drift/SQLite or ObjectBox):

// Stream reactive query to UI
Stream<List<TaskEntity>> watchActiveTasks() {
  return (select(tasks)..where((tbl) => tbl.isArchived.equals(false)))
      .watch();
}

Network requests never directly modify the UI state. Instead:

  1. User interacts with the screen.
  2. An optimistic record is written to local SQLite with a syncStatus = pending flag.
  3. The UI updates instantly via the local table stream.
  4. A background sync worker picks up pending rows and delivers them to the API server.
  5. On 200 OK, the sync worker marks the row syncStatus = synced.

Conflict Resolution Strategies

For collaborative multi-user apps, simple last-write-wins can erase colleague contributions. We utilize either:

  • CRDTs (Conflict-free Replicated Data Types) for rich document editing.
  • Append-only event sourcing with server sequence numbers.

Building offline-first requires upfront planning, but pays massive dividends in perceived speed and user retention.

H

Written by Hridoy Khandakar

Senior Mobile App Developer with deep experience in Flutter & Dart. Building production cross-platform apps that don't compromise on speed or feel.

More about my work →