ZEMOSO ENGINEERING STUDIO
June 5, 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
How to remix Amazon’s Working Backwards with Google’s Venture’s User Journey: The Dr. Strange Way
How to remix Amazon’s Working Backwards with Google’s Venture’s User Journey: The Dr. Strange Way
June 14, 2022
How we built a big data platform for a futuristic AgriTech product
How we built a big data platform for a futuristic AgriTech product
June 3, 2022
Zemoso Labs starts operations in Waterloo, Canada
Zemoso Labs starts operations in Waterloo, Canada
May 25, 2022
Deconstructing Elon Musk’s dog ate my homework answer for Twitter: More validation will be asked of startups
Deconstructing Elon Musk’s dog ate my homework answer for Twitter: More validation will be asked of startups
May 20, 2022
Real Talk: Lessons learned and evolved from 3M and Post-it®’s adoption of Crazy 8 methodology
Real Talk: Lessons learned and evolved from 3M and Post-it®’s adoption of Crazy 8 methodology
April 10, 2022
Understanding dynamic multi-column search with JPA Criteria for product development
Understanding dynamic multi-column search with JPA Criteria for product development
January 2, 2022
Product engineering zeitgeist: Implement OOPs in React JS using atomic design
Product engineering zeitgeist: Implement OOPs in React JS using atomic design
July 8, 2021
Honorable mention at O’Reilly’s Architectural Katas event
Honorable mention at O’Reilly’s Architectural Katas event
May 17, 2021
Product dev with testable spring boot applications, from day one
Product dev with testable spring boot applications, from day one
May 4, 2021
When not to @Autowire in Spring or Spring Boot applications
When not to @Autowire in Spring or Spring Boot applications
May 1, 2021
Efficiently handle data and integrations in Spring Boot
Efficiently handle data and integrations in Spring Boot
January 24, 2021
Unlock the power of atomic design in React and React Native using a theming library — Part 1
Unlock the power of atomic design in React and React Native using a theming library — Part 1
November 2, 2020
Our favorite CI/CD DevOps Practice: Simplify with GitHub Actions
Our favorite CI/CD DevOps Practice: Simplify with GitHub Actions
October 25, 2020
Kubernetes — What is it, what problems does it solve, and how does it compare with alternatives?
Kubernetes — What is it, what problems does it solve, and how does it compare with alternatives?
June 21, 2019
GraphQL — Why is it essential for agile product development?
GraphQL — Why is it essential for agile product development?
April 30, 2019
Orchestrating backend services for product development with AWS Step Functions
Orchestrating backend services for product development with AWS Step Functions
April 1, 2019
How To Decide When to Use Amazon Working Backwards, Business Model Canvas and Lean Canvas
How To Decide When to Use Amazon Working Backwards, Business Model Canvas and Lean Canvas
November 30, 2018
How to validate your Innovation: Mastering Experiment Design
How to validate your Innovation: Mastering Experiment Design
November 22, 2018
Working Backwards: Amazon's Culture of Innovation: My notes
Working Backwards: Amazon's Culture of Innovation: My notes
November 19, 2018
Product developer POV: Caveats when building with Spark
Product developer POV: Caveats when building with Spark
November 5, 2018
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

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

GraphQL — Why is it essential for agile product development?

April 30, 2019
12 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.

© 2021 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
June 5, 2022