Flutter Databases: 2023 review
Tags: flutter, dart, database, mobile
Published: 2023-06-05 14:06:51

As Flutter is regarded as one of the [most loved mobile frameworks of 2022](https://survey.stackoverflow.co/2022/ther-frameworks-and-libraries), the Flutter database scene is thriving too. With an ever-growing market that does not seem to be slowing down, it might be difficult to decide on what database you should use. You can find anything you want from packages that provide plugins to familiar relational databases (Sqflite), to light-weight and high-performance NoSQL databases ([ObjectBox](https://pub.dev/packages/objectbox)).

## What should you consider when choosing a Flutter database?
There are a number of factors that you should keep in mind when selecting a database for your flutter project. Although what factors are important to you might differ depending on your particular project, there are a few indicators that are invaluable no matter the app you are building. 

- **Speed:** Performance is a crucial factor when selecting a database. It not only [makes sure you have data when you need it](https://objectbox.io/connecting-database-performance-and-business-value/), it saves costs and avoids downtime. For example, a strong response rate on a website can go as far as sales: [70% of respondents in a study noting that page speed impacts their willingness to buy from an online retailer](https://unbounce.com/page-speed-report/).
- **Ease-of-use:** With constant pressure to deliver new apps and / or features, most developers care a lot about the eas-of-use. Depending on your skills or the team’s skill set, choosing a database that comes with native-language APIs that are intuitive to use, will save you a lot of time and nerves short-and longterm. While [SQL is still a popular language](https://www.tiobe.com/tiobe-index/), it is an additional skill needed, and inot a great match for object-oriented code.
- **Scalability:** Even though a project may not have a lot of requirements at the moment, it can grow quickly. Having a database that ensures a capacity to grow with your data and user base can be vital to ensure long-term success. 
- **Data Sync:** Local databases are great, but sometimes you need your data to [sync between systems that are far from each other](https://objectbox.io/what-is-data-synchronization-how-to-keep-data-in-sync/). You also need to automate an update process that maintains consistency in order to meet your business needs. Almost every mobile application will need data synchronization, but it takes a lot of time as well as introduces a lot of risk. A database that comes with a Sync solution out of the box is a no-brainer in this regard. 

### {Aside: a word about data sync}
If data-synchronization is your priority, ObjectBox Sync is a next-gen solution equipped to manage data flows and harmonize data across devices, offline as well as online. [Discover the easy to use alternative for syncing data](https://objectbox.io/sync/) – and simply rely on the data being available where you need it when you need it. Sync is a transactionally safe way of making the data sets you select reliably available in a highly efficient way. 

## What kind of databases exist?
Databases can be classified into various types. The most significant differentiations for our purposes include non-relational (NoSQL) versus relational (SQL) databases, cloud databases versus edge databases, and embedded versus in-memory databases. However, databases can also be distinguished based on additional criteria such as supported data types and scalability, although definitions may vary.

## Is an ORM a database?
An Object Relational Mapper (ORM) is not a database itself but rather a layer that sits on top of a database, simplifying its usage. This is particularly relevant when working with relational databases (SQL) and object-oriented programming languages like Dart. It helps bridge the gap between the object-oriented nature of the programming language and the relational structure of the database.

## Flutter database landscape in 2023
Let's introduce the key players in the current Flutter database market:

- [Sqflite](https://en.wikipedia.org/wiki/SQLite) serves as a wrapper around SQLite, a relational database that lacks direct support for Dart objects.
- [Drift](https://drift.simonbinder.eu/) (formerly known as Moor) is an ORM built on top of SQLite, which itself is a well-established lightweight relational (SQL) database.
- [Floor](https://pinchbv.github.io/floor/) is another ORM that utilizes SQLite as its underlying database.
- [Isar](https://isar.dev/) is a fast and lightweight NoSQL database developed by the author of Hive.
- [Sembast](https://github.com/tekartik/sembast.dart/tree/master/sembast) is a NoSQL database.
- [Realm](https://en.wikipedia.org/wiki/Realm_(database)) is a lightweight NoSQL database primarily written in Java, which was acquired by Mongo DB in 2019.
- [ObjectBox](https://github.com/objectbox/objectbox-dart) is a highly performant lightweight NoSQL database with integrated data synchronization capabilities.

Note: Since Hive is expected to be deprecated according to its author, we will focus on Isar as the recommended alternative in this discussion.

| Package name |          Package Description         | Data Model |                           Data Sync                           | Language |
|:------------:|:------------------------------------:|:----------:|:-------------------------------------------------------------:|:--------:|
|    sqflite   |       SQLite plugin for Flutter      | relational |                               ❌                               |    SQL   |
|     Drift    |         ORM on top of SQLite         | relational |                               ❌                               |    SQL   |
|     Floor    |         ORM on top of SQLite         | relational |                               ❌                               |    SQL   |
|     Isar     |      Lightweight NoSQL database      |    NoSQL   |                               ❌                               |   Dart   |
|    Sembast   | NoSQL database, fully document-based |    NoSQL   |                               ❌                               |   Dart   |
|     Realm    |            NoSQL database            |    NoSQL   | Yes, but MongoDB Atlas and Cloud are needed |   Dart   |
|   ObjectBox  |   Lightweight NoSQL database + Sync  |    NoSQL   |                               ✅                               |   Dart   |

## How to choose the best Flutter database?
In conclusion, the Flutter database market is a dynamic and evolving landscape, with new options continually emerging. Choosing the best database option for a Flutter project requires careful consideration of specific project requirements and objectives. In this article, we have reviewed the top options currently available so that you can have a handy reference to the most important tech features. We encourage you to stay informed and check for updates on pub.dev, as well as contribute to the community.