How would you build an offline app which occasionally synced with the server


I’m in the quest of building a small application in React Native. Imagine it’s a book in the form of an application, and I’ve been questioning myself if the chosen solution is the right way to build it.

The app must work offline, meaning when you first install the app, you already have all the content of the book. Then when you come online, it should check for updates and new content from API server

My questions are:

  • Local storage : I’m leaning more into using Realm. Would it be the best/easiest solution? Is handling data sync with Realm in React Native straight forward?

  • Prepopulate data : my initial idea is to prepopulate data is to ship the app with a bunch of JSON files (~100 files in my case), then read and insert all data from JSON files to Realm after installing the app. And content will be read from Realm afterward.

  • Cache images from server for offline used:
    seems to be the one? Does anyone have experience with using it?

I keep wondering if my solution is right? or there is a better way to handle prepopulating data?

Hope you can help to point me out the direction with some pieces of advice

Many thanks in advance,

@Winfield_Kohler Welcome! Realm Sync seems to be what you are looking for, once the data is downloaded the user can go offline, modify it if they have permission to, come back online and push their changes up and get any queued changes from the server-side.

I’d encourage you to take a look at our tutorial here -

If you want to use sync though, I would not bundle a realm with the app installation, instead I would download the data on first app launch. Presumably, when people first install the app they then open it, in which case they would have a connection and be able to download the data.

You cannot bundle a synced realm with app installed from the App Store. This is because the Server and Client need to exchange a variety of metadata in order to keep their histories straight and for sync to work.

We typically do not recommend caching images using Realm Sync as the operation log which Realm Sync depends on will start to really slow down when binary data is transferred. Instead, store them on disk and just store the reference to the path in Realm.

Hope this helps

1 Like