Mobile App Offline Feature Data Exchange With Server

Hi,

I have a question regarding mobile application that support offline features. I know to support offline feature we have local storage and data is synchronized based on the defined synchronization patterns. My question is - When user fetches or adds/updates any data, it must all be done only on local entities, and there should not be any interaction with server entities except when synchronization happens, is this the right assumption?

Thanks,

Junaid

Hi Junaid,

Your assumption is correct if your requirement is that the application should function without an internet connection.

Regards,

Daniel

Well I forgot to mention, would the assumption be valid even when application is online i.e. network is available? 

Hi,

there is a good online course on mobile development, with a whole section about Local Storage and Data Synchronisation.  This is first lesson.

The proposed approach is to do all fetching from local storage.  For updating the data: when online both local storage and database are updated, when offline only local storage is update.

And synchronisation is executed (amongst others) on going back online, so at that time any updates to the local storage are updated in the database, and from that point on they're back in synch.

example from one of the update actions in this course, you see local storage is always updated, and database only when not offline :



Happy coding,

Dorine



Thanks Dorine, I have gone through these tutorials already, however not clear about below scenario. 

Suppose in my application the local entities are synchronized with sever data  when the device is online or on login or application resume, and from this point on for user User-A the device is online. Now the user User-A navigates to a screen where some records are to be displayed and they are being pulled from local entity, when synchronization took place only 10 records were there, and after last synchronization on user's device two more records have been added by a different user User-B on server database. In this case the user User-A is seeing only 10 whereas he should see 12 records.

To handle this scenario if I decide to synchronize local entities with server data every time user navigates to screen, then I end up hitting the performance which I was trying to improve using local entities.

What do you suggest to handle this?


Hi Junaid,


i'm also still a student on OS and on mobile development, but agreed, scenario from tutorial is only usefull for data that is not shared between different users.  

So probably better for one of the more experienced OS developers to tackle this, but I would expect it would involve 

  • on server database to keep track at a rowlevel of timestamp of change
  • keeping track on local database of time (on the server's clock) it was last synchronised
  • pull down from server only those records that were changed after that timestamp
  • have complex logic on local database to incorporate changes instead of just delete all / add all


There is documentation here about more complex sync patters, I think what you need is maybe Read/Write Data With Conflict Detection.

Dorine Boudry wrote:

Hi Junaid,


i'm also still a student on OS and on mobile development, but agreed, scenario from tutorial is only usefull for data that is not shared between different users.  

So probably better for one of the more experienced OS developers to tackle this, but I would expect it would involve 

  • on server database to keep track at a rowlevel of timestamp of change
  • keeping track on local database of time (on the server's clock) it was last synchronised
  • pull down from server only those records that were changed after that timestamp
  • have complex logic on local database to incorporate changes instead of just delete all / add all


There is documentation here about more complex sync patters, I think what you need is maybe Read/Write Data With Conflict Detection.

Doesn't answer my question. 

Hi,

If u are working real time data rendering on user's screen like when user-A change some data and User-B should get update then we can call server action to check whether some data has changed or not on server when device is online then fetch updated data from server and insert into corresponding local table when screen is load.


Hope this help.

Regards,

Shoeb

Shoeb Khan wrote:

Hi,

If u are working real time data rendering on user's screen like when user-A change some data and User-B should get update then we can call server action to check whether some data has changed or not on server when device is online then fetch updated data from server and insert into corresponding local table when screen is load.


Hope this help.

Regards,

Shoeb

If I have to go to server every time to check for the updates from any other user, then this defeats the purpose of fetching data from local entities.


Junaid Ahmed Syed wrote:

If I have to go to server every time to check for the updates from any other user, then this defeats the purpose of fetching data from local entities.


Hi Junaid,


The only place that knows about these changes is the server, so you will have to have some sort of mechanism to keep your local storage of each user in sync, by going to that server.

So as said earlier, part of the answer (and performance gain) will be to only update changes that happened since last sync.

If that is still taking too much time, you might think about holding some sort of high level timestamp (for example one per entity indicating the last time changes happend in the server on that entity.)  As long as this is not later that a mobiles last sync timestamp, no further syncing on that table is needed.

Even if you sync very often, there is still advantage in having local storage

1) performance gain of only syncing records that changed, instead of all

2) better ux : can already see data of situation before sync, and then be updated once sync is complete 

3) offline use of the app is possible 

Junaid Ahmed Syed wrote:

Shoeb Khan wrote:

Hi,

If u are working real time data rendering on user's screen like when user-A change some data and User-B should get update then we can call server action to check whether some data has changed or not on server when device is online then fetch updated data from server and insert into corresponding local table when screen is load.


Hope this help.

Regards,

Shoeb

If I have to go to server every time to check for the updates from any other user, then this defeats the purpose of fetching data from local entities.


Hi,

Local entities are useful when ur application is offline.but if u need to get update data concurrently when multiple user on the same screen then u need to query data from server. or if u don't want to call each time when screen load to eliminate overload then u can put button to sync updated data and insert into local entities on demand.

Shoeb Khan wrote:

Junaid Ahmed Syed wrote:

Shoeb Khan wrote:

Hi,

If u are working real time data rendering on user's screen like when user-A change some data and User-B should get update then we can call server action to check whether some data has changed or not on server when device is online then fetch updated data from server and insert into corresponding local table when screen is load.


Hope this help.

Regards,

Shoeb

If I have to go to server every time to check for the updates from any other user, then this defeats the purpose of fetching data from local entities.


Hi,

Local entities are useful when ur application is offline.but if u need to get update data concurrently when multiple user on the same screen then u need to query data from server. or if u don't want to call each time when screen load to eliminate overload then u can put button to sync updated data and insert into local entities on demand.

Hey Shoeb, nice to hear from you after so long :-)

Yeah, that is what I had on my mind, was just wondering if there is a better way to do it.