Most enterprise mobile app architectures assume reliable internet connectivity. In East African field environments — farms, health clinics, rural cooperatives — that assumption fails regularly. Our Android apps for Vetra Model Farm needed to work in fields with no signal and sync reliably when connectivity returned.
The Core Pattern: Local-First with Conflict Resolution
We use a local SQLite database (via Room) as the primary data store. Every write goes to local storage first. A background sync service — using WorkManager with network connectivity constraints — pushes pending changes to the Django backend when a connection is available.
Conflict Resolution Strategy
When the same record is modified offline on two devices (e.g. two field supervisors updating the same animal's weight at different times), we use a last-write-wins strategy with server-side timestamps as the authority. For critical fields (like health observations), we preserve both writes as a timeline entry rather than overwriting.
User Experience Considerations
Users are shown a sync status indicator — a small icon in the toolbar showing pending changes. When sync fails repeatedly (e.g. no connectivity for more than 24 hours), a persistent notification tells the user to connect before end of day. This is a better experience than silently failing or blocking the user from recording observations.