Increase app responsiveness with MongoDB Realm mobile database and AWS Wavelength
This post was contributed by Robert Oberhofer, Senior Director of Technology Partnerships at MongoDB.
This blog post introduces MongoDB Realm, and examines its core characteristics and key benefits. While Realm is widely used for building mobile applications, its capabilities are also relevant for other problem spaces, including IoT and Edge.
Introduction to Realm
Realm database is an open-source, developer-friendly project for mobile data storage, distributed under the Apache 2.0 license and backed by MongoDB. Realm’s mobile database is an object-oriented embedded alternative to SQLLite, CoreData, and Room, which was built for mobile and web developers with simplicity in mind. The idiomatic, object-oriented data model can save thousands of lines of code.
There are various real-world use cases of Realm and AWS working together. For example, Cox Automotive built their mobile application on AWS and MongoDB, using Realm to simplify critical edge-to-cloud sync and provide backend services to speed development work, including triggers, functions, and GraphQL.
Deep dive into Realm
Realm’s open-source Mobile SDK (GitHub) is a lightweight, fully featured database embedded within the application. Realm’s object-oriented data model is one key characteristic that simplifies development and is native to each supported language. This eliminates the need to work with object-relational mapping (ORM) frameworks, which means no more mapping of objects to relational schema and no need for SQL. Data stored in Realm’s objects can be queried, filtered, linked, and persisted. Unlike a traditional database, objects in Realm are live and fully reactive. Thus, for event-driven applications, Realm’s live objects allow users to subscribe and react to data change events. This eliminates the need to write code to periodically check the datastore for changes in the user’s data. And it’s all thread safe and ACID compliant. It is also possible to encrypt the entire datastore, which allows for the adoption of the Realm SDK for the most security-sensitive applications, such as banking and healthcare.
These characteristics allow developers to build mobile applications quickly and easily on the open-source Realm SDK. On AWS, this capability is complemented by Realm Application Services that provide common back-end services such as authentication, access control, GraphQL, functions, and triggers that simplify integrating Realm mobile applications with MongoDB’s data capabilities. Most notable is Realm Sync, which simplifies building apps that work for users regardless of signal strength or connectivity status. Realm Sync allows for the exchange of data in real time when a device is online, automatically stores when offline, and then can integrate and resolve data conflicts when a device comes online again. This allows for the creation of seamless solutions that work in network-challenged environments and is excellent for offline-first field worker applications, logistics, hospitality, retail, and IoT.
The lightweight and embedded nature of the Realm Database lends itself to be used in the context of IoT. One technical aspect that has been fundamental since the inception of Realm is the “zero copy architecture,” which guarantees persistence of data—even during sudden power loss. The same architecture also ensures a low memory footprint, which is great for resource-constrained environments. This combination allows Realm to act as a persistence layer for Edge components where connectivity is not guaranteed and data has to be cached for longer periods of time. Pair this with Realm Sync and/or MQTT, and it increases architectural flexibility of AWS IoT applications leveraging AWS IoT Sitewise and AWS IoT core. Realm has been used successfully for medical devices, in the automotive industry, and for industrial applications.
Realm on Edge: Using AWS Wavelength as an example for enabling latency-critical applications
One recent collaboration between MongoDB and AWS demonstrates the flexibility of Realm in additional contexts. Much of our physical world is increasingly connected via mobile networks. With the emergence of 5G networks, it is possible to unlock new capabilities due to the low-latency nature of the advanced technology. For applications that are latency sensitive, such as those in gaming, AR/VR, AI/ML, or the more critical arenas of autonomous vehicles or remote surgery, there’s a need to bring key application capability into the network.
Enter AWS Wavelength, which brings familiar AWS tools into mobile networks. The service allows you to deploy applications and data within mobile networks to cache time-sensitive data, execute time-critical AI/ML inference locally and allow ultra-fast collaboration and data exchange, such as with games.
Realm, as a fast, flexible and lightweight database, can be easily integrated with applications running in AWS Wavelength zones. As an embedded database, there is no additional separate deployment method for the application and database, simplifying the process.
By leveraging Realm Sync—and especially Flexible Sync—between the cloud and each AWS Wavelength Zone, Realm allows users to cache data that is relevant to the region, application, or user whenever they request a service and have associated data available instantaneously. Even if data changes in the cloud, Sync ensures that these changes are automatically reflected and ready in the respective AWS Wavelength Zone (or Zones), reducing the need for latency-heavy refresh requests from the cloud to update local stale data. Realm Sync makes it possible to ensure low-latency readable, writable, and up-to-date data at whichever Edge location it requires.
Realm is an easy to use, modern, fast, lightweight, and completely open-source database. It can be used in conjunction with many AWS services, such as AWS Wavelength, Amazon API Gateway, Amazon Cloudfront, AWS Lambda, and Amazon Kinesis, to develop mobile applications. It can also be embedded in traditional server applications running on Amazon Elastic Compute Cloud (Amazon EC2) in region or in local zones, or deployed in the context of AWS IoT architectures. With AWS Wavelength, Realm lets applications logic directly within mobile networks to ensure the lowest latency response time while greatly simplifying real-time data replication.
The content and opinions in this post are those of the third-party author and AWS is not responsible for the content or accuracy of this post.