BlogAtlas Vector Search voted most loved vector database in 2024 Retool State of AI reportLearn more >>
MongoDB Developer
Realm
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Realmchevron-right

Announcing the Realm C++ SDK Alpha

Ian Ward, Jason Flax, Lee Maguire, Otso Virtanen5 min read • Published Apr 13, 2023 • Updated Apr 03, 2024
RealmSDKC++
Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Today, we are excited to announce the Realm C++ SDK Alpha and the continuation of the work toward a private preview. Our C++ SDK was built to address increasing demand — for seamless data management and on-device data storage solutions — from our developer community in industries such as automotive, healthcare, and retail. This interest tracks with the continued popularity of C++ as illustrated in the recent survey by Tiobe and the Language of the Year 2022 status by Tiobe.
This SDK was developed in collaboration with the Qt Company. Their example application showcases the functionality of Atlas Device Sync and Realm in an IoT scenario. Take a look at the companion blog post by the Qt Company.
The Realm C++ SDK allows developers to easily store data on devices for offline availability — and automatically sync data to and from the cloud — in an idiomatic way within their C++ applications. Realm is a modern data store, an alternative to SQLite, which is simple to use because it is an object-oriented database and does not require a separate mapping layer or ORM. In line with the mission of MongoDB’s developer data platform — designing technologies to make the development process for developers seamless — networking retry logic and sophisticated conflict merging functionality is built right into this technology, eliminating the need to write and maintain a large volume of code that would traditionally be required.

Why Realm C++ SDK?

We consider the Realm C++ SDK to be especially well suited for areas such as embedded devices, IoT, and cross-platform applications:
  1. Realm is a fully fledged object-oriented persistence layer for edge, mobile, and embedded devices that comes with out-of-the-box support for synchronizing to the MongoDB Atlas cloud back end. As devices become increasingly “smart” and connected, they require more data, such as historical data enabling automated decision making, and necessitate efficient persistence layer and real-time cloud-syncing technologies.
  2. Realm is mature, feature-rich and enterprise-ready, with over 10 years of history. The technology is integrated with tens of thousands of applications in Google Play and the Apple App Store that have been downloaded by billions of users in the past six months alone.
  3. Realm is designed and developed for resource constrained environments — it is lightweight and optimizes for constraints like compute, memory, bandwidth, and battery.
  4. Realm can be embedded in the application code and does not require any additional deployment tasks or activities.
  5. Realm is fully object-oriented, which makes data modeling straightforward and idiomatic. Alternative technologies like SQLite require an object-relational mapping library, which adds complexity and makes future development, maintenance, and debugging painful.
  6. Updates to the underlying data store in Realm are reflected instantly in the objects which help drive reactive UI layers in different environments.
Let’s dive deeper into a concrete example of using Realm.

Realm quick start example

The following Todo list example is borrowed from the quick start documentation. We start by showing how Realm infers the data schema directly from the class structure with no conversion code necessary:
Next, we’ll open a local Realm and store an object in it:
With the object stored, we are ready to fetch the object back from Realm and modify it:
While the above query examples are simple, Realm’s rich query language enables developers to easily express queries even for complex use cases. Realm uses lazy loading and memory mapping with each object reference pointing directly to the location on disk where the state is stored. This increases lookup and query speed performance as it eliminates the loading of pages of state into memory to perform calculations. It also reduces the amount of memory pressure on the device while working with the data layer.
The complete Realm C++ SDK documentation provides more complex examples for filtering and querying the objects and shows how to register an object change listener, which enables the developer to react to state changes automatically, something we leverage in the Realm with Qt and Atlas Device Sync example application.

Realm with Qt and Atlas Device Sync

The Qt framework contains a comprehensive set of highly intuitive and modularized C++ libraries and cross-platform APIs to simplify UI application development. Qt produces highly readable, easily maintainable, and reusable code with high runtime performance and small footprint.
The example provided together with Qt is a smart coffee machine application. We have integrated Realm and Atlas Device Sync into the coffee machine application by extending the existing coffee selection and brewing menu, and by adding local data storage and cloud-syncing — essentially turning the coffee machine into a fleet of machines. The image below clarifies:
Integrating Realm and Atlas Device Sync into the Coffee Machine application
This fleet could be operated and controlled remotely by an operator and could include separate applications for the field workers maintaining the machines. Atlas Device Sync makes it easy for developers to build reactive applications for multi-device scenarios by sharing the state in real-time with the cloud and local devices.
This is particularly compelling when combined with a powerful GUI framework such as Qt. The slots and signals mechanism in Qt sits naturally with Realm’s Object Change Listeners, emitting signals of changes to data from Atlas Device Sync so integration is a breeze.
In the coffee machine example, we integrated functionality such as configuring drink recipes in cloud, out of order sensing, and remote control logic. With Realm with Atlas Device Sync, we also get the resiliency for dropped network connections out of the box.
The full walkthrough of the example application is outside of this blog post and we point to the full source code and the more detailed walkthrough in our repository.

Looking ahead

We are working hard to improve the Realm C++ SDK and will be moving quickly to private preview. We look forward to hearing feedback from our users and partners on applications they are looking to build and how the SDK might be extended to support their use case. In the private preview phase, we hope to deliver Windows support and package managers such as Conan, as well as continuing to close the gap when compared to other Realm SDKs. While we don’t anticipate major breaking changes, the API may change based on feedback from our community. We expect the ongoing private preview phase to finalize in the next few quarters and we are closely monitoring the feedback from the users via the GitHub project.
Want more information? Interested in learning more before trying the product? Submit your information to get in touch.
Ready to get started now? Use the C++ SDK by installing the SDK, read our docs, and follow our repo.
Then, register for Atlas to connect to Atlas Device Sync, a fully-managed mobile backend as a service. Leverage out-of-the-box infrastructure, data synchronization capabilities, network handling, and much more to quickly launch enterprise-grade mobile apps.

Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Article

Realm Meetup - Realm Kotlin Multiplatform for Modern Mobile Apps


Mar 21, 2023 | 23 min read
Tutorial

Building an Android App


Jan 22, 2024 | 6 min read
Tutorial

Create a Custom Data Enabled API in MongoDB Atlas in 10 Minutes or Less


Sep 23, 2022 | 8 min read
Tutorial

Realm Partitioning Strategies


Sep 23, 2022 | 17 min read
Table of Contents