Offline & Sync
The mobile application makes full use of the locally available SQLite database to keep track of local events and synchronizes any changes with the server.
Offline support vs offline native
In conditions where connectivity is the exception and not the rule, offline support is not enough. It is important to change the framing to “online support” but offline native. This requires building highly performant applications in highly constrained environments where memory management is critical.
Local storage with SQLite
SQLite is a relational database management system contained in a C programming library. Unlike traditional client-server database engines, SQLite is embedded directly in the application.
Hikma Health uses WatermelonDB, a performant, scalable, and extensible database for React and React Native applications. WatermelonDB supports JSI for extremely fast queries written in C++ that can easily scale to tens of thousands of records with minimal impact to performance.
Data synchronization
Three change types are tracked during synchronization:
- Created: New data on user devices since the last sync.
- Changed/Updated: Previously existing data that has been modified locally.
- Deleted: Records removed since the last sync.
Changes are organized by table and sent with a synchronization timestamp.
Sync targets
The mobile app does not sync to a single fixed destination. It syncs to whichever peer is active, and supports three operational arrangements:
- Offline with cloud sync — the device collects data offline and syncs directly to the cloud master server when it has internet.
- Offline with hub sync — the device syncs to a Local Sync Hub: a desktop app on the clinic’s local network that buffers sync between devices when there is no internet, then relays to the cloud later. This is the arrangement for clinics where connectivity is intermittent or absent.
- Fully online — reads and writes bypass the local database entirely and go straight to the server. This requires a constant connection.
The transport differs by target: cloud sync uses the platform’s REST sync API over HTTPS, while hub sync uses an encrypted RPC transport (ECDH-derived AES-256-GCM) over the local network. See Data Synchronization for the full mechanics, including how the app resolves which peer to use.
Cloud server sync
When syncing to the cloud, the server sync API accepts a GET request first to check for any changes since the last sync, followed by a POST request where the device pushes any data it has locally.
Note: Initial synchronization requires downloading the entire database, which may take time depending on network availability.