Realm Blog

Realm ObjC & Swift 2.9: Set Permissions Based On Usernames, User Info Lookup & Bug Fixes!

by /

We’re releasing version 2.9 of Realm Objective‑C and Realm Swift today. In this release, we’re introducing a way to set permissions based on usernames, a way for administrators to retrieve user information from a Realm Object Server, various improvements, and applying a few bug fixes to keep your apps running strong.

Set Permissions Via Username

It’s now possible to set user permissions based on a user’s username, if they were registered using the Realm Object Server’s built-in username authentication system.

let permission = SyncPermissionValue(realmPath: realmPath,
                                     username: "[email protected]",
                                     accessLevel: .write)
user.applyPermission(permission) { error in
  // ...

Retrieving User Info

Administrator users can now look up the information of users on the Realm Object Server. If an administrator knows a user’s username, they can look up their Realm Object Server identity, which can be used to perform further administrative tasks.

let targetUserIdentity = "[email protected]"
adminUser.retrieveInfo(forUser: targetUserIdentity, identityProvider: .usernamePassword) { (userInfo, error) in
  guard let userInfo = userInfo else {
  print("The user's ROS identity is \(userInfo.identity)")

Sync User Improvements

It is now possible to create and log in multiple Realm Object Server users with the same identity if they originate from different servers. Note that if the URLs are different aliases for the same server each user will still be treated as separate (for example, they will each have their own copy of any synchronized Realm).

If you are creating users using the administrator token, we strongly recommend you specify an authentication server URL when calling the logIn() method. This server URL will become mandatory in a future release for all user types.

Other Enhancements

  • Performance for instantiating Swift objects containing at least one List property has been improved.

Bug Fixes

  • List.description now reports the correct types for nested lists.
  • Unmanaged object initialization when a nested property type returns false from Object.shouldIncludeInDefaultSchema() now works properly.
  • RLMArrays are no longer cleared on self-assignment.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on the Realm Forums, Stack Overflow, GitHub, or Twitter.

Read more

RealmContent: Add Real-time Updates to your iOS App in 5 Min

by /



RealmContent coupled with the Realm Mobile Platform quickly gives the developers the ability to add new content into an iOS App by adding data directly into the Realm Browser app.

RealmContent automatically adds the Realm objects it needs into the app’s own schema and allows the developer to use a number of pre-configured View Controllers to list the available content and to render each of the content “pages”.

The component works mostly automatically while it allows for a lot of customization. It saves developers time and drudgery of implementing the underlying plumbing themselves or even having to roll out a completely new version of the app to change in-app content.

The library is the easiest and fastest way to push content in real-time to your complete user base.

How does it work? The technical crash-course

There are five easy steps to add a dynamic content management system to an iOS app.

1) Import RealmContent

Add RealmContent via CocoaPods or include the source files directly into your project. Then import both RealmSwift and RealmContent in a view controller:

import RealmSwift
import RealmContent

Your app would normally have a list of objects it syncs from the Realm Object Server. Once you import RealmContent it will expose two new models which Realm will add to your default schema: ContentPage and ContentElement.

If you’re using multiple Realm files, add ContentPage and ContentElement to the desired object schema.

2) Create a content list data source

To display a list of the available content in your app you can use the ContentListDataSource class that RealmContent provides you with:

let items = ContentListDataSource(style: .sectionsByTag)

Use .plain for a plain list or .sectionsByTag for a list with sections having the pages split by their tag property.

3) Initialize the data source

Call loadContent(from:) to set which realm file to use as the content source:

items.loadContent(from: try! Realm())

You can also have the data source automatically tell your table or collection view to reload the data whenever changes come in from the Realm Object Server (best option):

items.updating(view: tableView)

4) Implement your table view or collection view data source methods like usual, but fetch data from the content data source. The class offers few methods to do that like: numberOfSections, numberOfItemsIn(section:), titleForSection(section:), and itemAt(indexPath:).

This way you can implement your own table view or collection view data source methods and do any UI setup or other logic that you need. (For more detailed code sample check out the demo app in the RealmContent repo.)

5) Presenting a content “page”

Present a ContentViewController instance to display content. You can do this from a table/collection view tap delegate method, prepareForSegue(_:) method, or from an arbitrary piece of code.

Here’s an example of how would it work after a tap on a table cell:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  tableView.deselectRow(at: indexPath, animated: true)

  let item = items.itemAt(indexPath: indexPath)
  let vc = ContentViewController(page: item)

  navigationController!.pushViewController(vc, animated: true)

The presented view controller uses a table view to dynamically show the content from the given ContentPage element. In case you change the content remotely, the changes will be reflected in real-time on screen.

Dynamically add, edit, or remove content

The best aspect of using RealmContent is that you can modify the displayed content at any time - all changes will be synchronized in real-time to all connected users. (And upon connecting for all users who aren’t connected in this very moment of course.)

You can easily use the Realm Browser app to add or remove new pages, add, re-arrange, and otherwise modify blocks of content, and more. You can even change the accent color of your headings and links.

Editing content via Realm Browser

Try RealmContent now

The component is open source and you can find the source code and a demo app here:

The quickest way to try RealmContent in your app is via CocoaPods; add pod 'RealmContent' to your Podfile.

If you have an idea for a feature, want to report a bug, or would like to help us with feedback reach us on Twitter or create an issue on GitHub.

We’re excited to see how far are you going to push this component and the awesome dynamic apps you’re going to create with it!

Read more

Easy End-to-End Encryption: Introducing ZeroKit for Realm

by /

Realm is dedicated to helping you build great apps, and one of the ways we do that is by making it easier to work with the data that powers your apps. Instead of having to write (and maintain) fragile networking and serialization code, the Realm Mobile Platform handles that work automatically, making realtime data sync, sharing, and building server-side data features easy. And of course, we do it securely, offering HTTPS/TLS, AES-256 encryption at rest, and flexible access control features. You are freed to focus on the work that will matter to your users.

But for some apps and some use cases, you need a higher level of data security. That’s why we’re happy to announce end-to-end encryption, with Tresorit’s new ZeroKit SDK integration with the Realm Platform. Now you can easily build realtime, reactive apps that meet the standards required for handling healthcare, government, financial, and other highly sensitive data.

Understanding End-to-End Encryption

End-to-end encryption is the method of choice to protect data transmitted between devices. By encrypting data on the source device before transmission, man-in-the-middle attackers cannot decode the data if they capture it, even if the transmission route itself isn’t encrypted. Only the clients who share the crypto keys can access the information; no other sources potentially snooping traffic, including internet service providers, can see what information is contained within that data. Today, this is standard practice for encrypted chat apps like Signal, Threema, iMessage, and FaceTime.

The challenge is that end-to-end encryption requires a very extensive set of processes to implement, and that can eat up a ton of development time. And if they are not implemented and tested properly, it’s possible to leave flaws that attackers could exploit. End-to-end encryption isn’t impossible or broken—it’s just hard, and it’s important to do it right.

Tresorit + Realm Make It Easy

With the ZeroKit SDK integration for the Realm Mobile Platform, Tresorit built an exceptionally simple, secure, and scalable integration with Realm. Building on their depth of knowledge in building cloud security services, the ZeroKit SDK makes end-to-end encryption accessible to all development teams.

At the core of ZeroKit is an SDK that provides a secure user auth service with end-to-end encryption functionality. This enables the sharing of encrypted data between devices using a single user account and also any number of other accounts which have been granted access.

