Tuesday, October 20, 2009

Sync data while you are "Mobile"

You (your mobile device) can browse and perform some action on most of the websites provided you are connected to the internet. How about performing few actions even when you are not connected to the internet due to no-network coverage. It’s good to have an offline capability of your web application in these scenarios. One common way of implementing this is having our local database such as “SQL Server Compact Edition” or “Oracle database Lite”.

The challenge with having a local database is data-sync problem. I don’t have much exposure to Oracle Lite. The previous versions of SQL CE (short form for SQL Server Compact Edition) have some limitations on synchronizing the data from mobile to a central SQL server. This is due to the following database limitation.

1) SQL CE is a single user database
2) SQL CE multi-threads are not really thread safe.

Microsoft SQL Compact Edition 2005 version overcame these issues. It’s now a multi-user database and thread safe. What it really means is while data synchronizing, user need not come out of the application which is accessing this database. The user can perform his / her regular operations while the data-sync operation continues in the background. This background data-sync works even when a mobile goes out of network coverage (due to being in an elevator etc) for a brief stint.

As always, any application working with multiple database instances carriers its own challenges such as “Conflicting changes” or “Concurrency” etc. Even SQL CE provides an option to “Merge” the data changes, it is still your responsibility to manage them through some good practices such as proper lock / unlock, multi-step data-sync operation and frequency / timing of data-sync operation.

0 comments: