ZEMOSO ENGINEERING STUDIO
February 7, 2022
5 min read

Why Realm trumps SQLite as database of choice for complex mobile apps — Part 1

For an Internet of Things (IoT) device, we were working on a data-intensive React Native mobile application, which used location data to plot on an interactive map. The data was serialized and encoded as binary data. For the product to work as intended, the data had to be deserialized and converted to the right format to store it and display it to end users. 

The data structure, as the development progressed, understandably grew in complexity and size. 

Growing understanding of our challenges

Unlike when developing applications for distributed systems and back-end servers, there are fewer resources to work with for a mobile-first application. On phones and tablets, memory and storage space is very limited.

Hence, processing (data retrieval, data structure for the database, data manipulation etc.)  has to be optimized and trade-offs have to be made on what data we absolutely need to save and what we can let go. 

Our options

1. SQLite

2. Realm

3. Other object-relational mapping (ORMs) built over a  Structured Query Language (SQL) engine

We started our journey with SQLite. Given how well SQLite worked with small application data, this seemed like the right choice at the time. However, shortly after, we ran into several challenges.  

Migration: Data migration was a pain; it was code and time intensive. Even a simple task in subsequent versions involved a protracted process.

Database (DB) file: Sometimes the journal files maintained by the DB are not deleted after a transaction is complete. We would not want to stop the journaling process run by the database to help debug failed transactions in posterity. Since the database file can be read easily, many extensions have to be downloaded to protect it.

To counter these challenges, I decided to give Realm by MongoDB a try. It is a non-relational database. It lets you declare relationships between different schema objects. It is a mobile-first database and takes memory limitations on a mobile device into consideration.

Realm, unlike other ORMs, has a new engine driving it (which is a custom-made engine, not SQL). This engine at its core is created using C/C++ and is blazing fast (exciting stats later in this post). The ideology behind how the Realm team visualizes data is what makes it so lightweight and developer-friendly.

Realm is easy to use; it uses familiar objects to store and retrieve data. All data models and schemas are defined as simple classes which extend the RealmObject class. Required fields and primary keys are easy to use with annotations.

The results returned by a Realm query can be directly used as a list interface and are iterable, unlike SQLite query results, which are returned as cursor objects.

Some statistics for performance of Realm are as follows:

Image source: Realm Academy

Image source: Realm Academy

Image source: Realm Academy

Realm is innovating a lot, and we’ll end Part 1 on that note.

Stay tuned for Part 2 where we’ll explore Realm code examples and take a closer look at some of its core ideas. 

ZEMOSO ENGINEERING STUDIO

Why Realm trumps SQLite as database of choice for complex mobile apps — Part 1

By Zemoso Engineering Studio
February 7, 2022
5 min read

For an Internet of Things (IoT) device, we were working on a data-intensive React Native mobile application, which used location data to plot on an interactive map. The data was serialized and encoded as binary data. For the product to work as intended, the data had to be deserialized and converted to the right format to store it and display it to end users. 

The data structure, as the development progressed, understandably grew in complexity and size. 

Growing understanding of our challenges

Unlike when developing applications for distributed systems and back-end servers, there are fewer resources to work with for a mobile-first application. On phones and tablets, memory and storage space is very limited.

Hence, processing (data retrieval, data structure for the database, data manipulation etc.)  has to be optimized and trade-offs have to be made on what data we absolutely need to save and what we can let go. 

Our options

1. SQLite

2. Realm

3. Other object-relational mapping (ORMs) built over a  Structured Query Language (SQL) engine

We started our journey with SQLite. Given how well SQLite worked with small application data, this seemed like the right choice at the time. However, shortly after, we ran into several challenges.  

Migration: Data migration was a pain; it was code and time intensive. Even a simple task in subsequent versions involved a protracted process.

Database (DB) file: Sometimes the journal files maintained by the DB are not deleted after a transaction is complete. We would not want to stop the journaling process run by the database to help debug failed transactions in posterity. Since the database file can be read easily, many extensions have to be downloaded to protect it.

To counter these challenges, I decided to give Realm by MongoDB a try. It is a non-relational database. It lets you declare relationships between different schema objects. It is a mobile-first database and takes memory limitations on a mobile device into consideration.

Realm, unlike other ORMs, has a new engine driving it (which is a custom-made engine, not SQL). This engine at its core is created using C/C++ and is blazing fast (exciting stats later in this post). The ideology behind how the Realm team visualizes data is what makes it so lightweight and developer-friendly.

Realm is easy to use; it uses familiar objects to store and retrieve data. All data models and schemas are defined as simple classes which extend the RealmObject class. Required fields and primary keys are easy to use with annotations.

The results returned by a Realm query can be directly used as a list interface and are iterable, unlike SQLite query results, which are returned as cursor objects.

Some statistics for performance of Realm are as follows:

Image source: Realm Academy

Image source: Realm Academy

Image source: Realm Academy

Realm is innovating a lot, and we’ll end Part 1 on that note.

Stay tuned for Part 2 where we’ll explore Realm code examples and take a closer look at some of its core ideas. 

Recent Publications
Actual access control without getting in the way of actual work: 2023
Actual access control without getting in the way of actual work: 2023
March 13, 2023
Breaking the time barrier: Test Automation and its impact on product launch cycles
Breaking the time barrier: Test Automation and its impact on product launch cycles
January 20, 2023
Product innovation for today and the future! It’s outcome-first, timeboxed, and accountable
Product innovation for today and the future! It’s outcome-first, timeboxed, and accountable
January 9, 2023
From "great potential" purgatory to "actual usage" reality: getting SDKs right in a product-led world
From "great potential" purgatory to "actual usage" reality: getting SDKs right in a product-led world
December 6, 2022
Why Realm trumps SQLite as database of choice for complex mobile apps — Part 2
Why Realm trumps SQLite as database of choice for complex mobile apps — Part 2
October 13, 2022
Testing what doesn’t exist with a Wizard of Oz twist
Testing what doesn’t exist with a Wizard of Oz twist
October 12, 2022
Docs, Guides, Resources: Getting developer microsites right in a product-led world
Docs, Guides, Resources: Getting developer microsites right in a product-led world
September 20, 2022
Beyond methodologies: Five engineering do's for an agile product build
Beyond methodologies: Five engineering do's for an agile product build
September 5, 2022
Actual access control without getting in the way of actual work: 2023
Actual access control without getting in the way of actual work: 2023
March 13, 2023
Breaking the time barrier: Test Automation and its impact on product launch cycles
Breaking the time barrier: Test Automation and its impact on product launch cycles
January 20, 2023
Product innovation for today and the future! It’s outcome-first, timeboxed, and accountable
Product innovation for today and the future! It’s outcome-first, timeboxed, and accountable
January 9, 2023
From "great potential" purgatory to "actual usage" reality: getting SDKs right in a product-led world
From "great potential" purgatory to "actual usage" reality: getting SDKs right in a product-led world
December 6, 2022
Why Realm trumps SQLite as database of choice for complex mobile apps — Part 2
Why Realm trumps SQLite as database of choice for complex mobile apps — Part 2
October 13, 2022
ZEMOSO ENGINEERING STUDIO
February 7, 2022
5 min read

Why Realm trumps SQLite as database of choice for complex mobile apps — Part 1

For an Internet of Things (IoT) device, we were working on a data-intensive React Native mobile application, which used location data to plot on an interactive map. The data was serialized and encoded as binary data. For the product to work as intended, the data had to be deserialized and converted to the right format to store it and display it to end users. 

The data structure, as the development progressed, understandably grew in complexity and size. 

Growing understanding of our challenges

Unlike when developing applications for distributed systems and back-end servers, there are fewer resources to work with for a mobile-first application. On phones and tablets, memory and storage space is very limited.

Hence, processing (data retrieval, data structure for the database, data manipulation etc.)  has to be optimized and trade-offs have to be made on what data we absolutely need to save and what we can let go. 

Our options

1. SQLite

2. Realm

3. Other object-relational mapping (ORMs) built over a  Structured Query Language (SQL) engine

We started our journey with SQLite. Given how well SQLite worked with small application data, this seemed like the right choice at the time. However, shortly after, we ran into several challenges.  

Migration: Data migration was a pain; it was code and time intensive. Even a simple task in subsequent versions involved a protracted process.

Database (DB) file: Sometimes the journal files maintained by the DB are not deleted after a transaction is complete. We would not want to stop the journaling process run by the database to help debug failed transactions in posterity. Since the database file can be read easily, many extensions have to be downloaded to protect it.

To counter these challenges, I decided to give Realm by MongoDB a try. It is a non-relational database. It lets you declare relationships between different schema objects. It is a mobile-first database and takes memory limitations on a mobile device into consideration.

Realm, unlike other ORMs, has a new engine driving it (which is a custom-made engine, not SQL). This engine at its core is created using C/C++ and is blazing fast (exciting stats later in this post). The ideology behind how the Realm team visualizes data is what makes it so lightweight and developer-friendly.

Realm is easy to use; it uses familiar objects to store and retrieve data. All data models and schemas are defined as simple classes which extend the RealmObject class. Required fields and primary keys are easy to use with annotations.

The results returned by a Realm query can be directly used as a list interface and are iterable, unlike SQLite query results, which are returned as cursor objects.

Some statistics for performance of Realm are as follows:

Image source: Realm Academy

Image source: Realm Academy

Image source: Realm Academy

Realm is innovating a lot, and we’ll end Part 1 on that note.

Stay tuned for Part 2 where we’ll explore Realm code examples and take a closer look at some of its core ideas. 

Recent Publications

ZEMOSO ENGINEERING STUDIO

Testing what doesn’t exist with a Wizard of Oz twist

October 12, 2022
7 min read
ZEMOSO ENGINEERING STUDIO

Beyond methodologies: Five engineering do's for an agile product build

September 5, 2022
6 min read
ZEMOSO ENGINEERING STUDIO

How we built a big data platform for a futuristic AgriTech product

June 3, 2022
8 min read
ZEMOSO NEWS

Zemoso Labs starts operations in Waterloo, Canada

May 25, 2022
5 min read
ZEMOSO ENGINEERING STUDIO

Honorable mention at O’Reilly’s Architectural Katas event

May 17, 2021
5 min read
ZEMOSO ENGINEERING STUDIO

Product dev with testable spring boot applications, from day one

May 4, 2021
5 min read
ZEMOSO ENGINEERING STUDIO

When not to @Autowire in Spring or Spring Boot applications

May 1, 2021
5 min read
ZEMOSO ENGINEERING STUDIO

Efficiently handle data and integrations in Spring Boot

January 24, 2021
5 min read
ZEMOSO ENGINEERING STUDIO

Our favorite CI/CD DevOps Practice: Simplify with GitHub Actions

October 25, 2020
5 min read
ZEMOSO ENGINEERING STUDIO

How to use BERT and DNN to build smarter NLP algorithms for products

February 14, 2020
12 min read
ZEMOSO ENGINEERING STUDIO

GraphQL — Why is it essential for agile product development?

April 30, 2019
12 min read
ZEMOSO ENGINEERING STUDIO

GraphQL with Java Spring Boot and Apollo Angular for Agile platforms

April 30, 2019
9 min read
ZEMOSO ENGINEERING STUDIO

Deploying Airflow on Kubernetes 

November 30, 2018
2 min read
ZEMOSO PRODUCT STUDIO

How to validate your Innovation: Mastering Experiment Design

November 22, 2018
8 min read
ZEMOSO PRODUCT STUDIO

Working Backwards: Amazon's Culture of Innovation: My notes

November 19, 2018
8 min read
ZEMOSO ENGINEERING STUDIO

Product developer POV: Caveats when building with Spark

November 5, 2018
2 min read

Want more best practices?

Access thought-leadership and best practice content across
the product development lifecycle

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

© 2023  Zemoso Technologies
Privacy Policy

Terms of Use
LinkedIn Page - Zemoso TechnologiesFacebook Page - Zemoso TechnologiesTwitter Account - Zemoso Technologies

© 2021 Zemoso Technologies
Privacy Policy

LinkedIn Page - Zemoso TechnologiesFacebook Page - Zemoso TechnologiesTwitter Account - Zemoso Technologies
May 25, 2023