
React Native offline-first: conflict rules in SQLite
I stopped “last write wins” from nuking offline edits. I model conflicts with base_rev + rev in SQLite. I sync with 1 endpoint: pull then push . I ship deterministic merges for workout sets. Context My fitness app has one job. Log a set in ~5 seconds. No spinner. No “retry later”. Offline-first forced me into SQLite. AsyncStorage died fast. I need queries like “last 12 sets for this exercise” in under 100ms. And I need sync. I shipped a naive sync first. It was brutal. Two devices editing the same workout would randomly overwrite each other. Sometimes it looked fine. Then you’d refresh. Poof. Half the sets gone. So I rebuilt it around conflict rules. Not “hope”. Rules I can test. Rules SQLite can enforce. 1) I store revisions per row. Not timestamps. Timestamps lied to me. Device clocks drift. Also, two updates can share the same millisecond. And I don’t want “latest” anyway. I want “what was this row based on?” So every row gets: rev (server-assigned integer) base_rev (what the client
Continue reading on Dev.to Tutorial
Opens in a new tab




