DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • An Overview of Creating Databases With Python
  • Building a High-Throughput Distributed Sequence Generator Using the Hi-Lo Algorithm
  • When Snowflake Lies to You: Understanding False Failures in dbt Pipelines
  • Master-Class: Understanding Database Replication (Single, Multi, and Leaderless)

Trending

  • DevOps and Platform Engineering Readiness Checklist: Everything Needed for a Scalable, Secure, High-Velocity Delivery Platform
  • Contract-First Integration: Building Scalable Systems With Flyway, OpenAPI, and Kafka
  • Designing Agentic Systems Like Distributed Systems
  • How We Diagnosed a Hidden Scheduler Failure in a Docker Swarm Cluster Serving 2 Million Users
  1. DZone
  2. Data Engineering
  3. Databases
  4. How Realm is Better Compared To SQLite

How Realm is Better Compared To SQLite

Read this article in order to see a comparison between Realm and SQLite.

By 
Lipika Gupta user avatar
Lipika Gupta
·
Jun. 21, 18 · Opinion
Likes (3)
Comment
Save
Tweet
Share
29.3K Views

Join the DZone community and get the full member experience.

Join For Free

While starting a new application, we often wonder which database to use, especially if the application is database intensive. Recently, I came across Realm, which is really well-built and surprisingly very fast compared to SQLite. In this post, I aim at showing how Realm compares to SQLite.

Let’s start with looking at basic CRUD operations in Realm.

Create:

Image title

Read:

Image title

Update:

Image title

Delete:

Image title

Now let’s look at the comparison between Realm and SQLite.

1. Architecture

Realm does not use SQLite as its engine, rather it is a database built from scratch to run directly on phones, tablets, and wearables. Realm is an object-oriented database that uses C++ as its core. However, SQLite uses a transactional SQL database engine.

2. Easy to Use

Realm is easy to use as it uses objects for storing data. Realm data models are defined using normal Java classes that are a subclass of RealmObject. This class can define properties of primary keys, required fields, etc. using simple annotations. Also, there is no requirement for converting the Realm query results into objects for further use because this conversion is handled automatically by Realm. Realm query results are returned in a generic RealmResults instance, which is a collection of the model class. This RealmResults instance is iterable like a list. However, the SQLite query results are returned in a Cursor object.

3. Cross Platform

Realm stores its data in a native object format where the objects are stored in a universal table-based format using C++ as its core, rather than storing them as is in their language-specific format. This makes Realm easy to use across multiple languages, platforms, and queries.

4. Speed

Realm performance is faster than SQLite, almost 10x faster according to the benchmark results. An example of this is — data fetched by Realm queries have a better performance enhancement than the insert queries as compared to SQLite.

Image title

Image title

Image title

5. Data Synchronization

The data in Realm is never copied; it works on live objects. Using Realm queries, we get a list of object references, thereby working on the original Realm data. Thus, any changes made to the queried data is reflected in the actual stored data as well after a simple commit. However, in SQLite, we get a copy of the data from the database through a query. Thus, using SQLite, any changes made on the queried data needs to be persisted by writing them back to the database again.

Companies Using Realm:

A few companies using Realm are Amazon, Google, Starbucks, Intel, eBay, Adidas, Zynga, Nike, IBM, and CISCO.

Limitations:

Realm currently has a few limitations:

  1. Realm does not have support for auto-incrementing IDs and composite keys.
  2. In order to maintain a balance between flexibility and performance, Realm imposes certain limitations on various aspects of storing information in a Realm, which includes:
    1. The upper limit on the name of a class is 57 characters, which includes the _class prefix.
    2. The field names have an upper limit of 63 characters.
    3. There is no support for nested transactions.
    4. String and byte arrays cannot be greater than 16 MB.
  3. There is no support for final, transient, and volatile variables.
  4. Realm model classes can only extend the Realm object.
  5. Realm model class must include the default empty constructor.
  6. There is currently support for only "Latin Basic," "Latin Supplement," "Latin Extended A,"  and "Latin Extended B" (UTF-8 range 0-591) in sorting and case-insensitive string matches. Further, setting the case insensitive flag in queries when using equalTo(), contains(), endsWith() or beginsWith() will only work on characters from the English locale.
  7. Although Realm files can be handled concurrently by multiple threads, we cannot hand over Realms, Realm objects, queries, and results between threads.
  8. Realm files cannot be accessed by concurrent processes, they can only be accessed by one process at a time. Different processes should either copy Realm files or create their own.
  9. RealmObject are live objects and might be updated by changes from other threads. Although two Realm objects returning true for RealmObject.equals() must have the same value for RealmObject.hashCode(), the value is not stable, and should neither be used as a key in HashMap nor saved in HashSet.

I hope this post was helpful in letting you decide which database to use for your next application.

SQLite Database

Published at DZone with permission of Lipika Gupta. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • An Overview of Creating Databases With Python
  • Building a High-Throughput Distributed Sequence Generator Using the Hi-Lo Algorithm
  • When Snowflake Lies to You: Understanding False Failures in dbt Pipelines
  • Master-Class: Understanding Database Replication (Single, Multi, and Leaderless)

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook