Building Mobile Apps: Offline First, and Last!

Michael Epstein
2 min readDec 29, 2016

--

“Because internet connections can be flakey or non-existent, you need to consider offline first: write your app as if it has no internet connection. Once your app works offline, add whatever network functionality you need for your app to do more when it’s online.” [Source: Offline First]

But that’s a pain, right? Code for offline, code for online, react to changes in network connectivity, resolve data conflicts, yadda, yadda. So much time and low-level code invested in the drudgery of moving data around.

Nevertheless, we have to do it right. A well-designed mobile app lets the user get work done, and doesn’t whine about the lack or quality of Internet connectivity.

In my work, I see a lot of interesting use cases for custom mobile apps that integrate with the Salesforce Platform, and offline requirements are often the hardest to meet. So I was very interested to try out Realm’s new Object Server, the back end of their Mobile Platform:

“Realm Mobile Platform delivers automatic and seamless realtime data sync and powerful event handling between server and devices. You never need to think about networking code again. The Realm Mobile Database is cross-platform, supporting both iOS and Android, and the Realm Object Server is ready to run on your servers or on your favorite cloud.” [Source: Realm Mobile Platform]

Sounds promising, so I set out to see what it takes to integrate the Realm Object Server with Salesforce. More specifically, I wanted to see if I could monitor data changes made via Realm’s sample mobile app, “Realm Tasks,” and then create and update Salesforce task records accordingly.

And I did it in just a few minutes (ok, not counting the time required to read Realm’s docs and understand how to set up custom event monitoring).

Architecture overview. Adapted from https://realm.io/news/introducing-realm-mobile-platform/

Realm Object Server is amazing! I modified the data on a mobile device, and it showed up almost instantly in the Realm Object Server. I took the device offline, updated data on the device and on the server, then watched as the local databases effortlessly synched up after I turned the WiFi back on. The Realm Object Server dutifully notified my event monitor, which fired off the API calls to Salesforce. No code at all to handle data synchronization, just a relatively-simple Javascript file to monitor events and update Salesforce; see the source code on GitHub.

--

--