WhoBuilt

Databases for mobile apps React Native & Realm

Aug 10, 2023· 56 min· 1.5K views·Watch on YouTube

Speaker

Andrew Meyer, a senior software engineer at MongoDB, explains Realm and mobile data design on the React Native Show podcast with its host.

How Realm differs from MongoDB

Meyer distinguishes MongoDB, a server database built for many connections, from Realm, a local object database for a device. Realm returns live objects that developers can use directly, rather than query results that must be copied into JavaScript state.

Choosing how to store app data

AsyncStorage works for simple key-value data, but larger JSON stores can take time to load and track. State libraries keep data in memory, while SQLite and ORMs add query and relationship management. Meyer says Realm offers typed models and direct object access without requiring developers to write SQL for common tasks.

Using Realm with React Native

To get started, install `realm` and `@realm/react`, define data models, and wrap the app in a Realm provider. The `useQuery` hook returns collections that can be filtered and sorted; hooks also listen for relevant changes and trigger React re-renders. Writes happen inside transactions, which Realm processes and can roll back if needed.

Offline-first apps and synchronization

With Flexible Sync, an app subscribes to the data it needs, such as records for a particular user or chat room. People can read and edit local data while offline, then synchronize changes when connectivity returns. Meyer gives delivery logistics and farming apps in areas with unreliable connections as examples.

Performance and upcoming work

Meyer says Realm avoids a separate hydration step by opening local data directly and loading it into memory as it is accessed. He also discusses work on WebAssembly support for browser use and a Realm.js version 12 release candidate that adds a TypeScript interface to Realm Core.

Takeaways

  • Use key-value storage for simple data; consider a local database when data volume and relationships grow.
  • Realm collections can feed React Native lists directly and stay current as data changes.
  • Transactions provide a controlled place to modify Realm objects and roll back invalid changes.
  • Flexible Sync can keep an app usable offline and synchronize subscribed data after reconnection.
  • Local-first storage can suit logistics, farming, chat, and note-taking apps where connectivity or fast access matters.

Mentioned in this talk

Search inside this talk

What was claimed 11

Show all 11 facts

Related talks