In mobile applications, data is a critical matter: It always has to be available and ready to your users. This is even more true for enterprise applications, if data takes a long time to load, sync or is only partially downloaded from the server, it will reflect very poorly on your product quality.
Internet instability can have concerning effects. One such example is if the app stops downloading a payload, you can retry until it is completed. However, that might take a long time, and you might have to start the communication from scratch.
Furthermore, in applications with highly structured data, partial information is useless. For instance, If you download order details which rely on product data, but products have not been downloaded, can we display order details?
With the previous discussion in mind, we can extract three major goals for our process flow:
- If internet drops, resume download.
- Have all your user’s data ready.
- Fast and reliable.
The solution I’m proposing has a simple flow. Once the user is logged in to the app, it will send a request to a Backend API, then it will will check in a file storage if the SQLite database file has been generated recently. If not, the API will create the SQLite file and make it available for the mobile app to download it, simple eh?
- The mobile app requests the database from the API and blocks the UI
- The API checks if the database exists
- If the database does not exist, generate and save it
- Return the database to the client
- The mobile app receives the database and allows the user to begin interacting with the app.
If you want to take a peek at the POC code, that covers this workflow end to end, check it out in my Github repo. The demo project was built using:
- Xamarin.Forms – 3.5
- AspNet Core API – 2.1
- Sqlite-net – 1.5.231
- HttpTransferTasks – 2.0.1
- WindowsAzure.Storage – 7.2.1
- HttpTracer – 1.0.2
- ReactiveUI – 9.10.7
- UserDialogs – 7.0.1
Treating SQLite db as any other type of download task, gives us management power, and if connection drops we can resume downloading. Moreover, we can be sure that all data we need will be available to our user, once the file is downloaded.
Delegate the heavy work to the backend. Even though our phones are powerful computers, they do not have the processing power and scalability of cloud providers, such as Azure or AWS.
What is next?
I will cover each and every step of the solution that was laid out in this post in a part II and possible part III. I would also like to thank Mr Dylan Berry and Allan Ritchie for all the meetings, code pairing and guidance.
throw new CauserException();