Introduction to MongoDB Realm for Mobile Developers¶
This introduction explains the MongoDB Realm product at a high level for developers who primarily develop mobile applications. After reading, you should understand what MongoDB Realm is, how it interacts with Realm Database, and which benefits MongoDB Realm offers compared to traditional mobile development stacks.
What Problem Does MongoDB Realm Solve?¶
As a developer, you face a number of challenges during the development of any mobile application. To name a few, mobile developers must:
- Gracefully handle the unpredictable environment of mobile apps in which connections can be lost, devices can shut down at any time, and clients usually update with a significant delay after release, if at all.
- Coordinate between mobile clients, backend APIs, and databases to maintain a common schema of objects and endpoints with which to communicate.
- Stay aware of security vulnerabilities across all components in an ecosystem, from the HTTP protocol, to API endpoints, to data stored on the client.
- Consistently serialize objects between networks, database storage, and application memory.
- Program in the languages and frameworks for one or more mobile operating systems.
All of these challenges present different obstacles. You can solve each in isolation with a wide variety of libraries and frameworks. Deciding which solution solves each problem with the right tradeoffs for your use case is a challenge most developers know all too well.
In addition to the challenges presented by each component individually, the combination of multiple components creates even more challenges. For instance, you can use a Java library on your Android client to serialize objects in that environment, but consistently serializing across Android, iOS, the web, and each of your backend services presents more of a challenge.
Many, but not all, of these challenges arise due to particularities of the mobile environment, including network reliability, local storage, and keeping UIs reactive (up-to-date as underlying data changes). Realm Database solves many common mobile programming headaches:
- Local storage: Realm Database runs right on client devices. Access objects using the native query language for each platform, so storing, accessing, and updating your data is simple and lightweight.
- Network reliability: Realm Database is offline-first: you always read from and write to the local database, not over the network. When Realm Sync is enabled, Realm Database synchronizes data with MongoDB Realm over the network in a background thread, pushing local data changes to MongoDB Realm and pulling remote changes down. The sync protocol resolves conflicts consistently on each client and in the linked MongoDB Atlas cluster.
- Reactive UI: Live objects always reflect the latest data stored in Realm Database and allow you to subscribe to changes, so you can keep your UI up-to-date at all times.
The Realm SDK lets you connect to local realms for Android, iOS, Node.js, React Native, and UWP development.
Client applications generate a lot of data. Whether it's uploaded reviews and ratings, posts and comments on a blog, or inventory in a kitchen, you need to store that data somewhere. MongoDB Atlas provides cloud-hosted managed instances of MongoDB that are always available.
Atlas supports aggregations and other complex workloads with the full capabilities of MongoDB. You can connect to your Atlas instance in your backend services using MongoDB drivers for a wide range of languages. Or connect your Atlas instance to MongoDB Charts to visualize your data in real time. Storing your data in Atlas makes it easy to share data across users and platforms.
MongoDB Realm enables sync between Realm Database and MongoDB Atlas, seamlessly stitching together the two components into an application layer for your mobile app. To support these services, MongoDB Realm also provides components to fulfill several common application requirements:
- Realm Users and Authentication provide built-in user management with easy integration into third-party authentication providers, like Facebook, Google, and Apple.
- Realm Functions provide server-side logic for your Realm app. Similar to endpoints in a REST API, except instead of manually constructing the URL, headers, body, and method for a call to an HTTP endpoint, you call Realm Functions from a module of the Realm SDK in your client application.
- Realm Triggers automatically execute a function at a scheduled time or when an event occurs, such as a change to a database or a call to a HTTP endpoint.
- Realm Rules let you control who accesses what data.
- Server-side Realm Values and Realm Secrets enable you to define global variables and private credentials once and use them across your entire Realm app.
- Use the GraphQL API to access data stored in a linked MongoDB cluster using any standard GraphQL client.
The Realm Mobile SDKs let you can call functions, authenticate users, sync remote realms, and query your local realms.
Get Started with MongoDB Realm¶
Jump right in and create a MongoDB Realm application or check out our Task Tracker tutorial for any of these platforms:
You can also refer to the documentation for each client SDK:
- MongoDB Realm is a serverless application platform that takes care of the details of deployment and scaling for you. You can customize your Realm app with custom logic via functions and triggers, custom permissions via rules, and authentication via third-party SSO.
- Realm Database is an offline-first mobile object database in which you can directly access and store live objects without an ORM.
Live Objects and Realm Sync offer significant benefits over traditional mobile development stacks:
- Live Objects always reflect the latest state of data in the database, making it easier to keep your UI in sync with changes to your data, regardless of where those changes come from.
- Realm Sync synchronizes data between client-side realms and the server-side MongoDB Atlas cluster linked to your Realm app. The sync protocol resolves conflicts consistently across all instances of a realm, both on the server and in client applications.
- Realm Database synchronizes data in a background thread, abstracting away network usage so you don't have to worry about latency, timeouts, or dropped connections.