ZeroKit works on the principle of using the user account system to share encryption keys between client devices. When a new user is invited to view encrypted data from another user, an encryption key is shared in order to decrypt the data. If desired, the key can also be revoked, rendering the data once more inaccessible.

Instead of completely rewriting your backend, you can integrate ZeroKit into Realm without any trouble. Combining the best of both worlds, Tresorit has set up a way to use ZeroKit to perform end-to-end encryption in conjunction with the synchronization capabilities of the Realm Mobile Platform so that your data is end-to-end encrypted while synchronizing seamlessly, in realtime.

How It Works

How it works is actually quite simple. ZeroKit integrates itself with Realm via the Realm Mobile Platform’s ability to allow third-party services to authenticate synchronization sessions. When a user logs into Realm, they use their ZeroKit credentials, which identifies them as a unique user to the Realm Mobile Platform. Once logged in, the encryption keys for that account are made available on that device throughout the user’s login session.

Tresorit diagram

After login, each time a set of data is to be saved, the developer calls a ZeroKit API to encrypt the data on the device. Behind the scenes, ZeroKit stores and uses the keys generated for the current Realm, so that developers don’t have to deal with the complexity of crypto. The encrypted data is then saved to Realm where the information cannot be read successfully by any attacker or even the server itself. To decrypt the data, the same process is repeated in reverse. If the logged-in user has access to the keychain (“tresor”) associated with the Realm, data will be seamlessly decrypted.

To share data with other user accounts, you can combine Realm’s and ZeroKit’s share permissions features. This requires Realm to share the required data and Tresorit to share the appropriate key to decrypt it. The guest user can now read the data with both components. You can also revoke the encryption key, meaning that even if the Realm data file lingers on the guest user’s disk, the information is rendered inaccessible.

In this way, Realm is able to synchronize data out in the open and absolutely nothing in Realm’s stack, or the infrastructure it is run on, is in charge of the encryption. What’s even more exciting is that ZeroKit was built in a way that even Tresorit doesn’t have access to the keys because they are stored encrypted with a secret derived from the ZeroKit user’s password. And Tresorit doesn’t have access to the password either: this is what they call “zero knowledge” service. ZeroKit uses Augmented Password-authenticated Key Agreement (APAKE) protocols to achieve this.

Although end-to-end encryption is all about client-side data access with servers that can’t decrypt data, you don’t have to encrypt everything this way. You can decide to only encrypt sensitive data end-to-end; the rest, you can access on your Realm Object Server. However, if you still need to access encrypted data on the server, you can use ZeroKit’s Node SDK, which enables you to log in a ZeroKit user on the server. Storing the password of this special server user is a task you need to plan carefully though, or ask the Tresorit team’s advice on best practices using Hardware Security Modules and other tricks to keep your product secure.

Combining Realm and Tresorit’s solutions is exceptionally advantageous for use cases requiring enhanced security. In order to compromise data in this architecture, an attacker must both compromise your data and separately steal the keys from every single user, one by one, on their client devices to decrypt it. It’s really fantastic for Tresorit to show us how easy it was to integrate their services into our own, and together, they provide a level of security that is absolutely unparalleled.

The solution is ready for you to experiment with today, just remember you’ll need to do a few more steps before taking the end product into live production to ensure your users’ privacy: for example writing code to validate your users’ email/phone number after registration and arranging certs on your servers. Details are covered in ZeroKit’s documentation.

If you’re building an app dealing with highly sensitive data, we definitely recommend you check out ZeroKit and give it a try!

Read more

Realm Java 3.4 - Reverse Relationship Queries and Sync Progress Listeners

by /

We’re releasing version 3.4 of Realm Java today, and with it introducing reverse relationship queries and sync progress listeners. Read on for all the details.

Reverse Relationship Queries

In Realm Java 3.1 we added beta support for reverse relationships using the @LinkingObjects annotation. In 3.4 we are making it possible to query those relationships as you would with a normal RealmList or RealmObject reference:

