Design every step so it is safe to kill and resume.
if retries < 5 { backoff(attempt) }
Persistence and the UI reels
Persistence and the UI1 / 3
1 / 5
Why SQLite everywhere
SQLite is transactional, fast with millions of rows and available on every platform. Room on Android, GRDB or SwiftData on iOS, and WatermelonDB or op-sqlite in React Native all sit on top of it. Pick the wrapper by platform and by how much control you need.
2 / 5
IDs made on the device
Generate primary keys on the device, ideally UUIDv7. A record can then be created, linked and edited offline without waiting for the server to hand out an ID, and its time ordering keeps indexes efficient.
3 / 5
WAL and one writer
Turn on write-ahead logging so the UI can read while sync writes. Use one writer connection and a pool of readers. Apply pulled changes in batches of a few hundred rows per transaction, so observers fire once rather than a thousand times.
4 / 5
Keep it lean
Index every column you filter or sort on. Use FTS5 for search instead of LIKE. Never keep large blobs in the database; store a path and a hash. Purge synced outbox rows and old tombstones on a schedule.
In practiceRegulated data: SQLCipher, with the key held in Keystore or Keychain.
Interview answer
Say it in the interview
SQLite sits underneath on every platform, with client-generated UUIDv7 keys, WAL mode, one writer and many readers, and batched transactions for sync. Blobs live on disk with a hash in the row, and search uses FTS5. That stays fast with millions of rows on mid-range phones.
1 / 5
Why SQLite everywhere
SQLite is transactional, fast with millions of rows and available on every platform. Room on Android, GRDB or SwiftData on iOS, and WatermelonDB or op-sqlite in React Native all sit on top of it. Pick the wrapper by platform and by how much control you need.
2 / 5
IDs made on the device
Generate primary keys on the device, ideally UUIDv7. A record can then be created, linked and edited offline without waiting for the server to hand out an ID, and its time ordering keeps indexes efficient.
3 / 5
WAL and one writer
Turn on write-ahead logging so the UI can read while sync writes. Use one writer connection and a pool of readers. Apply pulled changes in batches of a few hundred rows per transaction, so observers fire once rather than a thousand times.
4 / 5
Keep it lean
Index every column you filter or sort on. Use FTS5 for search instead of LIKE. Never keep large blobs in the database; store a path and a hash. Purge synced outbox rows and old tombstones on a schedule.
In practiceRegulated data: SQLCipher, with the key held in Keystore or Keychain.
Interview answer
Say it in the interview
SQLite sits underneath on every platform, with client-generated UUIDv7 keys, WAL mode, one writer and many readers, and batched transactions for sync. Blobs live on disk with a hash in the row, and search uses FTS5. That stays fast with millions of rows on mid-range phones.
SQLite at scale on a phone
#sqlite
❚❚
Persistence and the UI2 / 3
1 / 5
Long tail
Some users update months late. Some phones sit in a drawer holding unsynced changes. Your database and your protocol will both change while those devices are still out there.
2 / 5
On the device
Keep migrations versioned and forward-only, and test them in CI against real snapshots of old databases, not just a fresh install. A migration that fails at launch is among the worst bugs a sync app can ship, because it can strand unsynced data.
3 / 5
On the wire
Protocol changes are additive. New fields are optional, and the server keeps accepting old payload shapes and filling in defaults. A breaking change gets a new versioned endpoint, and the old one stays until telemetry shows almost nobody uses it.
4 / 5
Rule
Never assume clients upgrade together. Design every change so an app from six months ago can still push its outbox safely.
Interview answer
Say it in the interview
Database migrations are forward-only and tested in CI against real old snapshots. Protocol changes are additive, anything breaking gets a versioned endpoint, and old versions retire only when telemetry shows almost no devices use them. I assume clients never upgrade together.
1 / 5
Long tail
Some users update months late. Some phones sit in a drawer holding unsynced changes. Your database and your protocol will both change while those devices are still out there.
2 / 5
On the device
Keep migrations versioned and forward-only, and test them in CI against real snapshots of old databases, not just a fresh install. A migration that fails at launch is among the worst bugs a sync app can ship, because it can strand unsynced data.
3 / 5
On the wire
Protocol changes are additive. New fields are optional, and the server keeps accepting old payload shapes and filling in defaults. A breaking change gets a new versioned endpoint, and the old one stays until telemetry shows almost nobody uses it.
4 / 5
Rule
Never assume clients upgrade together. Design every change so an app from six months ago can still push its outbox safely.
Interview answer
Say it in the interview
Database migrations are forward-only and tested in CI against real old snapshots. Protocol changes are additive, anything breaking gets a versioned endpoint, and old versions retire only when telemetry shows almost no devices use them. I assume clients never upgrade together.
Schema changes while users stay offline
#migrations
❚❚
Persistence and the UI3 / 3
1 / 5
Read, never fetch
In this architecture the screen does not call the network. A ViewModel or store observes a database query and turns its results into immutable UI state, which Jetpack Compose, SwiftUI or React renders.
2 / 5
Loop
The user acts. The ViewModel writes the row and the outbox entry in one transaction. The observed query emits again and the screen re-renders. Later, when sync updates those rows, the screen re-renders again without any special code.
3 / 5
Optimistic UI
Each synced row carries a sync_state: pending, syncing, synced, failed or conflict. The UI shows a change instantly with a small badge. If the server rejects it, the row moves to failed or conflict with a clear action, never a silent rollback.
4 / 5
Status users trust
Show one honest global status: all changes saved, syncing twelve items, or offline with changes waiting. Show progress for big uploads, let users retry failures and offer Wi-Fi only for media. Trust in an offline app is built on this one line of UI.
In practiceLarge lists: keyset pagination from the database, with Paging 3, LazyVStack or FlashList recycling cells.
Interview answer
Say it in the interview
The UI follows one-way data flow: it observes database queries and renders immutable state. Writes are optimistic with a sync_state per row, and failures surface as clear actions rather than silent rollbacks. One honest sync status line is what makes users trust an offline app.
1 / 5
Read, never fetch
In this architecture the screen does not call the network. A ViewModel or store observes a database query and turns its results into immutable UI state, which Jetpack Compose, SwiftUI or React renders.
2 / 5
Loop
The user acts. The ViewModel writes the row and the outbox entry in one transaction. The observed query emits again and the screen re-renders. Later, when sync updates those rows, the screen re-renders again without any special code.
3 / 5
Optimistic UI
Each synced row carries a sync_state: pending, syncing, synced, failed or conflict. The UI shows a change instantly with a small badge. If the server rejects it, the row moves to failed or conflict with a clear action, never a silent rollback.
4 / 5
Status users trust
Show one honest global status: all changes saved, syncing twelve items, or offline with changes waiting. Show progress for big uploads, let users retry failures and offer Wi-Fi only for media. Trust in an offline app is built on this one line of UI.
In practiceLarge lists: keyset pagination from the database, with Paging 3, LazyVStack or FlashList recycling cells.
Interview answer
Say it in the interview
The UI follows one-way data flow: it observes database queries and renders immutable state. Writes are optimistic with a sync_state per row, and failures surface as clear actions rather than silent rollbacks. One honest sync status line is what makes users trust an offline app.