As you may know, in my MoneyBack Xamarin.Android application I’ve used SQLite as the local db management system. Recently I’ve added an ASP.NET Core web solution to my GitHub repository in order to create back-end API for my mobile app. I wanted to have database hosted on a remote server and Android application to synchronize its data with it.
Then I started wondering… and decided to make a deeper research first. As I wrote in my post summing up DajSiePoznac2017 competition, “before using a particular solution for an issue” we should “better examine the other possibilities” first. So I do 🙂

Why to synchronize with remote database?

First question to ask is why to synchronize with a remote database at all?

There are a few obvious advantages:

(+) users’ data is stored “in a cloud” and can be accessed from any device

(+) users don’t need to worry about backing-up their data

(+) data storage logic is moved to the web part of the system and with API exposed it can be easier to port it to other platforms

(+) having web API, a web client can be easily added to the system.

However, there are also some harms:

(-) synchronization of local and remote data (online and offline) must be handled

(-) synchronization uses some network data and battery of a mobile device

(-) web API must be maintained and after each change in it mobile app must be adjusted.

Despite all these aspects I’ve been wondering to implement a web API for few different reasons. First of all this could be a great programming experience, very interesting from architectural point of view. Secondly, I think this is a bit old-fashioned and messy that a user needs to export some database/app files backup to his GDrive in order to not lose his data.

Frankly, I just want to have some fun with ASP.NET Core, implement a web API and make MoneyBack working with it 🙂 Maybe some Linux deployment after all? Let’s create some nice programming playground here 😉

How to synchronize with web API?

That’s the question I’ve been searching an answer for recently. Long story short, the idea is to have a back-end database management system hosted on a web server and mobile app having its own local “mirror” of the database, bidirectionally synchronizing local data with remote database through web API. Mobile app should work in offline-first mode, which means that all operations must be possible to be done locally and potential (not mandatory) synchronization to happen as soon as it’s possible (user is connected to WiFi, has mobile network access etc.)

There are various possibilities and solutions to handle synchronization of mobile app’s data and remote database storage, from synchronization system built from scratch to Azure cloud hosting.

Custom synchronization mechanism

We could of course implement our own data synchronization mechanism. There are many tutorials available, including for instance this one, which describes all the contents quite nicely and I recommend reading it even if you don’t want to implement sync on your own – it helps understanding all the concepts.

Custom synchronization can be a lot of fun, but… why to reinvent the wheel?

Azure Mobile App Service

Microsoft’s Azure Mobile App Service is recommended almost everywhere – on StackOverflow, in the official Xamarin documentation and on a lot of blogs, but its free plan seems to not be worth using (except of performing some simple tests) while paid plans are more enterprisy. It seems great, but for my playground I neither want to pay nor use free plan which may become unusable after re-implementing the whole back-end.

Realm.io

Finally, out of a sudden, I found it. Realm.io is a totally separate database system built especially for mobile solutions. Its Mobile Database may be used as the db framework for a mobile app (Xamarin is also supported), replacing for instance SQLite. After all, Realm Mobile Platform can be used on a server-side handling mobile/web APIs and data synchronization – documentation says it supports .NET Core 1.1. Let’s hope they add support for 2.0 soon.

Realm.io looks very promising. I’m just a bit worried it’s almost never recommended on the web – is there something wrong with it? Maybe it’s a new stuff? Where’s a catch? Let me know if you’ve had any experience with it.

SQLite-sync.com

Last but maybe not least, I found SQLite-sync.com. The idea seems to be similar to Realm.io, however this product looks less mature. Not even 100 commits on their GitHub with just few contributors. Looking poor compared to Realm.io’s GitHub with more than 2.5k commits only for its .NET component.

The main (and the only?) benefit of using it would be the possibility to keep SQLite database in Xamarin.Android app. Apart from that, I don’t see any dominance over Realm.io.

Summary

As my research shows there are a lot of existing frameworks that help keeping data synchronized between mobile app and a remote back-end, allowing Xamarin app to work in offline-first approach. Microsoft offers great stuff in Azure, but in my opinion it’s not worth investing money for small playground apps.

For the moment I’m for Realm.io. It seems to provide very extended free plan, there’s a lot of resources on the web, folks talk about it on SO…

So now I’m asking you – do you have any experience with data sync in Xamarin apps? If yes, please share your insights and help me to choose the best approach 🙂

I’d be grateful for any suggestions!

After the framework is chosen, I will try to design the whole synchronization system and share it with you here.