FindOurDevices
Device Locator App
FindOurDevices is a React Native mobile app for iOS and Android allowing users to find their and their friends' devices by seeing movements in real-time on OpenStreetMap, create private groups, accept or decline invitations to join groups, remove members of a group they created, and control their own location visibility.
Table of Contents
Purpose
While working at MongoDB, I designed and built this application together with another colleague to provide a comprehensive React Native example showcasing data modeling, partitioning, MongoDB's Atlas Device SDK and their object database called Realm which is embedded directly in the device, as well as their Atlas App Services serverless backend.
Use Cases
The diagram below shows what a user is able to do within the application.
Data Model
The diagram below shows an Entity Relationship diagram of the data model used, showing all database objects and their relationships.
Database and Serverless Backend Integration
The diagram below illustrates how MongoDB's Atlas Device SDK and Realm are integrated in FindOurDevices, specifically for the use case of having groups. It also pinpoints from what exact places of the data model the data on various screens come from, and what serverless functions are called when the user interacts with the screen.
Denormalization
When the user navigates to the groups screen, they will see all of their group memberships. At this point, only the user realm and the devices realm have been opened. So in order to see a friendly name for each group without opening each individual group realm or asking the server, the data has been denormalized by duplicating Group.name
in GroupMembership.groupName
. The same is true for the user's display name and the device's name and location.
Hence, accessibility is favored over consistency in this case. This means that the duplicated data may not be consistent 100% of the time, since a change will need to be updated in multiple places and only synced when online.
Inconsistency is not an issue in this case, thus that tradeoff could be made confidently.
Opening a Group Realm
When the user clicks on a group, that specific partition is synced and the realm is opened. Once opened, it listens for changes to the data within the group.
Since the location of group members may be updated several times per minute, the realm is explicitly closed and the listeners removed as soon as the user navigates away from the screen in order to not receive and react to changes unnecessarily.
If the user clicks on the same group again, the realm that already exists on the device (due to the first open) is reopened. If online, any changes that may have happened in between the openings will be propagated via the Device Sync protocol.
Data Flow When Updating the Location of a Device
The diagram below walks through the activities that occur and how the data flows when the main use case of the application occurs.
Main use case:
- A device moves X meters and the new location can be seen on the map by the user and any group members that the user is a part of.
All activities within a specific column in the diagram represent what happens on that specific entity, e.g. on John's phone, Mary's phone, the serverless backend (called MongoDB Realm in the diagram), or on the cloud database (MongoDB Atlas).