AnnouncementIntroducing MongoDB 8.0, the fastest MongoDB ever! Read more >>

Compare

Android Databases

6 things to consider when looking for an Android database
Deploy a Sample App
View documentation
Overview

With data and data storage a common requirement in most mobile applications, the question of which is the best database to use often comes up. In this article, we are going to cover what to consider when choosing a database for your Android app, and what the available options are. This will allow you to make an informed choice the next time you require a database for your mobile app.

What is a database for Android?

A database for Android is a form of persistent data storage intended for use in apps for Android devices. It often consists of on-device, local storage so the app continues to be available even if the device loses connectivity. Due to its inclusion in the Android Software Development Kit (SDK), SQLite, an open-source relational database, is the most common database technology associated with Android applications. For Android apps, SQLite is most often paired with Room, a framework for managing the lifecycle of objects. However, as this article will go on to discuss, there are other simpler options for modern mobile applications.

What to look for in a mobile database

Although databases all provide the ability to store, query, and manipulate data, not all databases are created equal.

Before choosing, you need to understand your application requirements. Here are a couple of questions that can help you:

Database Type

What sort of data will you be storing?

Are you going to store structured/unstructured data or large files? Should the data be shared among users or can it be stored only on the device?

How will you access your data?

Do you need to perform complicated queries to join data from multiple data sources?

Hosting Method

How will users be interacting with your application’s data?

Do users expect to be able to collaborate in real-time without any noticeable delays? Does data need to be shared between users and devices?

Different types of Android databases

Now you know what things to consider in an Android database, let’s look at some of the types of Android databases available. They mainly fall into three categories: relational, key-value, and object-oriented.

Relational database - Uses tables and shared columns, aka keys, to form relationships between tables. Most common example is SQLite, available inside the Android SDK. Great if relationships between entities are important.


Key-Value database - Uses a key to single value mapping to store information. Often used in Android databases for saving things such as user settings. Example would be Shared Preferences for Android.


Object-oriented database - Can work with complex data objects as seen in object-oriented programming languages. Able to do fast queries with complex data. Code is often simpler as well due to closeness in structure between the database and objects in code. Atlas Device SDKs provide an object-oriented database.

Different ways to host your database

There are some factors in how a database can be hosted and how it works that are worth considering:

Local storage - Having the data stored locally and available offline is an important feature in mobile applications. With their portability, connections to the network can be inconsistent on mobile devices. With data stored locally on a mobile device, apps continue to be usable, even when offline, leading to a much better user experience.


Cloud - Many mobile applications require data sharing across users, devices, and a centralized back end — a capability not supported by local-only storage solutions. This means that mobile developers need to save their app data to the cloud or a self-hosted server.

A cloud database has several advantages. For example, MongoDB Atlas, MongoDB’s multi-cloud application data platform, combines a flexible document data model and unified query interface, to provide a first-class developer experience that can power almost any class of application while meeting the most demanding requirements for resilience, scale, and data privacy. However, the driver used to communicate with Atlas requires network access at all times, making the experience less than optimal for mobile use cases where devices are constantly disconnecting and reconnecting.


Server - You may prefer to self-host your data, using your own servers and data center. A database that can be self-hosted and work with mobile is therefore a consideration. However, this again would require internet access to reach so faces the same limitations around connectivity.


Locally and in the cloud - One option that addresses connectivity issues and ensures real-time data sharing capabilities is to use a cloud database and a local database. Then, connect the two with a synchronization mechanism. This is the most common architecture for building real-time, reactive mobile apps that appear “always on” for users. However, developing and maintaining an effective synchronization mechanism requires writing lots of networking code, error handling, and conflict resolution logic that is often complex and time-consuming for mobile development teams to devote resources to. Taking time to build custom data syncing mechanisms also means less time can be spent on building differentiating features within the application.

How does Atlas Device SDK compare?

Let’s examine some of the most popular examples of databases and then look into Atlas Device SDK. This is not an exhaustive list.
SQLite

This is the most well known relational database across both iOS and Android.