public class Person extends RealmObject {
   public String name;
   public Dog dog;
public class Dog extends RealmObject {
   public String name;
   public final RealmResults<Person> owners = null;
// Query for owner as you would a RealmList
Person owner = realm.where(Dog.class).equalTo("", "Jane").findFirst();

Queries on @LinkingObjects work the same way as Link Queries on RealmLists and with this change we are considering @LinkingObjects stable, and are moving them out of beta.

Sync Progress Listeners

Realm Mobile Platform offers a true offline-first experience, where changes can be applied immediately to the local Realm irrelevant of the network conditions. In the background, synchronization happens automatically, and when the network is available, changes quickly propagate across devices and the server. This enables the realtime, collaborative experiences unique to Realm.

There are times, however, when it’s useful to know how much data is left to transfer. Perhaps on the first launch of your app, you’d like to make sure a sizable amount of the data is available before presenting your user interface. At other times, your app will simply benefit from showing when data is synchronizing, by presenting a progress bar or activity indicator.

This is why we’ve added APIs to monitor sync progress by registering ProgressListeners on the SyncSession.

Realm realm = Realm.getInstance(config)
SyncSession session = SyncManager.getSession(config);
// Show progress bar while waiting for an image you just wrote to the Realm
// to be uploaded
session.addUploadProgressListener(ProgressMode.CURRENT_CHANGES, new ProgressListener() {
   public void onChange(Progress progress) {
       if (progress.isTransferComplete()) {
       } else {
// Show a UI hint as long as you are downloading data from the remote server
session.addDownloadProgressListener(ProgressMode.INDEFINITELY, new ProgressListener() {
   public void onChange(Progress progress) {

Note, that currently progress listeners can only be registered if a Realm instance is open.

See the CHANGELOG for the full list of changes.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on Stack Overflow, GitHub, or Twitter.

Read more

Bringing Education into the Digital Age with Realm

by /
Thread Learning: Coordinated Autism Education Powered by Realtime Data Sync and Offline-first Capabilities

Each day, special education teachers manually track thousands of data points related to student progress. At the end of the day, they graph that data with a ruler and analyze the results. The process is incredibly cumbersome and time consuming, and paper-based data has significant limitations.


Thread Learning is advancing the way that teachers, parents, and therapists educate children with special needs and autism. Thread Learning’s behavioral data collection platform allows caregivers to record student data using an iPad. The platform then automatically graphs and analyzes the data, provides quality control, and shares the results with all members of a child’s care team, including parents.

Armed with electronic data, a caregiver team can more efficiently coordinate the work of all members to better serve the needs of the student. For example, a child may be working on speech skills with three classroom teachers, as well as a speech therapist and behavioral analyst after school. Thread Learning syncs data in realtime across all team member devices. More informed caregivers means better quality instruction and improved student outcomes.

Building a Coordinated Care Platform

To deliver on their vision of coordinated care, Thread Learning needed a data handling solution that could allow caregiver teams to collaborate in realtime. One of the co-founders was exposed to Realm in a graduate school computer science class. He recognized its potential to enable advanced features that would otherwise be impossible to implement as a nascent startup.

“Realm really helped accelerate our development timeline. We were up and running in weeks instead of months.”
- Sam Raudabaugh, Co-Founder & CTO, Thread Learning

The Thread Learning team initially developed their app using the Realm Mobile Database. This allowed them to bypass the typical headaches of MySQL and an ORM, as well as the technical and resource debt that comes with non-object oriented data solutions.

After the Realm Mobile Platform was released, the Thread Learning team found it a natural progression to explore its more robust data handling and realtime synchronization capabilities. They had been using a REST API to handle data flows, but Realm’s data sync capabilities offered a much better solution. Two-way data synchronization enables a team of caregivers to work simultaneously on the same set of data in realtime.

“We tested Realm against our REST API and the results were impressive.”
- Sam Raudabaugh, Co-Founder & CTO, Thread Learning

Offline-First, Simplified

As school WiFi networks are often unreliable, Thread Learning also needed robust offline capabilities, so that caregivers could still input and access data regardless of connectivity. One of the founders’ early mentors had advised them to avoid offline functionality entirely because it’s “too hard and complicated.” However, the Realm Mobile Platform enables Thread Learning to easily handle networking complexities, such as data updates and conflict resolution, without the issues that typically arise with REST APIs.

Because data loss has historically been a big issue with paper-based processes, Thread Learning especially appreciated Realm’s built-in support for offline-first use cases. With Realm’s client-side database, all app data is stored locally and remains fully accessible when offline, providing a continuous, responsive offline user experience. When connectivity is restored, updates are automatically synced with the Realm Object Server and across all care team devices. Realm’s conflict resolution capabilities ensure that data is always up to date.

“With Realm, we don’t have to worry about what happens when devices go offline and data conflicts happen.”
- Gregory Brill, Co-Founder & CEO, Thread Learning

As the Thread Learning team works on evolving their platform, Realm’s transparency around new feature development helps them plan their own feature roadmap. This helps them better manage their growth and support their mission to serve 1m+ autistic children in the U.S. within the next five years.

“Realm allows us to leapfrog the competition.”
- Gregory Brill, Co-Founder & CEO, Thread Learning

Read more

Realm Events at WWDC 2017

by /

WWDC Week is coming and Realm is planning another week filled with WWDC Events!

Join Realm in San Jose and San Francisco for a variety of events. If you are in town we hope you will join us, and if you are not, tune in on Facebook and Twitter for our second year of “Realm Live from WWDC”. Whether you have tickets to the conference or are in town for other events, we have something planned for you.

  • Keynote Viewing Party: Come see the keynote live streamed at Realm HQ in San Francisco.
  • WWDC Bingo: Play an epic game of WWDC Bingo, powered by Realm, at the Realm viewing party, live at the keynote, or from the comfort of your own home. (Details and app coming soon)
  • Swift Panel: We’re hosting a panel discussion on the second night of the conference in San Jose (Details and registration below - location: Westin San Jose - Across from WWDC and AltConf).
  • WWDC Live @ AltConf: See interviews with WWDC & AltConf attendees, as well as live streams of a variety of AltConf Sessions. Check back for a full schedule.
  • Realm World Tour - San Jose: Join us as we continue the Realm World Tour in San Jose and announce new locations for the Summer!

Keynote Viewing Party

Just because you don’t have tickets to the conference, doesn’t mean you have to watch the Keynote alone. Come by Realm Headquarters in San Francisco for a viewing party, and join other developers as well as the Realm Team to watch the Keynote together. We’ll have brunchy bites and drinks.

When: Monday June 5th, 2017 @ 10am

Where: Realm Headquarters: 148 Townsend St, San Francisco, CA 94107

  • 9am: Doors open! Mix & mingle and grab some breakfast and drinks.
  • 10am: Keynote + WWDC Bingo.
  • Afterwards: Mix and mingle some more and grab a Realm t-shirt on your way out.

RSVP: Reserve your spot!

Swift Panel

Join Chris Lattner, Jesse Squires, Kamilah Taylor and Kevin Ballard as Realm’s JP Simard moderates this panel-style discussion on everything Swift.

When: Tuesday June 6th, 2017 @ 6pm

Where: Westin San Jose 302 S Market St San Jose, CA 95113

  • 6pm: Doors open! Mix & mingle among your fellow Swifters. Drinks and light snacks provided.
  • 7pm: Panel + Q&A.
  • Afterwards: Stay and chat with our panelists, mix and mingle some more.

*IMPORTANT: Capacity for this event is limited. RSVPs are required to attend and will be FIRST COME FIRST SERVED for the first 100 people at the door by 6pm.

RSVP: Reserve your spot!

Realm World Tour - San Jose

We just closed out the first leg of our Realm World Tour (See the highlights), and it was awesome! But we didn’t make it to San Jose, so we are kicking off the second leg of our Realm World Tour during WWDC week. You’ll be able to connect with Realm users who are in town from all over the world, see live Realm demo’s, & learn more about our newly launched Realm Mobile Platform.

When: Wednesday, June 7, 2017

Where: Westin San Jose 302 S Market St San Jose, CA 95113


Read more

Announcing Realm World Tour - The Encore!

by /

Whew! After traveling across 23 cities in less than 2 months in February and March we had to take a little breather.

But now we are back in action and sending more of our top product engineers out across the globe to bring the Realm Platform to you live!

We’ve reached out to leaders of the developer communities in each city, and with their help as local hosts, have planned a great evening for attendees. Each event includes an introduction to the free Developer Edition plus discussion of some of the advanced features, followed by sample code, practical demos, and extensive technical Q&A session — all led by a Realm product engineer. There will also be plenty of time to talk one-to-one, to share best practices, and to learn from each other. And, we’ll have some special attendees-only limited edition Realm swag to give out!

realm-world-tour-facebook We are starting off this leg of the tour in San Jose followed by another stop in Seoul, then onto Toronto, Denver and Atlanta, and adding MORE cities as we go. You can see other stops on the tour here.

Want us to come to you? If you want us to stop in YOUR city, tweet @Realm with hashtag #Realmworldtour and #cityname. We will be tallying votes throughout the tour, so get your friends to vote too! **Bonus points if you hook us up with a local meetup group or host location! ;)

We hope to see you!

The Realm World Tour events are free, but space is limited — check out the official web page for the latest info and chance to register.

Read more

Serverless Logic with Realm: Introducing Realm Functions

by /

Today we’re announcing Realm Functions, a new part of Realm that makes building server-side functionality a lot easier for mobile developers. Now, you can make server-side features without enlisting backend developers, plus you get all the benefits of building on top of the Realm Mobile Platform: you don’t need to add another endpoint to a server, and then write the serialization and networking code that would let you connect with it. You just connect your app to Realm, write a Realm Function in your web dashboard, and watch your code execute reactively as data streams in. Today’s release is a beta, and it’s available today to everyone, whether you’re building an app in an enterprise-scale team or for a small side project.

Performant data storage and realtime data synchronization are important parts of building a great app, but there’s an endless world of possibilities when you can add custom logic to your server. You can write functionality that needs to be protected from tampering, call and coordinate countless other APIs, or use your app’s aggregated data to power machine learning systems. Unfortunately, sophisticated server-side features are hard to build, and hard to integrate with your mobile apps. Even a basic streaming API requires lots of work from the backend developers who will build out the server-side code, and a lot of attention and maintenance so that your apps and server can communicate the data your users need.

Write code that does work, not code that makes work

Realm is deeply committed to getting rid of the roadblocks between you and great apps — and up until now, the bulk of our work has revolved around data. The data you work with in your apps should be easy to save, easy to sync, and easy to respond to as it changes — wherever it changes, and whoever changes it. With Realm Functions, we aim to make it just as easy to create the logic that your app is built on so that you can focus on delivering hard, important features.

In our web environment, you simply write JavaScript to perform the tasks you need, and you’ll instantly see the results as data pours in and your code runs reactively in response. You can breathe a sigh of relief, as adding more features doesn’t also mean adding more fragility and maintenance to your app: you don’t have to add any new serialization or networking code to make a Realm Function work, as the Realm Mobile Platform takes care of getting data to connected clients.

Try out Realm Functions

To show how easy it is, we added a cool new feature to our Realm Tasks app. When you create a task that has a time or date in the title, we’ll use a natural language processing API to turn that into a due date on your task. We did it with just a few lines of code in the app to display the reminder, and a few more lines of JavaScript to call the NLP API and update the Task object. Check out the video, and continue below to get started yourself.


To try it out yourself, just head over to our Realm Tasks repository and follow the instructions there to get started with the Realm Mobile Platform and Realm Functions. Or if you’d like, you can jump right to the Realm Functions documentation.

Realm Functions is a powerful way to add server-side logic to your app through a simple web interface. All Realm Mobile Platform users get access to the Realm Functions beta, and you can start using it today. Today’s beta release lets Developer Edition users try Realm Functions for free with up to three concurrent running Functions; Pro and Enterprise Edition customers have an unlimited number of Functions they can implement. We’re excited to see what you can build using Realm Functions!

Read more

Announcing Realm for Universal Windows Platform

by /

Today, we’re pleased to announce delivery of the most requested feature of our .NET community: Realm Mobile Database for Universal Windows Platform (UWP). UWP support is a major piece in the Microsoft puzzle for Realm—we’ve long had full support for Xamarin, a few months ago we added Win32 support, and a few weeks ago we joined the Azure Marketplace, enabling anyone to get started with the Realm Platform with just a few clicks. All of this has helped make .NET the fastest growing community of Realm developers over the last two quarters.

Realm for UWP means you can use Realm’s world-class object database to build apps for the 400 million mobile, PC, and Xbox devices powered by Windows 10—so you can now use Realm on virtually any modern Windows platform, including the Surface family of devices. For Xamarin developers, UWP support means that Realm now supports all platforms using Xamarin.Forms (Android, iOS, and now, UWP). With Realm and Xamarin.Forms, you can use a single codebase to build apps for all major mobile platforms.

With the addition of UWP, Realm now supports .NET developers across all popular mobile platforms—iOS, Android, and Windows 10—allowing people to use a single persistence and ViewModel layer across all of them. The strength of the Realm .NET community combined with the mobile innovation we see coming out of Microsoft encourages us to continue investing in growing our .NET offerings. We’re excited to share new and exciting tools for the .NET community of developers and we can’t wait to see what you’ll build. It’s as easy as jumping into the documentation.

Read more

Realm Java 3.2: Open Realms Asynchronously, Download Realm, Read-only Flag

by /

We’re releasing version 3.2 of Realm Java today, and with it introducing asynchronously opening a Realm, making read-only Realms as well as more improvements to our synchronized Realm APIs. Read on for all the details on this and more.

Asynchronously opening a Realm

The general recommendation for opening a Realm has always been using Realm realm = Realm.getInstance(configuration). Normally this is extremely fast as we internally cache Realm instances. However, if you have migrations or need to copy an initial file from assets, opening the Realm file for the first time might be a bit slower than you would like.

With 3.2 we now introduce Realm.getInstanceAsync(configuration, callback). This method allows you to open a Realm instance on a background thread and only return once all expensive operations have completed.

One way of using this method can be seen below:

// Let all your activities implement this class
public abstract class BaseActivity extends Activity {
   private Realm realm = null;
   private RealmAsyncTask realmAsyncTask;

   protected void onCreate(Bundle savedInstanceState) {
       realmAsyncTask = Realm.getDefaultInstanceAsync(new Callback() {
           public void onSuccess(Realm realm) {
               if (isDestroyed()) {
                   // If the activity is destroyed, the Realm instance should be closed
                   // immediately to avoid leaks. Or you can call realmAsyncTask.cancel()
                   // in onDestroy() to stop callback delivery.
               } else {
                   BaseActivity.this.realm = realm;
                   // Remove the spinner and start the real UI.
       // Show a spinner before Realm instance returned by the callback.

   protected void onDestroy() {
       if (realm != null) {
           realm = null;
       } else {
           // Calling cancel() on the thread where getInstanceAsync was called on to
           // stop the callback delivery. Otherwise you need to check if the activity
           // is destroyed to close in the onSuccess() properly.

   // This can be overridden by activities so they can start displaying data once Realm
   // is ready.
   abstract void onRealmReady(Realm realm);

Download Realm

Alongside Realm.getInstanceAsync() we also added a new option for synchronized Realms: SyncConfiguration.Builder.waitForInitialRemoteData().

You can enable this option to force Realm to download an initial dataset from the server before reporting the Realm as ready to be opened. This can be beneficial if it doesn’t make sense for your app to display anything until it has a full dataset available. “Full” is determined by the point in time the client contacts the server, so if more data is written by other devices in the meantime, they are not taken into consideration. These changes will of course continue to synchronize in the background after the Realm has been opened.

SyncConfiguration config = new SyncConfiguration.Builder(getUser(), getUrl())

// This will not be called until the remote Realm has been fully downloaded.
Realm.getInstanceAsync(new Realm.Callback() {
   public void onSuccess(Realm realm) {
       // Use Realm

This dataset will only be downloaded the first time the Realm is opened i.e., no local Realm file exists. After that, the Realm will be opened immediately.

Read-only Realms

With 3.2 we also enabled the option to create read-only Realms. These can be useful if you do not want to accidentally write changes to a Realm file.

RealmConfiguration config = new RealmConfiguration.Builder()
       .modules(new MyModule())

SyncConfiguration syncConfig = new SyncConfiguration.Builder(getUser(), getUri())
       .modules(new MyModule())

Marking a Realm as read-only will cause all transactions against that Realm to throw an IllegalStateException.

Note this also prevents writing any schema information to the file, so marking a Realm as read-only only makes sense if you at the same time either set RealmConfiguration.Builder.assetFile() or SyncConfiguration.Builder.waitForInitialRemoteData().

Since the Realm schema is automatically created from all known Realm model classes, there can be an advantage to explicitly enumerate all classes in the provided file. This is done using modules.

Refreshing a Realm

Calling Realm.refresh() will force all asynchronous queries to be synchronous in order to provide a consistent view of the underlying data. You should only use refresh() if you are not using any asynchronous queries.

With the changes introduced to iterators in 3.0, it has now been possible to add Realm.refresh() back after popular demand.

Calling Realm.refresh() will force any Realm instance to the latest version of the database as well as trigger any registered notifications. This has especially been useful if you are using some other notification system than Realm notifications, e.g. event busses.

Other improvements

  • It is now possible for SyncUsers to change their password using the new SyncUser.changePassword(password, callback) API.
  • It is now possible to ask if a given SyncUser is an administrator on the Realm Object Server by calling SyncUser.isAdmin(). Admin users have special capabilities like changing permissions for other users.
  • Transient fields in Realm Model classes will now be treated as implicitly having the @Ignore annotation.
  • DynamicRealmObjects now support reverse relationships as well using DynamicRealmObject.linkingObjects(String parentClass, String parentField).

See the CHANGELOG for the full list of changes.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on Stack Overflow, GitHub, or Twitter.

Read more

Realm Events at Google I/O 2017

by /

Are you headed to Google I/O? Join Realm in Mountain View and San Francisco for some I/O fun! Whether you have tickets to the conference or are just in town for the other events, we have something planned for you.

  • Women in Android Panel: Realm and San Francisco Android Developers are hosting a Panel discussion on the second night of the conference at Realm Headquarters (Details and registration below).

  • Google I/O Scavenger Hunt and Realm Swag: Can’t make it to San Francisco but still want in on the fun? Don’t worry, look for us at Shoreline on Wednesday before the Keynote. We will be handing out details about our Google I/O Scavenger Hunt and some fun Realm swag.

Google i/o Scavenger hunt

Women in Android Panel

Realm and the SF Android Developers Meetup invite you to our Google I/O Women in Android Panel.

Join Stacy Devino, Caren Chang, Angella Derington, and Nicolette Yadegar, with Britt Barak from Women Techmakers Tel Aviv as she moderates this panel-style discussion on everything Android.

When: Thursday May 18th, 2017

  • 6pm: Doors open! Mix & mingle among your fellow Android Devs. Drinks and snacks provided.
  • 7pm: Panel + Q&A
  • Afterwards: Stay and chat with our panelists, mix and mingle some more.

*IMPORTANT: Capacity for this event is limited. RSVPs are required to attend and will be FIRST COME FIRST SERVED for the first 150 people at the door by 6pm. RSVP ON EVENTBRITE


Stacy Devino is the head of Mobile Apps for one of the fastest growing FinTech companies in the US. Prior to that she was the technical lead for Android Apps at Home Depot. Stacy has been doing this since Android 1.6 and has worked in embedded Android operating-system-level as well as hybrid and consumer applications.

Caren Chang studied Computer Science at UC Berkeley and has been around the Bay Area ever since. Previously she worked at companies such as Dreamworks and VSCO, and is currently helping build smart ovens at June. Her favorite part of Android development is working with custom views and animation.

Angella Derington is a seasoned Android developer with a passion for creating experiences that delight the user in their simplicity and polish. In the last few years, she has been busy working on the Android apps for major retailers. When not building apps, Angella keeps herself busy with her two kids, dog, and two cats!

Nicolette Yadegar is currently the Technical Lead for Support Engineering on Microsoft’s Yammer Android team. As Team Lead, she focuses on Performance and QA, while working on internal projects including upgrading/adding new libraries, adding fun features like GIF support, and refactoring efforts. Before that she worked at Microsoft on their IoT Innovation team and their Frameworks & Services team.

Britt Barak (Moderator) is co-leading Android Academy TLV which is one of the largest and most active Android communities out there. Britt is also leading the Women Techmakers Israel community. She is on a mission of sharing knowledge and inspiring others. You can find her public speaking, mentoring and blogging on Android development at .

This panel is presented by Realm, a platform to build reactive apps, realtime collaborative features, and offline-first experiences.

Read more

Arccos Golf Ups its Game with Realm

by /

Delivering fast, responsive app experiences online and offline

A golfer’s game depends on good decisions with every shot. Performance data, captured and analyzed in realtime, can help players improve their skills mid-game and make better decisions throughout the course. As the field of connected sports gains momentum, Arccos Golf is using today’s innovative IoT and mobile technologies to re-invent one of the world’s oldest games.


The company’s innovative shot-tracking system pairs small, ultra-light golf club sensors with a mobile app and analytics platform. Using GPS and Bluetooth, Arccos automatically captures data on every shot, analyzes a player’s strengths, weaknesses, and trends, and delivers feedback through the mobile app in realtime. Such data-driven insights can dramatically improve a player’s ability to make the right decisions at every hole.

In order to deliver on their vision, Arccos needed to provide a fast, seamless user experience with zero disruption to the player’s golf routine. Their system had to handle significant data flows from sensor data capture and analytics processes, as well as from rendering detailed course maps and a rich UI—all in realtime. Because users expect apps to function wherever they are, the Arccos mobile application needed to work on remote golf courses where mobile connectivity may be unreliable.

Three different models for handling data

Originally, Arccos outsourced the development of an Android app that took a traditional approach. The app used RxJava and OrmLite, SQLite. However, the performance for this model was unacceptably low and the Arccos development team had to persist data as JSON blobs as a workaround. To translate data between models and keep it all in sync, the Arccos development team had to write a massive amount of code. This meant significant time spent debugging and maintaining code, which distracted the team from focusing on new development. Arccos users experienced frustratingly slow app performance, which inhibited their ability to get the most out of it. Arccos knew that they had to re-architect their system in order to make it more efficient and sustainable.

Unified data model on Realm

Arccos decided to explore a simplified data solution using Realm, and they started by building a proof of concept to evaluate this new approach. The development team was initially impressed with how quickly they could get Realm up and running — no lengthy boilerplate code or set up processes needed. More importantly, switching to Realm resulted in a significant increase in transaction speed.

“With Realm, we noticed a huge improvement in the loading time of one of our asset classes. What used to take 6 seconds, now takes about 20 milliseconds. The speed was impressive.”
- Muhammad Arafat, Android Team Lead, Arccos Golf


Arccos found that Realm’s reactive architecture enabled a fast, responsive user experience, regardless of network connectivity. In the golf course environment, offline usage is critical. The team was particularly happy with Realm’s support for offline-first use cases. Realm persists data locally on device, which enables users to access all app data while offline.

“Realm’s fast local storage allows us to provide an extremely responsive app experience, both online and offline.”
- Colin Phillips, VP of Software, Arccos Golf

Realm’s single data model allowed Arccos to simplify their system architecture, streamline app code, and more easily improve stability. Because app data is stored as objects, the database didn’t “get in the way” and distract the team with tedious data translation tasks, making it much easier to implement a pure object model that worked well for their application. In addition, Realm only pulls into memory the parts of the object that you actually need or are actually touching. This effectively spreads the transaction time across user actions ensuring a seamless experience for the user.

“Re-architecting our app on Realm shrank our code base by about 35%, making it much easier for us to debug and maintain.”
- Colin Phillips, VP of Software, Arccos Golf


Using platform tools, such as the Realm Browser, the Arccos team found that they were able to discover and troubleshoot bugs much faster. The browser helped Arccos ensure that their objects were structured correctly, see the one-to-one mapping across objects in memory and the database, and quickly identify any issues.

Ultimately, migrating to Realm has been a game-changing decision for Arccos. Players now experience a highly responsive app that works well on a remote golf course. The development team can now move faster and spend more time building new ways to help players become better golfers.

Read more

Realm Platform on Azure: Easiest Path to Realm in the Cloud

by /

Today we’re pleased to announce the availability of Realm Mobile Platform, Developer Edition, on Microsoft’s Azure Marketplace.

The Realm Platform has always been easy to install — we offer a Linux and Mac version, a public AMI for Amazon Web Services, and detailed instructions for Digital Ocean — but if you have an Azure account, this is by far the easiest way to get started. You simply find us in the Marketplace, and in a few clicks (see the steps below), you can have your own instance of Realm’s Developer Edition immediately available. It’s free and you can use it for almost anything – though of course fees for Azure may apply.

This is really just the beginning — we’re now an official Microsoft partner, and are working on making the other Realm Platform editions available on Azure. And we’re on the same path with the other major cloud platforms as well, so stay tuned.

Getting Started on Azure

Sign into your Azure account (or create one), then click the green plus sign (+) on the left to get access to the Marketplace. Enter Realm in the search box and choose the result. You’ll be walked through Azure’s quick and pretty straightforward five-step process to get your server configured. The necessary ports for Realm — 9080 and 22 — are preset. Other than naming things and setting up SSH, you can pretty much accept all the defaults.


Following step five, it takes a minute or two for deployment, after which you’ll see the details of your new server, including the IP address. Open a new tab, copy that into the address bar, add :9080 to the end, and hit enter — you’ll see the Create Admin User panel for your shiny new Realm Object Server instance running Azure. Success! Now you are ready to start exploring the platform — start with one of our fun demo apps, like Realm Pop (realtime gameplay), Realm Draw (realtime collaboration), or Realm Tasks (realtime task management).


Read more

Realm ObjC & Swift 2.7: Permission APIs, Fast Reconnects, Password Change & Bug Fixes!

by /

We’re releasing version 2.7 of Realm Objective‑C and Realm Swift today. In this release, we’re introducing improved permission APIs, faster reconnects, password change and applying a few bug fixes to keep your apps running strong.

Improved Permission APIs

We’re introducing new APIs for changing and retrieving permissions for synchronized Realms.

These APIs are intended to replace the existing Realm Object-based permissions system that were introduced in 2.0.4 and 2.4.4.

For example, the previous way to grant or revoke permissions was to create a {RLM}SyncPermissionChange object in the user’s managementRealm().

You could then observe that “change” object to be notified when the server had processed it, and whether or not the operation was successful.

let permissionChange = SyncPermissionChange(realmURL: realmURL,    // The remote Realm URL on which to apply the changes
                                            userID: anotherUserID, // The user ID for which these permission changes should be applied
                                            mayRead: true,         // Grant read access
                                            mayWrite: true,        // Grant write access
                                            mayManage: false)      // Grant management access

let managementRealm = try! user.managementRealm()
try! managementRealm.write {
// Wait for server response
token = permissionChange.addNotificationBlock { _ in
  switch permissionChange.status {
  case .notProcessed: break // handle case
  case .success: break // handle case
  case .error: break // handle case
  print(permissionChange.statusMessage) // contains error or informational message

Retrieving permissions used a separate Realm (SyncUser.permissionRealm()) and a separate model type (SyncPermission).

let permissionRealm = try! user.permissionRealm()
let permissions = permissionRealm.objects(SyncPermission.self)
token = permissions.addNotificationBlock { _ in
  // permissions updated

These APIs have now been deprecated in favor of a simpler family of permission APIs that don’t require knowledge about how the internal transport mechanism is implemented.

There’s now a single {RLM}SyncPermissionValue type that should be used to apply, revoke and retrieve permissions:

// Applying permissions
let permission = SyncPermissionValue(realmPath: realmPath,
                                     userID: anotherUserID,
                                     accessLevel: .write)
user.applyPermission(permission) { error in
  if let error = error {
    // handle error
  // success!
// Retrieving permissions
user.retrievePermissions { permissions, error in
  if let error = error {
    // handle error
  // success! access permissions

You’ll find more documentation for using Realm’s Permissions APIs in the Access Control section of our docs.

These APIs require any edition of the Realm Object Server 1.1.0 or later.

Faster Reconnects

This release detects changes in connectivity status via the Reachability framework to instantly attempt a reconnection with the object server if the connection was not sustained.

Previously, the time before reconnection occurred was dependent on how long it had been since the connection was lost due to our exponential backoff reconnection algorithm.

Password Change

Users can now change their passwords using the -[RLMSyncUser changePassword:completion:] API if using Realm’s ‘password’ authentication provider. This API requires any edition of the Realm Object Server 1.4.0 or later.

Other Enhancements

  • {RLM}SyncConfiguration now has an enableSSLValidation property (and default parameter in the Swift initializer) to allow SSL validation to be specified on a per-server basis.
  • Transactions between a synced Realm and a Realm Object Server can now exceed 16 MB in size.

Bug Fixes

  • Support Realm model classes defined in Swift with overridden Objective-C names (e.g. @objc(Foo) class SwiftFoo: Object {}).
  • Fix -[RLMMigration enumerateObjects:block:] returning incorrect oldObject objects when enumerating a class name after previously deleting a newObject.
  • Fix an issue where Realm.asyncOpen(...) would fail to work when opening a synchronized Realm for which the user only had read permissions.
  • Using KVC to set a List property to nil now clears it to match the behavior of RLMArray properties.
  • Fix crash from !m_awaiting_pong assertion failure when using synced Realms.
  • Fix poor performance or hangs when performing case-insensitive queries on indexed string properties that contain many characters that don’t differ between upper and lower case (e.g. numbers, punctuation).

iOS 7 Support

We’d like to remind you that we will continue to support a minimum target iOS version of 7.0 as long as we can, but will be increasing the minimum target iOS version to 8.0 in a future release.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on the Realm Forums, Stack Overflow, GitHub, or Twitter.

Read more

Xamarin Show: Realm Mobile Database & Platform

by /

This week, James is joined by friend of the show Adam Fish, Product Manager at Realm, who introduces us to the cross-platform mobile reactive database, Realm for .NET. Realm offers developers a crazy fast, mobile optimized, easy to use, open source, and totally free database. Adam walks us through setting up your first Realm database and then expands on it to create an offline-first, real-time, and reactive mobile app leveraging the Realm Mobile Platform. You don’t want to miss this episode!

Intro (0:00)

My name’s Adam Fish, I’m the Senior Director of Product at Realm. I’ve been with the company for about two years now. Realm is a database company, and is about five years old. It got started as a typical Silicon Valley start-up. The founders are Danish and came over from Copenhagen, raised some capital, and built the database from scratch.

During the first three years, it was a high-speed, in-memory, server-based database. We quickly realized, with its unique capabilities coupled with the growth of mobile, that there was a great opportunity to basically build a replacement for SQLite or any of the derivatives. Two years ago, we launched it for iOS, and since then we’ve added Android, Xamarin, .NET support, and React Native. It’s really designed to be a cross-platform, and easy to use mobile database.

What is Realm? (2:19)

It’s pretty common to forget that the only database that anyone uses on mobile is SQLite. There’s always different wrappers that people put around it, Core Data being a major one for the iOS platform, but at the core, it’s SQLite.

With Realm, the biggest argument to build something new was that at the end of the day, when you’re building mobile apps, you’re working with objects. There’s always this mismatch between the object layer and the SQL layer. A lot of effort and Core Data goes into trying to manage that, with a ORM, but you’ve always got some level of mismatch than can happen. With Realm, we decided to build it from the ground up as something new.

At the core level it is a table interface, but the actual columns can link to other tables, so it inherently supports links. You don’t have that actual mismatch. We’re able to then provide an object interface in whatever the native language is that you’re using for the platform, and it just becomes a very fluid development experience.

Coupled with that, there’s been a real focus on performance. It’s a column-based database, so it can have really high performance and it uses memory mapping. You’re basically interacting with the data directly on disk and there’s no in-memory copying that’s happening.

Before I worked at Realm, I was working on my own start-up, we had an iOS app, and we were spending an inordinate amount of time fighting with Core Data; your typical threading issues and things that you’ll run into. When it launched, it was the simplicity of Realm that attracted me. I remember going to the website, and I saw the code snippets, and thought, “Aw, yes, that makes a ton of sense.”

The moment you start playing with it and you realize that not only is the interface really easy, but I’m not having to pay any performance penalty for that ease of use. It just became a no-brainer. We re-wrote the whole app using Realm. We started to do some really cool stuff, and contributed some open source projects that use Realm. I became an avid user, and the company ended up saying, “Why don’t you come and join us?”

Since then, speaking with developers, they echo the same thing. It’s the ease of use and performance. It’s the two that come hand in hand that really sells it.

Every month, there’s more Fortune 1000, Fortune 500 companies, and major brands that are moving to Realm and using it in their applications on all the different platforms. It has really taken off. It is fully open source.

During the first three years of the company, when it was more server-oriented, the core database was written in C++. When we first launched, just the bindings that wrapped that C++ layer into the native language of the platform were open source. Last summer, we open sourced the core. The whole stack of the actual database is fully open source on GitHub. Coupled with the open source nature and the fact that it’s been five years since it’s been built, we think it really is battle-tested at this point.

I have to hand it to a lot of the developers on our team, I became a better developer just watching how the Cocoa team at Realm had actually built that version of it. With a lot of the Objective-C run time and stuff, they do some really amazing work. Being able to watch that in real time, it’s amazing as a developer.

Realm and Cross-Platform (7:48)

The easiest place to get started with Realm is, that’s the number one place. You can just jump right in. We try to get you into the code, right on the homepage, so you can see a little bit about how you would use the database and some of the newer features that we recently released. If you go over to the docs, you dive into the platform that you’re looking for. If you look on the Xamarin docs, there’s a quick getting started. The package is available through NuGet.

The code is on GitHub. There is Xamarin iOS, Xamarin Android, and Win 32 support. We’re trying to work on spreading that over time to all the other platforms.

While there are some edges of the SDKs that are platform specific, the general concept of how you work with Realm objects and write transactions, is all very similar. Someone that is fluent in .Net could look at a Java code snippet and immediately adjust it.

Sample App(9:45)

There is a sample app that we include in the repo called Quick Journal. It’s basically a task tracker app. The first thing really to dive into is that looking at the data model of this application, we are creating an object called a JournalEntry. That’s what’s going to be represented in the table.

When you work with Realm, this is kind of like the key starting point of understanding how Realm works. You sub-class a Realm object, and that sub-class is actually the definition of your data model or schema. With the JournalEntry, we’ve got a string property for Title, another for BodyText, and then we’re demonstrating linking to another object, where we have another Realm object called EntryMetadata.

This is the nice part about how Realm works under the hood; at the core level those links are represented just like a reference. What’s really cool is that if you actually build an app that has a really complex object graph, when you query and you’re working with these Realm objects, you don’t actually have to pull all those objects into memory. You can actually traverse the object graph lazily. It does it for you. As you go to new objects, you basically don’t have to use as much memory. There’s no foreign key look-ups or anything. It is just working with almost totally native objects.

If you create a Realm JournalEntry object initially, its state is unmanaged. It’s basically just an in-memory object. It becomes managed when you actually add it to the Realm. We can show what that looks like, but that’s what isManaged is demonstrating.

The Realm is actually a single file. You can actually introspect the file. We’ve got a little browser application. It’s a single Realm file that is the database, so when you take an unmanaged object, and you add it, it’s going to write that and persist it on disk as well.

Transactions (13:41)

The view looks like a standard XAML. The add entry command is what we’re binding to. In the view model there is nothing Realm specific in that. In the application, if I click “add,” I can just give my journal entry an ID. If we look at the view model code, when I actually am adding that journal entry into the Realm, this is what it looks like.

	private void AddEntry()
            var transaction = _realm.BeginWrite();
            var entry = _realm.Add(new JournalEntry
                Metadata = new EntryMetadata
                    Date = DateTimeOffset.Now,
                    Author = AuthorName

            var page = new JournalEntryDetailsPage(new JournalEntryDetailsViewModel(entry, transaction));


The key aspect of working with Realm objects is that every interaction or write that you’re doing with Realm, or any change to the object, needs to be done in a write transaction. There is a very big secondary benefit of having this transaction-based model, which is you know the database is basically acid compliant, and it also is crash-safe.

Acid compliant means that you have a stable view of the database no matter which thread you’re on. It’s just basically a number of different properties the database has that prevents it from having corruption.

The database has what’s called a multi-version concurrency control system. Basically, what happens is the database in itself is essentially just a B-tree, if you want to visualize it. When you create a new transaction, there’s a new root of the tree that’s added, but any other thread that’s doing reads, because the writes are not blocked by reads, continues to look at all the data that’s in the previous root. You can add all your changes in that transaction, and then it’s actually going to write it down to the disk, and call an F-sync command, so that it is actually fully on the disk.

Only after that has happened, do we advance to the new root of the tree. The key point is that, if suddenly your phone died, or something happened and that other transaction was partially complete, the original root of the tree is still there, so you’re never going to get corrupt data. It’s a little in the weeds, but using write transactions actually is very beneficial in terms of the durability of the database itself.

The _realm is how you actually interact with the database itself. The thing with Realm is that it is all accessors, as I would call it. Whether you’re working with the database as a whole, which is what this Realm.GetInstance is,

_realm = Realm.GetInstance();

or you’re working with any sort of Realm object that you’ve gotten from the database, all of those are thread-specific. If I was on a background thread, I would also call Realm.GetInstance, and I would have an object specific for that thread. You never want to pass Realm objects across threads.

We actually do offer the capabilities to do that, so you can. There are ways to pass objects across threads, but you can’t just take an object and directly move it across.

When you actually commit the transaction, and it finishes, then it’s written to the disk.

The transaction gives you the, in the acid, the atomicity of being able to say that these two changes need to always be applied together. That’s another benefit of having a transaction system. We would recommend to use larger transactions than to do a bunch of really small ones. It depends on the circumstance. If you’re looping over, we’d say put the loop in the transaction itself.

Querying (20:16)

It’s pretty straightforward interaction in this application. There’s a lot of other things that are more hidden here, because this is a forms-based application. The querying that’s happening in terms of reading the data is a little bit more hidden from view.

On the JournalEntryDetails page, when you’re typing, you are just writing to the Realm object, setting it right on the property itself. Then you save, and this is where the commit happens.

You created the entry, and you passed that entry to this page. You’re doing live data binding to that entry, and then when you hit save, then it commits it. You’re not setting any properties, you’re just typing to it, and it just knows.

That’s all from the binding itself. We tap into that automatically. That’s going to be setting it for you, and so as you commit it, that’s when it’s actually going to hit the disk. When you’re using Xamarin forms, the data binding is plugged into automatically.

We actually support a number of different abilities to listen for changes. If you’re not using a form-based application, we have a number of different APIs where you can basically query the database.

You could query all the person objects in the Realm, and then, whenever that query changes, it tells you. We can even pass in a changes object that’ll say, “Here are the ones that have been inserted, deleted, or modified.”

If you’re working with an iOS or Android app directly, you can pass this into list view or a UI table view to do the animations, if you’re doing this more manually. We also support object notifications, so you can get when properties specifically change.

This is what’s beneath the hood with Xamarin forms, which is doing this automatically for you, but if you’re not using that, you can still tap into that same sort of reactive architecture. Once you’re done completing the transaction, you commit it, and there’s nothing you need to do.

We have a complex query capability. We tap in and use link with that, so you can use a similar link query syntax to work with the database. You can sort objects and use a number of different query capabilities.

The really interesting thing about this, is this lazy loading aspect of the database. When you perform a query, you’re not having to actually pull all those objects into memory. If you imagine you had 10,000 objects that match your query, it does not have to actually move all those into memory. Instead, only when you start accessing the individual objects in the query, do you actually start interacting with them. The memory performance for applications that have tons of data is much lower than you would find with SQLite.

When you perform the entries = _realm.All command, it’s not having to move all those objects into memory. Instead, if you had the screen where the objects were much larger than what could fit on the screen, as you’re scrolling and trying to call out to get the data, that’s when it’s actually interacting with it, so it’s extremely efficient.

We don’t support limit, because it’s irrelevant. You don’t have to paginate when working with this.

The vast majority of times, you can do it all on the UI thread. Now I know that’s kind of a very controversial statement. We’ve designed the performance with the memory mapping, lazy loading, and all these capabilities, that it really can be used on the main thread. Now there’s always going to be an edge case. You can very easily switch to background thread, get a new instance of the Realm for that thread, and work with the objects on the background thread. Then utilizing those notification capabilities, if you say, “were doing some sort of background synchronization on another thread”, and you make changes, your UI thread can subscribe to those notifications as those changes come in and react to it.

It’s a very simple model in terms of being able to listen for changes that are happening across threads. Even more interestingly, this works across processes. If you have an iOS, widget of some sort, where you’re using one of the notifications, original to apple watch app, you have different processes. Another process can be working with the Realm, making changes, and the other process can actually listen for those changes.

Realm Mobile Platform (28:38)

There was a master plan with Realm all along, and it builds off of this idea that the Realm objects are live and auto-updating. As you’re making changes, they’re being synchronized across threads. What we wanted to do was basically say, imagine it’s not the change coming from another thread that’s updating the object, what if that change is coming from another device, or a server? For the past couple years, we’ve been working on what is called the Realm Mobile Platform, and it includes a Linux-based application called the Realm Objects Server that automatically synchronizes changes. The really slick thing is, you pretty much already know how to use it if you know how to use Realm. There’s not much else more to it in terms of the client experience.

Every time you make changes to the local database, they get persisted locally on disk, and then the change itself is sent to the object server and it handles sending it wherever else it needs to go.

It is extremely low-latency. We aren’t sending the state of objects around, which is like traditional REST API, requesting the json. Instead, because we control the whole stack, we know the specific changes that have actually occurred, and we send the operations.

It’s designed to also be offline first, because from a client mobile developer perspective, your source of truth is the database on disk. You’re making changes to it, and then asynchronously, those changes get sent. On the server application, we used what’s called operational transformation. It’s basically a way to make sure that all the changes get ordered correctly regardless of whether the network has sent them in order.

Realm Browser (31:06)

There is another app included that you can play with for the Realm Mobile Platform. It’s another task app. You just need Realm and Realm database. The key difference is there is a name space sync that includes a number of different APIs. If you don’t want to use the mobile platform if you’re not using the server, you don’t have to; it doesn’t change the database itself. It’s just other APIs that you can tap into if you want to use it.

We put a little more effort into the UI for this app, but it’s a task application where you can have lists, and then you can click in and add different tasks here. It’s also using Xamarin forms.

The key thing to show off is that, we have this mac application. We are working on a cross platform version of this, but today the Realm browser is just a mac application. It’s really cool because you can go in here and you can open up, local Realm database files. You can use this even on device, when you’re developing, you can go get the Realm file off the device and explore it if you need to.

If you download the zip file, the package for the Realm mobile platform, we have a free version, which is called the developer edition. You can run it locally on your mac, which is mainly just for debugging. If you’re going to use it for production, there’s a whole Linux installation. I’ve got it running just a single command. You start it up, and it runs in the terminal. After you start it up, it’ll open the dashboard. It’s a very primitive and basic dashboard at the moment.

You can see all the synchronized Realms that you’re working with. You can see all the users that are actually in the server itself, and even check out the logs.

I’ve got the server running locally, and so I have connected in the sample app, Realm task. I’ve logged into this local server. The synchronized Realm I’m connecting to is connecting to the local host and opening up the Realm file.

Beneath the hood, each application has its own copy of the data, and so the browser has its own copy of the Realm. The simulator has its own copy of the Realm, and the server, running in the background, is going to automatically synchronize the changes. If I make a change, you’re immediately going to see it. I can then undo the change, and call this task two.

The nice part about this, because it is a Xamarin form app, it is basically doing implicit transactions. Every time there is a property update, it is tapping into the inner workings of the data binding mechanisms to be able to create a write transaction on every small change, and so that’s how you’re seeing, it.

Specific character-by-character changes happening.

As a developer, you’re still just writing to make changes to a Realm object. Beneath the hood is the async networking that’s just doing everything for you. That’s really the productivity benefit. I’d rather not have to write json parsing and making network requests and handling any sort of the error scenarios. I just want to work with synchronous local APIs, and make the UI beautiful or build the unique capabilities in the app, rather than all the data handling that, we continually have to rewrite.

An individual Realm is the encapsulation of the data being synced. The unique nature is that, a Realm itself is very lightweight. In the previous app, we had the default Realm and we were just putting all the data into a single Realm. With the Realm mobile platform, we recommend thinking about it a little differently. You might have several different Realms with different datasets. That’s how you can synchronize data at different times. One part of the app, like the homework feature of the app might only use the homework Realm if the user goes to that area, and if not, it’s not actually doing any sort of synchronization.

Authentication (38:59)

The permissions for how you work with the platform is all around Realm users. The object server has built-in authentication for username and passwords. It also supports a number of federated or external identity systems, and so, we’ve recently added active directory support.

To actually go and get it implemented, you have to do a couple of things. When you start the server, there’s a configuration file. There’s a section called providers, and this is where you can enable the supported third-party providers. For example I’ve got the Azure provider with my attendant ID, because I’m using the Azure active directory cloud offering.

You have to set your client ID, and your redirect, but basically you create a credentials object, and there’s various different methods that we support. You can create a credential that’s a Facebook credential, a Google credential, or Azure active directory credential, etc.

We’re basically using the Azure STK to go out and get the access token, and then once the client has the access token, it passes it into Realm’s APIs to send that access token to the Realm server and say, “This is my identity through Azure, please verify it.” If it’s verified, then you become a Realm user.

If you just want a username and password type login, its done for you automatically. Instead of creating, a credential where you’re using Azure, you’d be just creating a credential with the username and password. There’s register and login methods associated with it.

Conclusion (41:45)

The number one place is to go for information is the website. You basically have two options. You can go download it locally on your mac, and get it up and running really quickly. Alternatively, you can go over to the Linux install. We support a couple different flavors of Linux: Red Hat, Enterprise, CentOS, and Ubuntu. We also have AWS/AMIs available, but the easiest way to do it is to get your Linux VM up and running, and then we just go through a couple of.

I think that sums it up. If you’ve got any questions, we are very active with support. You can go to the GitHub repo, and file an issue if you have any sort of problems that arise. Our documentation is all on, that’s just the best place to start if you’re interested.

Read more