Mobile Offline Sync – Architecture

Many mobile apps are data-centric, and are designed to replace pocket atlases, and dictionaries, as well as create new smart digital pocket references for data that changes seamlessly by leveraging different synchronization technologies.
In today’s world, the major challenge in mobile computing is to provide same user experience to customers during poor or no network connectivity as with LTE or Wi-Fi network. Mobile users keep on roaming to different places and often times, they receive poor cell coverage and bad network connectivity. Most of the smart phone apps fail to work in such conditions since they are engineered to rely heavily on strong data connectivity.
The contexts causing the use of data synchronization mechanism can be considered from two viewpoints: uploading and downloading. Uploading is the transfer of data from the mobile device to a remote backend server, whereas downloading is the transfer of data from the remote backend server to mobile device. In both cases, the success or failure of the data sync should be conveyed to the user either directly (with a notification or dialog), or indirectly (in a log), with appropriate error information if a failure occurs.
Data synchronization mechanisms in mobile apps should address key questions such as-
1. When should an application synchronize data between a device and a remote server?
2. What should be the sync frequency so that it doesn’t drain out user’s battery & network bandwidth?
3. Should data sync be performed in synchronous or asynchronous mechanism?
Data Synchronization on the mobile device can be performed in 2 ways – 
1. Asynchronous Data Sync – 
The intent is to manage a data synchronization event asynchronously and without blocking the user interface.
2. Synchronous Data Sync – 
The intent is to block the user interface while data sync is happening in background.
The architecture of mobile data synchronization can be described in the following figure. Sync Service is responsible for syncing data from remote server to mobile device and stores the data locally in SQLite database. All UI components are rendered via local database. Now even in case of subsequent sync failures, it will provide same user experience to customers.
Figure 1 – Mobile Offline Sync Architecture
The data synchronization in Android apps can be achieved using Sync Service and Sync Adapter. A Sync Adapter is a plug-in that handles background syncs on Android platform to sync data from your app to a server. This plug-in is registered on the platform’s Sync Manager, which is in charge of running it and can be triggered when needed, requested or scheduled.
In Android, Sync Adapter has many advantages over other approaches:
1.Battery Efficiency
The system schedules the sync to run when other syncs run, or when some other network request was already made on the device. This prevents awaking the device from its sleep for performing a single sync.
2. User Settings
All sync adapters on the device can be accessed from the Settings screen, under the account they are tied to. This gives the end user the option to change sync preferences, see if there are any sync problem or even disable the sync.
3. Data Responsiveness
If we use Content Provider for accessing/manipulating our data, the sync adapter can observe any changes done to it. That way it can run only when the data actually changes.
3. Retry Mechanism
The sync manager has its implementation to retry failed syncs, using timeouts and exponential backoffs.

Leave a Comment