Realm Blog

Realm and IBM Cloud Functions

Today we are pleased to announce a collaboration between Realm and IBM to bring the power of Realm to the flexibility and extensibility of IBM Cloud. This collaboration combines Realm’s capabilities for offline-first and zero-latency mobile applications with IBM’s Cloud and IBM Cloud Functions, enabling server-side triggers written in any language (including Swift!), for the real-time facilitation of arbitrary functions and application extensions. We have open-sourced a demo application and recorded a video of it, but this is just the beginning – this is purely an example demo, and the possibilities are endless.

The combined solution pairs a Realm-enabled mobile app with its native Realm sync technology to seamlessly synchronize state changes to and from a IBM Cloud deployed Realm Object Server in a bidirectional manner. The Realm Listener and Realm Event Handler, as part of the Realm Object Server solution, send updates and changed data in real time to the IBM Cloud Function, which is IBM’s implementation of serverless or Functions-as-a-Server. One aspect of this collaboration that should be particularly compelling to mobile developers is that IBM’s Cloud Functions can be completely written in Swift, enabling a mobile app developer to build a full stack application where both the frontend and backend share the same codebase.

In our demo app, we demonstrate how a Realm-enabled application fetches restaurant data from Foursquare’s API, triggered by a location object being synced from the mobile’s GPS. This is saved to Realm on the device, which then persists to Realm Object Server and notifies Realm’s server-side event handler which subsequently calls the IBM Cloud Function and then sends the result back down the mobile app. The beauty of this is that the restaurant data is saved locally in Realm on the mobile device, delivering a truly offline experience when WiFi or cellular coverage is not accessible or being agreeable.

We deployed the prepackaged Realm Object Server Helm chart to IBM Cloud’s Kubernetes as a Service offering; however, the Realm Object Server can be deployed anywhere, even locally, because the event handler and IBM Cloud Functions, built on Apache Openwhisk, can all be called remotely with built-in APIs. The Realm Event Handler is also deployed as a container on IBM’s Kubernetes Service and is configured with API tokens to talk to the IBM Cloud Functions. This serverless function is then configured with an API token from Foursquare enabling you to fetch data based on a given latitude and longitude. This JSON of restaurants is simply mapped to the Restaurant objects stored in a Realm on the Realm Object Server which automatically syncs the result down to the mobile app.

https://github.com/realm/realm-cloud-functions-demo

Please give the repo a spin and let us know what you think! All the instructions you need to get this up and running are in the README.md document in the repository on GitHub, and you can watch an annotated video that describes the application here.

Do you have a mobile app that could use an integration into serverless functions to deliver more value to your users? We would love to hear about it! We are interested in cloud users that have deployed an app to production who would be intrigued in adding server-side event processing capabilities to their app similar to those described in this demo app.

We are happy to help build the code and run the handler for you on the IBM Cloud. With this opportunity comes co-blogging events and the potential for free credits for running the service as well as expert support from our developers to ensure that the written code is as performant as possible.

Contact us at [email protected]


Ian Ward

Ian is a Solutions Engineer at Realm, where he helps clients integrate the Realm Platform into their mobile app architectures. He has a strong background in solution design and entrepreneurship, having previously been one of the first field engineers at start-ups Meraki and Mesosphere.

Get more development news like this