Pros

  • Available inside the Android SDK, so no extra library is required.

  • It uses a file-based system which means it can be used easily across multiple platforms, such as iOS and Android.
  • Cons

  • Objects need to be transformed and broken into row-based stores.

  • No user-based management, only application managed security.

  • Lacks scalability due to the restrictions of tables needing to be kept together.

  • Oftentimes, requires an ORM or DAO to be used alongside it. SQLite has no automatic data change notification mechanism, meaning developers must write functions to monitor an object's lifecycle as its values change via updates in the application or database.

  • Queries for different views in the application UI must be hard-coded ahead of time, adding complexity to front-end customization.

  • No cross-device, cloud, or sync capabilities.

  • ORMLite

    Lightweight Object Relational Mapper (ORM) intended for Java/Kotlin applications including Android. Is a wrapper around any mobile SQL database rather than a database in itself.

    Pros

  • Simplifies queries with a flexible query builder. Able to take advantage of Data Access Objects (DAO) classes.
  • Cons

  • Needs to be used alongside a SQL database.

  • Can increase application size.

  • Requires extra learning and management.

  • It still needs to map from objects to row-based storage under the hood.

  • No cloud capabilities.

  • Room

    An abstraction layer over SQLite. Uses database classes to hold the database and be the main access point for the persisted data.

    Pros

  • Supports compile-time verification of SQL queries. Can add convenience annotations to avoid boilerplate and repetitive code. Supports DAO classes.
  • Cons

  • Needs to be used alongside SQLite — managing two systems instead of one.

  • Queries can be overly complex.

  • Can take a long time to learn and be hard to master.

  • Advanced functionality requires a lot of time and code to implement, which hinders productivity.

  • No built-in cloud capabilities.

  • Firebase

    Cloud Firestore or Realtime Database

    Extensive multifunctional platform with a wide breadth of products, including Cloud Firestore and Realtime Database.

    Pros

  • Easy to get started and build to MVP.

  • Built-in support for mobile-to-cloud sync.

  • Wide breadth of products beyond just mobile database capabilities like authentication.

  • Has a strong community for support.
  • Cons

  • Requires adding a third-party library that increases app size.

  • Limited data model and query constraints mean lower performing applications and poor user experience.

  • No aggregation queries (average, sum, count, etc). Complex queries have to be handled externally with Cloud Functions, creating an additional service management burden for developers.

  • Scaling requires sharding, which cannot be manually configured in Firestore.

  • Sync only supports “last write wins” for conflict resolution which could lead to data loss with multi-user applications.

  • KeyChain

    It’s an API used for persisting sensitive data locally, such as passwords and in-app purchase statuses.

    Pros

  • Data is encrypted, so it’s ideal for storing sensitive information.

  • It’s built into iOS through the security framework, meaning it doesn’t require extra libraries.
  • Cons

  • The framework is quite old and hasn’t been updated recently.

  • APIs haven’t been modernized, so when used with Swift, the code can be quite complex.

  • Atlas Device SDK

    Atlas Device SDK is a fast, reactive, and scalable alternative to SQLite that makes storing, syncing, and querying data simple for modern mobile applications.

    Pros

  • Object-oriented data model — no need for ORMs or DAOs.

  • Lightweight, idiomatic query APIs that allow developers to work with data as code.

  • Built-in sync capabilities to MongoDB Atlas.

  • Seamlessly integrated with other Atlas services like Triggers, Functions, GraphQL API, and Charts.

  • Atlas Device SDK offers per property syncing — a fine-grained conflict resolution method that leads to much lower likelihood of error and overwrites of other data.
  • Cons

  • Requires adding a third-party library that increases app size.

  • Smaller community than Firebase and SQLite.

  • While Atlas works across cloud providers, Atlas Device SDK sync functionality currently only runs on AWS, with support for GCP and Azure coming soon.
  • Given the above criteria, we feel that Atlas Device SDK is the best option for your Android application if you’re looking to build real-time, reactive mobile apps fast. Atlas Device SDK object-oriented data model enables developers to work directly with native objects — no ORMs or DAOs required. And the built-in mobile-to-cloud data sync lets you focus on building differentiating features without worrying about connectivity or real-time collaboration issues.
    Summary

    When it comes to creating an application for Android, it often requires a database just like any other project. In this article, we have learned about the different storage options available for Android, as well as what to consider when choosing a database. We then learned about some of the database options available for Android and why Atlas Device SDK is an excellent database choice for Android.

    Atlas Device SDK has many idiomatic SDKs, including those for Java and Kotlin, as well as cross-platform frameworks like Kotlin Multiplatform. Get started with Atlas Device SDK for Java or Atlas Device SDK for Kotlin.

    FAQ

    What is the best alternative to SQLite?

    If you want to get away from relational databases and SQLite, Atlas Device SDK is a fast, scalable alternative that makes storing, querying, and syncing data simple for modern mobile applications.

    The object-oriented data model enables developers to work directly with native objects — no ORMs or DAOs required. And built-in mobile-to-cloud data sync lets developers easily back up, manage, and analyze mobile app data in the cloud, using the full power of MongoDB Atlas.

    Can I use MongoDB with Android?
    Absolutely! While we do not recommend running MongoDB on mobile devices, Atlas Device SDK provides a fast, scalable mobile database with SDKs for both Java and Kotlin, as well as cross-platform frameworks like Kotlin Multiplatform.
    Are the Atlas Device SDK and MongoDB the same?

    No. Atlas Device SDK is a collection of tools to accelerate app development on a broad range of devices that can be used to sync data between the on-device database it provides and MongoDB’s fully managed cloud data platform.

    MongoDB is committed to keeping the Atlas Device SDK database open source and free to use.

    Deploy Atlas Device SDK in minutes

    Deploy an iOS, Android, or cross-platform “To Do” app with real-time sync in minutes.
    Get Started Now
    An illustration of a database and device syncing over clouds.