ylliX - Online Advertising Network
Which Local Database Should You Choose in 2025? Comparing Realm, SQLDelight, and Room.

Which Local Database Should You Choose in 2025? Comparing Realm, SQLDelight, and Room.


If you’re starting a Greenfield project, one of the key decisions you’ll face is selecting the right local database. Over the years, these databases have evolved significantly, with new features, improvements and some feature deprecations that could impact your choice.

Photo by Oladimeji Ajegbile on Pixels.com

If you’ve worked with databases before, whether on Android/iOS platforms using Kotlin or Swift, or through backend experience with SQL or NoSQL databases, you’ll find this comparison of the latest features insightful. I’ll also share my recommendations to help you choose the best local database for your new project.

Simplicity over complexity, Realm operates directly on the stored data which makes it faster with no intermediate mapping step. Realm handles complexity of concurrency when something changes in the database, the view is easily updated. It’s simple to use because you work with objects directly in your code instead of writing SQL. It’s also fast and supports automatic updates to data.

— What has Realm changed over the years?

  • Realm’s db size can reach 4MB which in-turn increases the APK size, so that hasn’t changed over the years.

You can reduce the APK size by doing APK Splitting or preferably using app bundles on Google Play to implement the splitting and manage the versioning altogether.

  • Realm Studio remains the only way to browse your db, that hasn’t changed.
  • MongoDB acquired Realm.

In Spring 2019, MongoDB acquired Realm to unify platform for backend and mobile app development, MongoDB’s cloud database (MongoDB Atlas)

  • On September 2024, MongoDB deprecated Native Sync-support (Atlas Device Sync — as named by MongoDB) to be removed by September 2025. This feature used to allow automatic syncing of data with other devices. Now developers need to come up with a sync strategy on their own.
  • Realm still supports Kotlin Multiplatform (KMP) till date.
  • Changes to the schema still requires a migration, providing utility methods like addField, removeField, and renameField to simplify schema updates.
  • Pagination still through its RealmResults object, which supports lazy loading and allows you to load subsets of data in chunk using methods like subList() or limit(), you can also implement Android Paging with Realm.
  • Still supports Swift databases (for iOS & macOS) apps, Flutter & React Native for Cross Platforms. For those who want to maintain same db across their Android & iOS teams.

SQLDelight adopts an SQL-first approach, eliminating the traditional limitations of ORMs. A major advantage where precise SQL control is necessary: You want full control over queries for performance tuning. It provides IDE features like autocomplete and refactoring which make writing and maintaining SQL simple.

— What has SQLDelight changed over the years?

  • Maintains support for Kotlin Multiplatform (KMP) till date.
  • On July 26, 2023 the release SQLDelight 2.0 was announced, the package name changed, and the IDE plugin improved dramatically. The package name transitioned from com.squareup.sqldelight to app.cash.sqldelight
  • Introduced Dialect support from 1.3.0 & above, which is being able to support MySQL & Postgres syntax & conventions.

According to the announcement, SQLDelight is switching its primary focus to server development but while Android and multiplatform development will continue to receive attention and improvements, there would be no fundamental changes to how SQLDelight functions on mobile platforms.

  • Since SQLDelight databases in Android apps are stored as SQLite databases. You can still access them using ADB or download the data & browse them using SQLite client like DB Browser for SQLite.
  • Provides extension for Rxjava, Coroutines & Android Pagination.

Room is well-suited where ease of integration with the Android Jetpack ecosystem is essential. Abstracting SQLite & supports writing SQL queries if needed, providing annotations for defining schemas and managing migrations with minimal effort.

Its ability to seamlessly work with LiveData and Flow for reactive programming. Great for apps requiring a well-supported ORM tailored to Android development. Room does compile time validation, validates your whole schema & queries before you can even run your app. So, you can be sure it is syntactically correct when it compiles.

— What has Room changed over the years?

  • Still offers built-in support for migrations. Room automatically validates migrations, but manual intervention may be required for complex schema changes.
  • Room now supports Kotlin Multiplatform (KMP) starting from version 2.7.0-alpha01.

Android released Room version 2.7.0-alpha01 on May 1, 2024, which supports Kotlin Multiplatform (KMP)

  • Supports pagination, Room paging library now available for KMP on September 18, 2024 Version 2.7.0-alpha08.
  • Still maintains great native support for Kotlin Coroutines for asynchronous database operations and UI updates.

There are other numerous changes to both Realm, SQLDelight & Room that was not mentioned here, I choose to focus on the major changes.

ObjectBox is a NoSQL Java database designed for local data storage on resource-restricted devices, prioritising offline-first functionality. As written on ObjectBox’s Github page, it outperform SQLite, Room & Realm across all CRUD operations. Supports Swift Databases (for iOS & macOS) apps, Go, C++ & Dart/Flutter.

ObjectBox Sync does keeps data in sync between devices and servers, therefore for devs having troubles with deprecated MongoDB Atlas Device sync (Realm native sync), they can migrate to ObjectBox for this feature.

ObjectBox currently does not support Kotlin Multiplatform (KMP).

Realm’s performance has always had an edge from inception as Realm utilizes an object-oriented approach where database entities are modeled as objects. Realm implements a zero-copy architecture which means data is read straight from memory without creating additional object copies. This method delivers faster performance for CRUD operations compared to relational ORM mapping system.

Realm has its own set of APIs and is not tightly integrated with Jetpack components. While SQLDelight is not a part of Jetpack but integrates well with Kotlin and provides a clean API to work with SQL.

Room is part of the Android Jetpack suite. It integrates well with LiveData, ViewModel, and other architecture components, making it a good choice for modern Android development.

Comparison table

Let’s put together a table outlining the features and key figures to guide you in reaching your final decision.

Going by the comparison table, If performance is crucial, and you prefer to avoid SQL queries or complex SQL joins, Realm is an excellent choice. For type safety and Kotlin-first integration with SQL, SQLDelight stands out. If you prefer a traditional SQL-based database with strong Android integration, Room is a reliable option.

For recommendations, I personally recommend Room. Google’s active support over the years inspires confidence in its longevity. Room provides the flexibility of SQL while abstracting queries for simplicity. It supports custom SQL queries, allowing developers to leverage existing SQL knowledge.

Additionally, it simplifies migration management, which can otherwise be challenging in complex scenarios. Room works seamlessly with Kotlin Coroutines and more importantly, now supports Kotlin Multiplatform (KMP), making it a future-proof choice for cross-platform development.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *