mobile-handy-database-comparison

Mobile databases: SQLite and SQLite alternatives for Android and iOS

UPDATED 2020. At Droidcon Berlin, we noticed a lot of questions around databases. Many people weren’t aware of SQLite alternatives and Object-Relational Mappers (ORMs). Therefore, we follow up with an overview of the mobile database landscape.

What is a mobile database?

While Wikipedia defines a mobile database as “either a stationary database that can be connected to by a mobile computing device […] over a mobile network, or a database which is actually stored by the mobile device,” we solely refer to databases that run on the mobile device itself.

Why use a mobile database?

There are some advantages associated with using a mobile database:

  • full offline modus for apps that depend on stored data
  • frugal on bandwidth for apps that depend on stored data
  • stable and predictable performance independent from network availability
  • (personal data can be stored with the user, where some say they belong)

What are the advantages and disadvantages of working with SQLite?

The most established mobile database – one could even say the only “established” – mobile database is SQLite. This may be due to SQLite being around since the year 2000 and being embedded with iOS and Android since the beginning. SQLite is a relational database.

In our previous post, we presented advantages and disadvantages of using raw SQLite without any tools as we had gathered them with a group of developers. Based on this, we generated a more generic overview of advantages and disadvantages of using raw SQLite:

advantages

disadvantages

  • Toolchain, e.g. DB browser
  • No dependencies, is included with Android and iOS
  • Developers can define exactly the data schema they want
  • Developers have full control, e.g. handwritten SQL queries
  • SQL is a powerful and established query language, and SQLite supports most of it
  • Debuggable data: developers can grab the database file and analyze it
  • Rock-solid, widely used technology, established since the year 2000
  • Using SQLite means a lot of boilerplate code and thus inefficiencies (also in the long run with the app maintenance)
  • 1 MB BLOB Limitation on Android
  • No compile time checks (e.g. SQL queries)
  • The performance of SQLite is unreliable
  • SQL is another language to master
  • SQL queries can get long and complicated
  • Testability (how to mock a database?)
  • Especially when database views are involved, maintainability may suffer with SQLite

What are SQLite alternatives?

There are plenty of SQLite alternatives. If you simply find it unpleasant to write a lot of SQL and boilerplate code, you can use a object abstraction on top of SQLite. This abstraction is usually an ORM (object/relational mapping). But if you want to replace SQLite completely, there are also quite a few alternative databases: Couchbase Lite, Interbase, LevelDB, Oracle Berkeley DB (formerly Oracle's mobile database was "Oracle Database Lite"), Realm, SnappyDB, Sparksee Mobile (graph database, brand-new at the time of this article), SQL Anywhere, SQL Server Compact (discontinued), and UnQLite.

To give you an overview, we have compiled a small comparison table:

NameAndroid / iOSType of data storedSync CentralOffline SyncData level encryptionLicense / business modelShort descriptionMinimum footprint sizeCompany
Core Dataembedded on iOSCore Data is not a database, we added it here because of its importance on iOSOptions with CloudKitNoNoProprietaryCore Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems.~4MBApple Inc
Couchbase MobileAndroid / iOSJSON Documents / NoSQL dbYesNoDatabase encryption with SQLCipher (256 AES)Apache 2.0Embedded / portable db with P2P and central synchronization (sync) support. Secure SSL.< 3,5 MBCouchbase
ForestDBAndroid / iOSKey-value pairs / NoSQL dbNoNoNoApache 2.0Portable lightweight key-value store, NoSQL database.  
extremeDBiOSIn-memory relational DB, hybrid persistenceNoNoAES encryptionProprietaryEmbedded relational database200kBMcObject LLC
InterbaseAndroid / iOSRelationalDepends on version.NoDepends on version (Lite versus ToGo).ProprietaryEmbeddable SQL database.400 KBEmbarcadero
LevelDBAndroid / iOSKey-value pairs / NoSQL dbNoNoNoNew BSDPortable lightweight key-value store, NoSQL db, no index support, very fast for some use cases.350kBLevelDB Team
LiteDBAndroid / iOS (with Xamarin only)NoSQL document storeNoNoSalted AESMIT licenseA .Net embedded NoSQL database350kb 
Mongo RealmAndroid / iOSObject DatabaseYesNoYesProprietary with Apache 2.0 License APIs.Embedded object db; Realm was acquired by Mongo in 2020 (shutting down Mongo's own development on "Mongo Mobile")5 MB+Mongo DB Inc.
ObjectBox DBAndroid / iOSObject Database, NoSQL, Edge DB for Mobile and IoTYesYestransport encryption; additional encryption upon requestApache 2.0 and ProprietaryEmbedded object-oriented NoSQL edge database with out-of-the-box synchronization; fully ACID compliant; optimized for speed restricted devices, benchmarks available.< 1MBObjectBox
Oracle Berkeley DBAndroid / iOSRelational and Key-Value-StoreWith Oracle Mobile ServerNo128-bit AES Standard encrytionProprietaryEmbedded / portable db with P2P and central sync support as well as support for sync with SQLite.< 1MBOracle Corporation
Snappy DBAndroidKey-value pairs / NoSQL dbNoNoNoApache 2.0Portable lightweight key-value store, NoSQL db based on LevelDB. Nabil HACHICHA
SQLiteembedded on Android & iOSRelationalNoNoNo, use SQLCipher to encrypt SQLitePublic domainRelational embedded database contained in a C library. ACID-compliant.500KBHwaci
UnQLiteAndroid / iOSKey-value pairs / document store / NoSQL dbNoNo 2-Clause BSDPortable lightweight embedded db; self-contained C library without dependency. Symisc systems

Find a more extensive comparison matrix on edge databases here. Mobile databases - as defined here - is a subset of Edge databases.

If you are interested in an indication of the diffusion rate, check out the following database popularity ranking: http://db-engines.com/en/ranking

Also note: DB-Engines lists 300+ databases as of 2020; the database of databases, which also includes hobby projects, counts 700+ databases. While the database market is very crowded and indeed vibrant, the Edge Database market, is still is a very small and clear market with only few notable players. In short: In the realm of edge databases there is still room 😉

What about NoSQL on Mobile?

NoSQL is a rather large bracket for database approaches that use a data structure that is non-relational. Indeed, NoSQL databases include key-value stores, document databases, wide-column stores, object databases, and graph databases. Generally, NoSQL is associated with scalability and performance. However, the scalability of NoSQL approaches on the serverside largely stems from scaling horizontally (adding more servers), which usually is no advantage for a mobile database running on mobile devices.

While NoSQL approaches usually process some operations faster, the particular fit of a particular NoSQL database depends on the use case. Also, the speed of a NoSQL approach may come with less emphasis on reliable data storage (see ACID). So, if your app requires strong data consistency or you handle highly structured data, like e.g. an address book, a relational database may still be a good choice. If, however, you are looking to handle unstructured data or need a lot of flexibility, a NoSQL approach may be more interesting for you.

The general traits of NoSQL approaches that make it worthy for evaluation for mobile:
  1. Object-oriented code in iOS and Android Apps

    Developers implement apps in object-oriented languages, meaning an app works with objects. But a relational database works with columns and rows and does not allow storing objects directly. Consequently, objects need to be serialized or reassembled in possibly inefficient way when stored or retrieved. For any database operation this takes time and imposes a natural speed limitation. The right NoSQL approach, e.g. an object database/store, may solve it without complex mappings.

  2. Dynamic requirements of Mobile Apps

    After the release of a mobile app, there is often an ongoing live operation process to continually adapt and enhance the app (bug fixes, new features, changes due to changes in the software or legal environment).  Implementing changes in a mobile app with a relational client database requires changes to the database schema, which results in additional work. NoSQL databases usually operate without a schema (usually with some enforcing data validation rules). Adding new fields as needed and storing dissimilar data together as necessary means minimal implementing effort for the database. However, again it all depends on the specific database implementation and use case.

  3. Growing need for handling big and / or unstructured data on Mobile

    There seems to be the need for handling more and more data (roughly speaking, the amount of data is doubling every 24 months) generally and on mobile. Obviously, on mobile the storage space is still a major concern, which usually omits simply storing every possible data point for potential use. Nevertheless, most NoSQL databases favor speed and store unstructured data. So, for mobile app handling large amounts of (unstructured) data, a NoSQL approach may be the solution.

However, other criteria like size, battery-friendliness or security may also be important factors for choosing a mobile database.

All in all, we hope, we provide a good general overview of the general status of mobile databases.

Spread the love
  • 17
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Posted in News and tagged , , , .